Changeset 1893 for trunk/test


Ignore:
Timestamp:
Sep 9, 2012, 4:55:26 PM (8 years ago)
Author:
sam
Message:

math: refactor real number constant declarations so that they are only
computed on demand with static initialisation.

Location:
trunk/test
Files:
3 edited

Legend:

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

    r1647 r1893  
    2424int main(int argc, char **argv)
    2525{
    26     printf("Pi: "); real::R_PI.print();
    27     printf("e: "); real::R_E.print();
    28     printf("ln(2): "); real::R_LN2.print();
    29     printf("sqrt(2): "); real::R_SQRT2.print();
    30     printf("sqrt(1/2): "); real::R_SQRT1_2.print();
     26    printf("Pi: "); real::R_PI().print();
     27    printf("e: "); real::R_E().print();
     28    printf("ln(2): "); real::R_LN2().print();
     29    printf("sqrt(2): "); real::R_SQRT2().print();
     30    printf("sqrt(1/2): "); real::R_SQRT1_2().print();
    3131
    3232    /* Gauss-Legendre computation of Pi -- doesn't work well at all,
  • trunk/test/math/poly.cpp

    r1647 r1893  
    8585{
    8686    return lol_sin(f);
    87     //static float const k = (float)real::R_2_PI;
     87    //static float const k = (float)real::R_2_PI();
    8888
    8989    //f *= k;
     
    120120
    121121printf("-- START --\n");
    122     for (flint u = { (float)real::R_PI_2 }; u.f > 1e-30; u.x -= 1)
     122    for (flint u = { (float)real::R_PI_2() }; u.f > 1e-30; u.x -= 1)
    123123    {
    124124        union { float f; uint32_t x; } s1 = { sinf(adjustf(u.f, 0)) };
  • trunk/test/unit/real.cpp

    r1668 r1893  
    2525    LOLUNIT_TEST(Constants)
    2626    {
    27         double a0 = real::R_0;
    28         double a1 = real::R_1;
    29         double a2 = real::R_2;
    30         double a10 = real::R_10;
     27        double a0 = real::R_0();
     28        double a1 = real::R_1();
     29        double a2 = real::R_2();
     30        double a10 = real::R_10();
    3131
    3232        LOLUNIT_ASSERT_EQUAL(a0, 0.0);
     
    3535        LOLUNIT_ASSERT_EQUAL(a10, 10.0);
    3636
    37         double b1 = log(real::R_E);
    38         double b2 = log2(real::R_2);
     37        double b1 = log(real::R_E());
     38        double b2 = log2(real::R_2());
    3939        LOLUNIT_ASSERT_EQUAL(b1, 1.0);
    4040        LOLUNIT_ASSERT_EQUAL(b2, 1.0);
    4141
    42         double c1 = exp(re(real::R_LOG2E));
    43         double c2 = log(exp2(real::R_LOG2E));
     42        double c1 = exp(re(real::R_LOG2E()));
     43        double c2 = log(exp2(real::R_LOG2E()));
    4444        LOLUNIT_ASSERT_EQUAL(c1, 2.0);
    4545        LOLUNIT_ASSERT_EQUAL(c2, 1.0);
    4646
    47         double d1 = exp(re(real::R_LOG10E));
     47        double d1 = exp(re(real::R_LOG10E()));
    4848        LOLUNIT_ASSERT_EQUAL(d1, 10.0);
    4949
    50         double e1 = exp(real::R_LN2);
     50        double e1 = exp(real::R_LN2());
    5151        LOLUNIT_ASSERT_EQUAL(e1, 2.0);
    5252
    53         double f1 = exp(real::R_LN10);
     53        double f1 = exp(real::R_LN10());
    5454        LOLUNIT_ASSERT_EQUAL(f1, 10.0);
    5555
    56         double g1 = sin(real::R_PI);
    57         double g2 = cos(real::R_PI);
     56        double g1 = sin(real::R_PI());
     57        double g2 = cos(real::R_PI());
    5858        LOLUNIT_ASSERT_DOUBLES_EQUAL(g1, 0.0, 1e-100);
    5959        LOLUNIT_ASSERT_EQUAL(g2, -1.0);
    6060
    61         double h1 = sin(real::R_PI_2);
    62         double h2 = cos(real::R_PI_2);
     61        double h1 = sin(real::R_PI_2());
     62        double h2 = cos(real::R_PI_2());
    6363        LOLUNIT_ASSERT_EQUAL(h1, 1.0);
    6464        LOLUNIT_ASSERT_DOUBLES_EQUAL(h2, 0.0, 1e-100);
    6565
    66         double i1 = sin(real::R_PI_4) * sin(real::R_PI_4);
    67         double i2 = cos(real::R_PI_4) * cos(real::R_PI_4);
     66        double i1 = sin(real::R_PI_4()) * sin(real::R_PI_4());
     67        double i2 = cos(real::R_PI_4()) * cos(real::R_PI_4());
    6868        LOLUNIT_ASSERT_EQUAL(i1, 0.5);
    6969        LOLUNIT_ASSERT_EQUAL(i2, 0.5);
     
    219219    LOLUNIT_TEST(ExactDivision)
    220220    {
    221         float m1 = real::R_1 / real::R_1;
    222         float m2 = real::R_2 / real::R_1;
    223         float m3 = real::R_1 / real::R_2;
    224         float m4 = real::R_2 / real::R_2;
    225         float m5 = real::R_1 / -real::R_2;
     221        float m1 = real::R_1() / real::R_1();
     222        float m2 = real::R_2() / real::R_1();
     223        float m3 = real::R_1() / real::R_2();
     224        float m4 = real::R_2() / real::R_2();
     225        float m5 = real::R_1() / -real::R_2();
    226226
    227227        LOLUNIT_ASSERT_EQUAL(m1, 1.0f);
     
    236236        /* 1 / 3 * 3 should be close to 1... check that it does not differ
    237237         * by more than 2^-k where k is the number of bits in the mantissa. */
    238         real a = real::R_1 / real::R_3 * real::R_3;
    239         real b = ldexp(real::R_1 - a, real::BIGITS * real::BIGIT_BITS);
     238        real a = real::R_1() / real::R_3() * real::R_3();
     239        real b = ldexp(real::R_1() - a, real::BIGITS * real::BIGIT_BITS);
    240240
    241241        LOLUNIT_ASSERT_LEQUAL((double)fabs(b), 1.0);
     
    260260    LOLUNIT_TEST(Ulp)
    261261    {
    262         real a1 = real::R_PI;
     262        real a1 = real::R_PI();
    263263
    264264        LOLUNIT_ASSERT_NOT_EQUAL((double)(a1 + ulp(a1) - a1), 0.0);
     
    347347    LOLUNIT_TEST(Pow)
    348348    {
    349         double a1 = pow(-real::R_2, real::R_2);
     349        double a1 = pow(-real::R_2(), real::R_2());
    350350        double b1 = 4.0;
    351351        LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, 1.0e-13);
    352352
    353         double a2 = pow(-real::R_2, real::R_3);
     353        double a2 = pow(-real::R_2(), real::R_3());
    354354        double b2 = -8.0;
    355355        LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, 1.0e-13);
Note: See TracChangeset for help on using the changeset viewer.