Changeset 777 for soft/giet_vm/giet_libs/math
- Timestamp:
- Feb 4, 2016, 6:25:22 PM (9 years ago)
- Location:
- soft/giet_vm/giet_libs/math
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/math/e_pow.c
r682 r777 103 103 int32_t i,j,k,yisint,n; 104 104 int32_t hx,hy,ix,iy; 105 u _int32_t lx,ly;105 uint32_t lx,ly; 106 106 107 107 EXTRACT_WORDS(hx,lx,x); … … 180 180 181 181 /* (x<0)**(non-int) is NaN */ 182 if(((((u _int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);182 if(((((uint32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x); 183 183 184 184 /* |y| is huge */ … … 251 251 252 252 s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ 253 if(((((u _int32_t)hx>>31)-1)|(yisint-1))==0)253 if(((((uint32_t)hx>>31)-1)|(yisint-1))==0) 254 254 s = -one;/* (-ve)**(odd int) */ 255 255 … … 312 312 { 313 313 double z = __ieee754_pow(x, y); 314 if (isnan(y)) 314 if (isnan(y)) { 315 315 return z; 316 } 316 317 if (isnan(x)) { 317 318 if (y == 0.0) { … … 322 323 if (x == 0.0) { 323 324 if (y == 0.0) { 324 325 return 0; /* pow(0.0,0.0) */ 325 326 } 326 327 if (isfinite(y) && y < 0.0) { … … 332 333 if (isfinite(x) && isfinite(y)) { 333 334 if (isnan(z)) { 334 return 0.0 /0.0; /* pow neg**non-int */335 return 0.0 / 0.0; /* pow neg**non-int */ 335 336 } 336 337 { 337 338 double ret = huge; 338 339 y *= 0.5; 339 if(x<zero&&rint(y)!=y) ret = -huge; 340 if (x < zero && rint(y) !=y ) { 341 ret = -huge; 342 } 340 343 return ret; 341 344 } … … 347 350 return z; 348 351 } 352 353 /* 354 * Pseudo exp function (QM) 355 * There probably is a better implementation 356 */ 357 double exp(double x) 358 { 359 const double e = 2.71828182846; 360 return pow(e, x); 361 } 362 -
soft/giet_vm/giet_libs/math/e_rem_pio2.c
r581 r777 75 75 double tx[3]; 76 76 int32_t e0,i,j,nx,n,ix,hx; 77 u _int32_t low;77 uint32_t low; 78 78 79 79 GET_HIGH_WORD(hx,x); /* high word of x */ … … 115 115 y[0] = r-w; /* quick check no cancellation */ 116 116 } else { 117 u _int32_t high;117 uint32_t high; 118 118 j = ix>>20; 119 119 y[0] = r-w; -
soft/giet_vm/giet_libs/math/e_sqrt.c
r581 r777 93 93 int32_t sign = (int)0x80000000; 94 94 int32_t ix0,s0,q,m,t,i; 95 u _int32_t r,t1,s1,ix1,q1;95 uint32_t r,t1,s1,ix1,q1; 96 96 97 97 EXTRACT_WORDS(ix0,ix1,x); … … 168 168 if (z>=one) { 169 169 z = one+tiny; 170 if (q1==(u _int32_t)0xffffffff) { q1=0; q += 1;}170 if (q1==(uint32_t)0xffffffff) { q1=0; q += 1;} 171 171 else if (z>one) { 172 if (q1==(u _int32_t)0xfffffffe) q+=1;172 if (q1==(uint32_t)0xfffffffe) q+=1; 173 173 q1+=2; 174 174 } else -
soft/giet_vm/giet_libs/math/math_private.h
r588 r777 16 16 #define _MATH_PRIVATE_H_ 17 17 18 typedef unsigned int u_int32_t; 19 18 typedef unsigned int uint32_t; 20 19 typedef int int32_t; 20 typedef unsigned long long int uint64_t; 21 typedef long long int int64_t; 21 22 22 23 /* The original fdlibm code used statements like: … … 51 52 struct 52 53 { 53 u _int32_t msw;54 u _int32_t lsw;54 uint32_t msw; 55 uint32_t lsw; 55 56 } parts; 56 57 } ieee_double_shape_type; … … 64 65 struct 65 66 { 66 u _int32_t lsw;67 u _int32_t msw;67 uint32_t lsw; 68 uint32_t msw; 68 69 } parts; 69 70 } ieee_double_shape_type; -
soft/giet_vm/giet_libs/math/s_copysign.c
r581 r777 24 24 double copysign(double x, double y) 25 25 { 26 u _int32_t hx,hy;26 uint32_t hx,hy; 27 27 GET_HIGH_WORD(hx,x); 28 28 GET_HIGH_WORD(hy,y); -
soft/giet_vm/giet_libs/math/s_fabs.c
r581 r777 22 22 double fabs(double x) 23 23 { 24 u _int32_t high;24 uint32_t high; 25 25 GET_HIGH_WORD(high,x); 26 26 SET_HIGH_WORD(x,high&0x7fffffff); -
soft/giet_vm/giet_libs/math/s_finite.c
r581 r777 23 23 int isfinite(double x) 24 24 { 25 u _int32_t hx;25 uint32_t hx; 26 26 27 27 GET_HIGH_WORD(hx, x); -
soft/giet_vm/giet_libs/math/s_floor.c
r581 r777 11 11 12 12 /* Modified for GIET-VM static OS at UPMC, France 2015. 13 13 */ 14 14 15 15 /* … … 28 28 double floor(double x) 29 29 { 30 int32_t i0,i1,j0; 31 u_int32_t i,j; 32 EXTRACT_WORDS(i0,i1,x); 33 j0 = ((i0>>20)&0x7ff)-0x3ff; 34 if(j0<20) { 35 if(j0<0) { /* raise inexact if x != 0 */ 36 if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ 37 if(i0>=0) {i0=i1=0;} 38 else if(((i0&0x7fffffff)|i1)!=0) 39 { i0=0xbff00000;i1=0;} 40 } 41 } else { 42 i = (0x000fffff)>>j0; 43 if(((i0&i)|i1)==0) return x; /* x is integral */ 44 if(huge+x>0.0) { /* raise inexact flag */ 45 if(i0<0) i0 += (0x00100000)>>j0; 46 i0 &= (~i); i1=0; 47 } 48 } 49 } else if (j0>51) { 50 if(j0==0x400) return x+x; /* inf or NaN */ 51 else return x; /* x is integral */ 52 } else { 53 i = ((u_int32_t)(0xffffffff))>>(j0-20); 54 if((i1&i)==0) return x; /* x is integral */ 55 if(huge+x>0.0) { /* raise inexact flag */ 56 if(i0<0) { 57 if(j0==20) i0+=1; 58 else { 59 j = i1+(1<<(52-j0)); 60 if(j<i1) i0 +=1 ; /* got a carry */ 61 i1=j; 62 } 63 } 64 i1 &= (~i); 65 } 66 } 67 INSERT_WORDS(x,i0,i1); 68 return x; 30 int32_t i0, i1, j0; 31 uint32_t i, j; 32 EXTRACT_WORDS(i0, i1, x); 33 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; 34 if (j0 < 20) { 35 if (j0 < 0) { /* raise inexact if x != 0 */ 36 if (huge + x > 0.0) {/* return 0*sign(x) if |x|<1 */ 37 if (i0 >= 0) { 38 i0 = i1 = 0; 39 } 40 else if (((i0 & 0x7fffffff) | i1) != 0) { 41 i0 = 0xbff00000; 42 i1 = 0; 43 } 44 } 45 } 46 else { 47 i = (0x000fffff) >> j0; 48 if (((i0 & i) | i1) == 0) { 49 return x; /* x is integral */ 50 } 51 if (huge + x > 0.0) { /* raise inexact flag */ 52 if (i0 < 0) { 53 i0 += (0x00100000) >> j0; 54 } 55 i0 &= (~i); 56 i1 = 0; 57 } 58 } 59 } 60 else if (j0 > 51) { 61 if (j0 == 0x400) { 62 return x + x; /* inf or NaN */ 63 } 64 else { 65 return x; /* x is integral */ 66 } 67 } 68 else { 69 i = ((uint32_t) (0xffffffff)) >> (j0 - 20); 70 if ((i1 & i)== 0) { 71 return x; /* x is integral */ 72 } 73 if (huge + x > 0.0) { /* raise inexact flag */ 74 if (i0 < 0) { 75 if (j0 == 20) { 76 i0 += 1; 77 } 78 else { 79 j = i1 + (1 << (52 - j0)); 80 if (j < i1) { 81 i0 += 1 ; /* got a carry */ 82 } 83 i1 = j; 84 } 85 } 86 i1 &= (~i); 87 } 88 } 89 INSERT_WORDS(x, i0, i1); 90 return x; 69 91 } 70 92 -
soft/giet_vm/giet_libs/math/s_isnan.c
r581 r777 26 26 EXTRACT_WORDS(hx,lx,x); 27 27 hx &= 0x7fffffff; 28 hx |= (u _int32_t)(lx|(-lx))>>31;28 hx |= (uint32_t)(lx|(-lx))>>31; 29 29 hx = 0x7ff00000 - hx; 30 return (int)(((u _int32_t)hx)>>31);30 return (int)(((uint32_t)hx)>>31); 31 31 } -
soft/giet_vm/giet_libs/math/s_rint.c
r581 r777 35 35 { 36 36 int32_t i0, j0, sx; 37 u _int32_t i,i1;37 uint32_t i,i1; 38 38 double t; 39 39 /* We use w = x + 2^52; t = w - 2^52; trick to round x to integer. … … 47 47 EXTRACT_WORDS(i0,i1,x); 48 48 /* Unbiased exponent */ 49 j0 = ((((u _int32_t)i0) >> 20)&0x7ff)-0x3ff;49 j0 = ((((uint32_t)i0) >> 20)&0x7ff)-0x3ff; 50 50 51 51 if (j0 > 51) { … … 57 57 58 58 /* Sign */ 59 sx = ((u _int32_t)i0) >> 31;59 sx = ((uint32_t)i0) >> 31; 60 60 61 61 if (j0<20) { … … 81 81 } 82 82 } else { 83 i = ((u _int32_t)(0xffffffff))>>(j0-20);83 i = ((uint32_t)(0xffffffff))>>(j0-20); 84 84 if ((i1&i)==0) return x; /* x is integral */ 85 85 i>>=1;
Note: See TracChangeset
for help on using the changeset viewer.