Changeset 874


Ignore:
Timestamp:
Aug 29, 2011, 2:20:50 AM (12 years ago)
Author:
sam
Message:

core: rename half::isnan() etc. to half::is_nan() because "isnan" can be
a C macro on some systems (Android NDK, PS3...).

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/half.h

    r873 r874  
    3333    }
    3434
    35     inline int isnan() const
     35    inline int is_nan() const
    3636    {
    3737        return ((bits & 0x7c00u) == 0x7c00u) && (bits & 0x03ffu);
    3838    }
    3939
    40     inline int isfinite() const
     40    inline int is_finite() const
    4141    {
    4242        return (bits & 0x7c00u) != 0x7c00u;
    4343    }
    4444
    45     inline int isinf() const
     45    inline int is_inf() const
    4646    {
    4747        return (uint16_t)(bits << 1) == (0x7c00u << 1);
    4848    }
    4949
    50     inline int isnormal() const
     50    inline int is_normal() const
    5151    {
    52         return (isfinite() && (bits & 0x7c00u)) || ((bits & 0x7fffu) == 0);
     52        return (is_finite() && (bits & 0x7c00u)) || ((bits & 0x7fffu) == 0);
    5353    }
    5454
  • trunk/test/half.cpp

    r872 r874  
    2929    CPPUNIT_TEST(test_half_makeslow);
    3030    CPPUNIT_TEST(test_half_makefast);
    31     CPPUNIT_TEST(test_half_isnan);
    32     CPPUNIT_TEST(test_half_isinf);
    33     CPPUNIT_TEST(test_half_isfinite);
    34     CPPUNIT_TEST(test_half_isnormal);
     31    CPPUNIT_TEST(test_half_is_nan);
     32    CPPUNIT_TEST(test_half_is_inf);
     33    CPPUNIT_TEST(test_half_is_finite);
     34    CPPUNIT_TEST(test_half_is_normal);
    3535    CPPUNIT_TEST(test_half_classify);
    3636    CPPUNIT_TEST(test_half_to_float);
     
    7979    }
    8080
    81     void test_half_isnan()
    82     {
    83         CPPUNIT_ASSERT(half::makebits(0x7c01).isnan());
    84         CPPUNIT_ASSERT(half::makebits(0xfc01).isnan());
    85         CPPUNIT_ASSERT(half::makebits(0x7e00).isnan());
    86         CPPUNIT_ASSERT(half::makebits(0xfe00).isnan());
    87 
    88         CPPUNIT_ASSERT(!half::makebits(0x7c00).isnan());
    89         CPPUNIT_ASSERT(!half::makebits(0xfc00).isnan());
    90 
    91         CPPUNIT_ASSERT(!half(0.0f).isnan());
    92         CPPUNIT_ASSERT(!half(-0.0f).isnan());
    93         CPPUNIT_ASSERT(!half(2.0f).isnan());
    94         CPPUNIT_ASSERT(!half(-2.0f).isnan());
    95     }
    96 
    97     void test_half_isinf()
    98     {
    99         CPPUNIT_ASSERT(half(65536.0f).isinf());
    100         CPPUNIT_ASSERT(half(-65536.0f).isinf());
    101 
    102         CPPUNIT_ASSERT(!half(0.0f).isinf());
    103         CPPUNIT_ASSERT(!half(-0.0f).isinf());
    104         CPPUNIT_ASSERT(!half(65535.0f).isinf());
    105         CPPUNIT_ASSERT(!half(-65535.0f).isinf());
    106 
    107         CPPUNIT_ASSERT(half::makebits(0x7c00).isinf());
    108         CPPUNIT_ASSERT(half::makebits(0xfc00).isinf());
    109 
    110         CPPUNIT_ASSERT(!half::makebits(0x7e00).isinf());
    111         CPPUNIT_ASSERT(!half::makebits(0xfe00).isinf());
    112     }
    113 
    114     void test_half_isfinite()
    115     {
    116         CPPUNIT_ASSERT(half(0.0f).isfinite());
    117         CPPUNIT_ASSERT(half(-0.0f).isfinite());
    118         CPPUNIT_ASSERT(half(65535.0f).isfinite());
    119         CPPUNIT_ASSERT(half(-65535.0f).isfinite());
    120 
    121         CPPUNIT_ASSERT(!half(65536.0f).isfinite());
    122         CPPUNIT_ASSERT(!half(-65536.0f).isfinite());
    123 
    124         CPPUNIT_ASSERT(!half::makebits(0x7c00).isfinite());
    125         CPPUNIT_ASSERT(!half::makebits(0xfc00).isfinite());
    126 
    127         CPPUNIT_ASSERT(!half::makebits(0x7e00).isfinite());
    128         CPPUNIT_ASSERT(!half::makebits(0xfe00).isfinite());
    129     }
    130 
    131     void test_half_isnormal()
    132     {
    133         CPPUNIT_ASSERT(half(0.0f).isnormal());
    134         CPPUNIT_ASSERT(half(-0.0f).isnormal());
    135         CPPUNIT_ASSERT(half(65535.0f).isnormal());
    136         CPPUNIT_ASSERT(half(-65535.0f).isnormal());
    137 
    138         CPPUNIT_ASSERT(!half(65536.0f).isnormal());
    139         CPPUNIT_ASSERT(!half(-65536.0f).isnormal());
    140 
    141         CPPUNIT_ASSERT(!half::makebits(0x7c00).isnormal());
    142         CPPUNIT_ASSERT(!half::makebits(0xfc00).isnormal());
    143 
    144         CPPUNIT_ASSERT(!half::makebits(0x7e00).isnormal());
    145         CPPUNIT_ASSERT(!half::makebits(0xfe00).isnormal());
     81    void test_half_is_nan()
     82    {
     83        CPPUNIT_ASSERT(half::makebits(0x7c01).is_nan());
     84        CPPUNIT_ASSERT(half::makebits(0xfc01).is_nan());
     85        CPPUNIT_ASSERT(half::makebits(0x7e00).is_nan());
     86        CPPUNIT_ASSERT(half::makebits(0xfe00).is_nan());
     87
     88        CPPUNIT_ASSERT(!half::makebits(0x7c00).is_nan());
     89        CPPUNIT_ASSERT(!half::makebits(0xfc00).is_nan());
     90
     91        CPPUNIT_ASSERT(!half(0.0f).is_nan());
     92        CPPUNIT_ASSERT(!half(-0.0f).is_nan());
     93        CPPUNIT_ASSERT(!half(2.0f).is_nan());
     94        CPPUNIT_ASSERT(!half(-2.0f).is_nan());
     95    }
     96
     97    void test_half_is_inf()
     98    {
     99        CPPUNIT_ASSERT(half(65536.0f).is_inf());
     100        CPPUNIT_ASSERT(half(-65536.0f).is_inf());
     101
     102        CPPUNIT_ASSERT(!half(0.0f).is_inf());
     103        CPPUNIT_ASSERT(!half(-0.0f).is_inf());
     104        CPPUNIT_ASSERT(!half(65535.0f).is_inf());
     105        CPPUNIT_ASSERT(!half(-65535.0f).is_inf());
     106
     107        CPPUNIT_ASSERT(half::makebits(0x7c00).is_inf());
     108        CPPUNIT_ASSERT(half::makebits(0xfc00).is_inf());
     109
     110        CPPUNIT_ASSERT(!half::makebits(0x7e00).is_inf());
     111        CPPUNIT_ASSERT(!half::makebits(0xfe00).is_inf());
     112    }
     113
     114    void test_half_is_finite()
     115    {
     116        CPPUNIT_ASSERT(half(0.0f).is_finite());
     117        CPPUNIT_ASSERT(half(-0.0f).is_finite());
     118        CPPUNIT_ASSERT(half(65535.0f).is_finite());
     119        CPPUNIT_ASSERT(half(-65535.0f).is_finite());
     120
     121        CPPUNIT_ASSERT(!half(65536.0f).is_finite());
     122        CPPUNIT_ASSERT(!half(-65536.0f).is_finite());
     123
     124        CPPUNIT_ASSERT(!half::makebits(0x7c00).is_finite());
     125        CPPUNIT_ASSERT(!half::makebits(0xfc00).is_finite());
     126
     127        CPPUNIT_ASSERT(!half::makebits(0x7e00).is_finite());
     128        CPPUNIT_ASSERT(!half::makebits(0xfe00).is_finite());
     129    }
     130
     131    void test_half_is_normal()
     132    {
     133        CPPUNIT_ASSERT(half(0.0f).is_normal());
     134        CPPUNIT_ASSERT(half(-0.0f).is_normal());
     135        CPPUNIT_ASSERT(half(65535.0f).is_normal());
     136        CPPUNIT_ASSERT(half(-65535.0f).is_normal());
     137
     138        CPPUNIT_ASSERT(!half(65536.0f).is_normal());
     139        CPPUNIT_ASSERT(!half(-65536.0f).is_normal());
     140
     141        CPPUNIT_ASSERT(!half::makebits(0x7c00).is_normal());
     142        CPPUNIT_ASSERT(!half::makebits(0xfc00).is_normal());
     143
     144        CPPUNIT_ASSERT(!half::makebits(0x7e00).is_normal());
     145        CPPUNIT_ASSERT(!half::makebits(0xfe00).is_normal());
    146146    }
    147147
     
    151151        {
    152152            half h = half::makebits(i);
    153             if (h.isnan())
    154             {
    155                 CPPUNIT_ASSERT(!h.isinf());
    156                 CPPUNIT_ASSERT(!h.isnormal());
    157                 CPPUNIT_ASSERT(!h.isfinite());
    158             }
    159             else if (h.isinf())
    160             {
    161                 CPPUNIT_ASSERT(!h.isnormal());
    162                 CPPUNIT_ASSERT(!h.isfinite());
     153            if (h.is_nan())
     154            {
     155                CPPUNIT_ASSERT(!h.is_inf());
     156                CPPUNIT_ASSERT(!h.is_normal());
     157                CPPUNIT_ASSERT(!h.is_finite());
     158            }
     159            else if (h.is_inf())
     160            {
     161                CPPUNIT_ASSERT(!h.is_normal());
     162                CPPUNIT_ASSERT(!h.is_finite());
    163163            }
    164164            else
    165165            {
    166                 CPPUNIT_ASSERT(h.isfinite());
     166                CPPUNIT_ASSERT(h.is_finite());
    167167            }
    168168        }
     
    183183            float f = (float)h;
    184184            half g = (half)f;
    185             if (h.isnan())
     185            if (h.is_nan())
    186186            {
    187187                CPPUNIT_ASSERT(isnan(f));
    188                 CPPUNIT_ASSERT(g.isnan());
     188                CPPUNIT_ASSERT(g.is_nan());
    189189            }
    190190            else
Note: See TracChangeset for help on using the changeset viewer.