Changeset 578 for libcaca/trunk/kernel/kernel.c
 Timestamp:
 Mar 10, 2006, 10:31:32 AM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/kernel/kernel.c
r573 r578 212 212 } 213 213 214 /* math.h functions */ 215 double cos(double x) 216 { 217 double ret = 0.0; 218 double x2; 219 double num = 1.0; 220 double fact = 1.0; 221 int i; 222 223 x = x  ((double)(int)(x / (2 * M_PI))) * (2 * M_PI); 224 x2 = x * x; 225 226 /* cos(x) = 1/0!  x^2/2! + x^4/4!  x^6/6! ... */ 227 for(i = 0; i < 10; i++) 228 { 229 ret += num / fact; 230 num *=  x2; 231 fact *= (2 * i + 1) * (2 * i + 2); 232 } 233 234 return ret; 235 } 236 237 double sin(double x) 238 { 239 double ret = 0.0; 240 double x2; 241 double num; 242 double fact = 1.0; 243 int i; 244 245 x = x  ((double)(int)(x / (2 * M_PI))) * (2 * M_PI); 246 x2 = x * x; 247 num = x; 248 249 /* sin(x) = x/1!  x^3/3! + x^5/5!  x^7/7! ... */ 250 for(i = 0; i < 10; i++) 251 { 252 ret += num / fact; 253 num *=  x2; 254 fact *= (2 * i + 2) * (2 * i + 3); 255 } 256 257 return ret; 258 } 259 260 double sqrt(double x) 261 { 262 double ret = x; 263 int i; 264 265 /* This is Newton's method */ 266 for(i = 0; i < 10; i++) 267 ret = (ret * ret + x) / (ret * 2.0); 268 269 return ret; 270 } 271 214 272 #endif /* __KERNEL__ */
Note: See TracChangeset
for help on using the changeset viewer.