Ignore:
Timestamp:
Oct 12, 2011, 12:01:44 AM (9 years ago)
Author:
sam
Message:

core: fix an accuracy error in real::re() and real::sqrt() introduced in
the 16-to-32-bit refactoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/real.cpp

    r1003 r1017  
    181181    }
    182182
    183     LOLUNIT_TEST(Division)
    184     {
    185         real a1(1.0f);
    186         real a2(2.0f);
    187 
    188         float m1 = a1 / a1;
    189         float m2 = a2 / a1;
    190         float m3 = a1 / a2;
    191         float m4 = a2 / a2;
    192         float m5 = a1 / -a2;
     183    LOLUNIT_TEST(ExactDivision)
     184    {
     185        float m1 = real::R_1 / real::R_1;
     186        float m2 = real::R_2 / real::R_1;
     187        float m3 = real::R_1 / real::R_2;
     188        float m4 = real::R_2 / real::R_2;
     189        float m5 = real::R_1 / -real::R_2;
    193190
    194191        LOLUNIT_ASSERT_EQUAL(m1, 1.0f);
     
    197194        LOLUNIT_ASSERT_EQUAL(m4, 1.0f);
    198195        LOLUNIT_ASSERT_EQUAL(m5, -0.5f);
     196    }
     197
     198    LOLUNIT_TEST(InexactDivision)
     199    {
     200        /* 1 / 3 * 3 should be close to 1... check that it does not differ
     201         * by more than 2^-k where k is the number of bits in the mantissa. */
     202        real a = real::R_1 / real::R_3 * real::R_3;
     203        real b = (real::R_1 - a) << (real::BIGITS * real::BIGIT_BITS);
     204
     205        LOLUNIT_ASSERT_LEQUAL((double)fabs(b), 1.0);
    199206    }
    200207
Note: See TracChangeset for help on using the changeset viewer.