# Changeset 578 for libcaca/trunk/kernelTweet

Ignore:
Timestamp:
Mar 10, 2006, 10:31:32 AM (15 years ago)
Message:
• Implemented a few math functions in our kernel: cos(), sin(), sqrt().
Location:
libcaca/trunk/kernel
Files:
2 edited

Unmodified
Added
Removed
• ## libcaca/trunk/kernel/kernel.c

 r573 } /* math.h functions */ double cos(double x) { double ret = 0.0; double x2; double num = 1.0; double fact = 1.0; int i; x = x - ((double)(int)(x / (2 * M_PI))) * (2 * M_PI); x2 = x * x; /* cos(x) = 1/0! - x^2/2! + x^4/4! - x^6/6! ... */ for(i = 0; i < 10; i++) { ret += num / fact; num *= - x2; fact *= (2 * i + 1) * (2 * i + 2); } return ret; } double sin(double x) { double ret = 0.0; double x2; double num; double fact = 1.0; int i; x = x - ((double)(int)(x / (2 * M_PI))) * (2 * M_PI); x2 = x * x; num = x; /* sin(x) = x/1! - x^3/3! + x^5/5! - x^7/7! ... */ for(i = 0; i < 10; i++) { ret += num / fact; num *= - x2; fact *= (2 * i + 2) * (2 * i + 3); } return ret; } double sqrt(double x) { double ret = x; int i; /* This is Newton's method */ for(i = 0; i < 10; i++) ret = (ret * ret + x) / (ret * 2.0); return ret; } #endif /* __KERNEL__ */
• ## libcaca/trunk/kernel/kernel.h

 r573 #define RAND_MAX ((unsigned int)0x8000000) #define INT_MAX ((int)0x7fffffff) #define M_PI 3.14159265358979323846 #define __BYTE_ORDER 1 #define __BIG_ENDIAN 2 int gettimeofday(struct timeval *tv, struct timezone *tz); /* math.h functions */ double cos(double x); double sin(double x); double sqrt(double x);
Note: See TracChangeset for help on using the changeset viewer.