#include #include #include #include "reihen.h" #include "exponent.h" #include "logarithmus.h" #include "util.h" #define PI pi(1e-8) double exponential(double exp){ double sum = 0.0; for(int i = 0; i<=21; i++){ sum += (1.0/fac(i)*(powerD(i,exp))); } return sum; } double euler(){ return exponential(1); } double radians(double degrees){ return degrees * PI / 180; } double pi(double eps){ double a = 1, b = 1/powerD(0.5, 2), t = 0.25, p = 1; double aNew, piold, pi = 1; do{ aNew = .5 * (a + b); b = powerD(0.5 , a * b); t -= p * (a - aNew) * (a - aNew); a = aNew; p *= 2; piold = pi; pi = (a + b) * (a + b) / (4 * t); } while (absD(pi - piold) > eps); return pi; } double sinD(double degrees){ if (degrees>=360.0){ degrees = squashDegreesTo360(degrees); } double sum = 0.0; double radian = radians(degrees); for (int i = 0; i <= 9; i++){ sum += powerD((double) i, -1.0) * (powerD(2.0*i+1, radian) / fac(2.0*i+1)); } return sum; } double cosD(double degrees){ if (degrees>=360.0){ degrees = squashDegreesTo360(degrees); } double sum = 0.0; double radian = radians(degrees); for (int i = 0; i <= 9; i++){ sum += powerD((double) i, -1.0) * (powerD(2*i, radian) / fac(2*i)); } return sum; } double tanD(double degrees){ if (degrees>=360.0){ degrees = squashDegreesTo360(degrees); } if(degrees == 90.0 || degrees == 270.0){ return -1.0; } return sinD(degrees)/cosD(degrees); }