Changeset 1015


Ignore:
Timestamp:
Oct 10, 2011, 3:33:18 AM (9 years ago)
Author:
sam
Message:

test: random useless crap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/math/poly.cpp

    r1012 r1015  
    2020using namespace std;
    2121
    22 static float adjustf(float f, int i)
     22float adjustf(float f, int i) __attribute__((noinline));
     23float adjustf(float f, int i)
    2324{
    2425    union { float f; uint32_t x; } u = { f };
     
    2728}
    2829
    29 static double adjust(double f, int i)
     30double adjust(double f, int i) __attribute__((noinline));
     31double adjust(double f, int i)
    3032{
    3133    union { double f; uint64_t x; } u = { f };
     
    3739{
    3840    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);
    4042    int i = (u.x & 0x7fffffu) | 0x800000u;
    4143    int j = 23 - ((u.x >> 23) & 0xff) + ((1 << 7) - 1);
    4244    if (u.f <= 0)
    4345        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));
    4547}
    4648
    4749//#define float double
    4850#if 1
     51static float const a0 = 1.0;
     52static float const a1 = -0.1666666666663036;
     53static float const a2 = 0.008333333325075758;
     54static float const a3 = -0.0001984126372689299;
     55static float const a4 = 2.755533925906394e-06;
     56static float const a5 = -2.476042626296988e-08;
     57static float const a6 = 0.0;
     58#elif 0
    4959static float const a0 = adjust(0.9999999999999376, 0);
    5060static float const a1 = adjust(-0.1666666666643236, 0);
     
    7484static float floatsin(float f)
    7585{
    76     //return lol_sin(f);
     86    return lol_sin(f);
    7787    //static float const k = (float)real::R_2_PI;
    7888
     
    8898int main(void)
    8999{
     100    typedef union { float f; uint32_t x; } flint;
     101
    90102    int error[5] = { 0 };
    91103
     
    97109    inspect(a5);
    98110
    99     for (float f = (float)real::R_PI_2; f > 1e-30; f = adjustf(f, -1))
     111//flint v = { 1.433971524239 };
     112flint v = { 1.555388212204 };
     113inspect(v.f);
     114printf("sinf: ");
     115flint w = { sinf(adjustf(v.f, 0)) };
     116inspect(w.f);
     117printf("lols: ");
     118flint z = { lol_sin(adjustf(v.f, 0)) };
     119inspect(z.f);
     120
     121printf("-- START --\n");
     122    for (flint u = { (float)real::R_PI_2 }; u.f > 1e-30; u.x -= 1)
    100123    {
    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)) };
    104126        int e = abs((int)(s1.x - s2.x));
    105127        switch (e)
    106128        {
    107129        case 3:
    108             if (fabs((double)s1.f - (double)s2.f) > 1e-10 * 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);
    110130        case 2:
    111131        case 1:
     132inspect(u.f);
     133printf("sinf: ");
     134inspect(sinf(u.f));
     135            if (fabs((double)s1.f - (double)s2.f) > 1e-10 * 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);
    112137        case 0:
    113138            error[e]++;
Note: See TracChangeset for help on using the changeset viewer.