/* * MathPlanner 3.2 - Mathematical design tool. * Copyright(C) 2003 Jarmo Nikkanen * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation. * * You should have received a copy of the GNU General Public License with this program. * */ // REAL MATH #include "MathHeaders.h" #include "Error.h" #define MODUL_ACCURACY 100000 // This is required to overide same problems than sin & cos have. bool mpl_modul(mpl_real a,mpl_real b) { mpl_real c=(a/b); mpl_real ca=floor(c*MODUL_ACCURACY); mpl_real cb=floor(c)*MODUL_ACCURACY; if (ca==cb) return(true); return(false); } mpl_real mpl_factorial(mpl_real val) { mpl_real f,i; if (val!=floor(val)) return(0); f=1.0; for(i=1.0;i<=val;i+=1.0) f=f*i; return(f); } mpl_real mpl_rad(mpl_real deg) { return((deg*2/360)*PI); } mpl_real mpl_deg(mpl_real rad) { return(360*rad/(2*PI)); } mpl_real mpl_coth(mpl_real x) { mpl_real ex=pow(NEPER,x); mpl_real emx=pow(NEPER,-x); return((ex+emx)/(ex-emx)); } mpl_real mpl_asinh(mpl_real x) { return(log(x+sqrt((x*x)+1))); } mpl_real mpl_acosh(mpl_real x) { return(log(x+sqrt((x*x)-1))); } mpl_real mpl_atanh(mpl_real x) { return(0.5*log((1+x)/(1-x))); } mpl_real mpl_acoth(mpl_real x) { return(0.5*log((x+1)/(x-1))); } // Sin(x) is only defined in a range of x ( 2pi > x > 0 ) we have to extend that. // Also Sin(pi) does not return exactly a zero, so we have to force it to zero. // This is NOT about unaccurate defination of pi mpl_real mpl_sin(mpl_real x) { if (x>(2*PI)) x=fmod(x,2*PI); else if (x<0) x=(2*PI)-fmod(fabs(x),2*PI); mpl_real a=sin(x); if (a<1e-14 && a>-1e-14) return(0); return(a); } mpl_real mpl_cos(mpl_real x) { if (x>(2*PI)) x=fmod(x,2*PI); else if (x<0) x=(2*PI)-fmod(fabs(x),2*PI); mpl_real a=cos(x); if (a<1e-14 && a>-1e-14) return(0); return(a); } mpl_real mpl_tan(mpl_real x) { if (x>(2*PI)) x=fmod(x,2*PI); else if (x<0) x=(2*PI)-fmod(fabs(x),2*PI); mpl_real a=tan(x); if (a<1e-14 && a>-1e-14) return(0); return(a); }