/* * $Id$ * * $Date$ * $Revision$ * * Written in 2018 by Daniel "Daytona675x" Müßener * * This file is part of the MiniGL library project * See the file Licence.txt for more details * */ #ifdef MGL_HAS_NO_SPE_NEWLIB #include "tabor.h" // taken from newlib #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #include "math/s_copysign.c" #include "math/s_scalbln.c" #include "math/s_cos.c" #include "math/k_cos.c" #include "math/e_rem_pio2.c" #include "math/k_rem_pio2.c" #include "math/s_sin.c" #include "math/k_sin.c" #include "math/e_sqrt.c" /* float spe_sqrt(float v) { float n=v*0.5f; float lstX=0.0f; while(n!=lstX) { lstX=n; n=(n+v/n)*0.5f; } return n; } */ float spe_exp(float v) { v=1.0f+v/256.0f; v*=v; v*=v; v*=v; v*=v; v*=v; v*=v; v*=v; v*=v; return v; } float spe_log(float v) { return 6.0f*(v-1.0f)/(v+1.0f+4.0f*spe_sqrt(v)); } float spe_pow(float x,float y) { if(y==2.0f) { return x*x; } else if(y==0.5f) { return spe_sqrt(x); } return spe_exp(spe_log(x)*y); } float spe_floor(float v) { if(v<0.0f) { float nv=-v; int iv=nv; if(nv==(float)iv) return v; return -(iv+1); } int iv=v; return iv; } float spe_ceil(float v) { if(v<0.0f) { float nv=-v; int iv=nv; return -iv; } int iv=v; if(v==(float)iv) return v; return (iv+1); } #define POLYNOM1(x,a) ((a)[1]*(x)+(a)[0]) #define POLYNOM2(x,a) (POLYNOM1((x),(a)+1)*(x)+(a)[0]) #define POLYNOM3(x,a) (POLYNOM2((x),(a)+1)*(x)+(a)[0]) #define POLYNOM4(x,a) (POLYNOM3((x),(a)+1)*(x)+(a)[0]) float spe_atan(float x) { static const float p[] = { -0.13688768894191926929e+2, -0.20505855195861651981e+2, -0.84946240351320683534e+1, -0.83758299368150059274e+0 }; static const float q[] = { 0.41066306682575781263e+2, 0.86157349597130242515e+2, 0.59578436142597344465e+2, 0.15024001160028576121e+2, 1.0 }; static const float a[] = { 0.0, 0.52359877559829887307710723554658381, 1.5707963267948966192313216916398, 1.04719755119659774615421446109316763 }; int neg=x<0; int n; if(neg) x=-x; if(x>1.0f) { x=1.0f/x; n=2; } else n=0; if(x>0.26794919243112270647f) { ++n; x=(((0.73205080756887729353f*x-0.5f)-0.5f)+x)/(1.73205080756887729353f+x); } float g=x*x; x+=x*g*POLYNOM3(g,p)/POLYNOM4(g,q); if(n>1) x=-x; x+=a[n]; return neg ? -x : x; } static inline int spe_IsNum(char c) {return (c>='0' && c<='9');} static const char* spe_ShiftExp(const char *s,double *nr) { if(*s=='E' || *s=='e') { ++s; int neg=0; switch(*s) { case '-': neg=1; ++s; break; case '+': ++s; break; default: break; } if(spe_IsNum(*s)) { while(*s=='0') ++s; // skip zeros if(spe_IsNum(*s)) { unsigned int shift=0; do { shift*=10; shift+=*s-'0'; ++s; }while(spe_IsNum(*s)); if(neg) { for(unsigned int t=0;t