Changeset 1015
 Timestamp:
 Oct 10, 2011, 3:33:18 AM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/math/poly.cpp
r1012 r1015 20 20 using namespace std; 21 21 22 static float adjustf(float f, int i) 22 float adjustf(float f, int i) __attribute__((noinline)); 23 float adjustf(float f, int i) 23 24 { 24 25 union { float f; uint32_t x; } u = { f }; … … 27 28 } 28 29 29 static double adjust(double f, int i) 30 double adjust(double f, int i) __attribute__((noinline)); 31 double adjust(double f, int i) 30 32 { 31 33 union { double f; uint64_t x; } u = { f }; … … 37 39 { 38 40 union { float f; uint32_t x; } u = { f }; 39 printf("%08x % g  ", u.x, u.f);41 printf("%08x %14.12g  ", u.x, u.f); 40 42 int i = (u.x & 0x7fffffu)  0x800000u; 41 43 int j = 23  ((u.x >> 23) & 0xff) + ((1 << 7)  1); 42 44 if (u.f <= 0) 43 45 i = i; 44 printf("%i / 2^%i = % g\n", i, j, (float)i / (1LLu << j));46 printf("%i / 2^%i = %14.12g\n", i, j, (float)i / (1LLu << j)); 45 47 } 46 48 47 49 //#define float double 48 50 #if 1 51 static float const a0 = 1.0; 52 static float const a1 = 0.1666666666663036; 53 static float const a2 = 0.008333333325075758; 54 static float const a3 = 0.0001984126372689299; 55 static float const a4 = 2.755533925906394e06; 56 static float const a5 = 2.476042626296988e08; 57 static float const a6 = 0.0; 58 #elif 0 49 59 static float const a0 = adjust(0.9999999999999376, 0); 50 60 static float const a1 = adjust(0.1666666666643236, 0); … … 74 84 static float floatsin(float f) 75 85 { 76 //return lol_sin(f);86 return lol_sin(f); 77 87 //static float const k = (float)real::R_2_PI; 78 88 … … 88 98 int main(void) 89 99 { 100 typedef union { float f; uint32_t x; } flint; 101 90 102 int error[5] = { 0 }; 91 103 … … 97 109 inspect(a5); 98 110 99 for (float f = (float)real::R_PI_2; f > 1e30; f = adjustf(f, 1)) 111 //flint v = { 1.433971524239 }; 112 flint v = { 1.555388212204 }; 113 inspect(v.f); 114 printf("sinf: "); 115 flint w = { sinf(adjustf(v.f, 0)) }; 116 inspect(w.f); 117 printf("lols: "); 118 flint z = { lol_sin(adjustf(v.f, 0)) }; 119 inspect(z.f); 120 121 printf(" START \n"); 122 for (flint u = { (float)real::R_PI_2 }; u.f > 1e30; u.x = 1) 100 123 { 101 union { float f; uint32_t x; } u = { f }; 102 union { float f; uint32_t x; } s1 = { sinf(f) }; 103 union { float f; uint32_t x; } s2 = { floatsin(f) }; 124 union { float f; uint32_t x; } s1 = { sinf(adjustf(u.f, 0)) }; 125 union { float f; uint32_t x; } s2 = { floatsin(adjustf(u.f, 0)) }; 104 126 int e = abs((int)(s1.x  s2.x)); 105 127 switch (e) 106 128 { 107 129 case 3: 108 if (fabs((double)s1.f  (double)s2.f) > 1e10 * fabs(s1.f))109 printf("%15.13g %08x: %15.13g %15.13g %08x %08x\n", f, u.x, s1.f, s2.f, s1.x, s2.x);110 130 case 2: 111 131 case 1: 132 inspect(u.f); 133 printf("sinf: "); 134 inspect(sinf(u.f)); 135 if (fabs((double)s1.f  (double)s2.f) > 1e10 * fabs(s1.f)) 136 printf("%15.13g %08x: %15.13g %15.13g %08x %08x\n", u.f, u.x, s1.f, s2.f, s1.x, s2.x); 112 137 case 0: 113 138 error[e]++;
Note: See TracChangeset
for help on using the changeset viewer.