Changeset 874
 Timestamp:
 Aug 29, 2011, 2:20:50 AM (8 years ago)
 Location:
 trunk
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/half.h
r873 r874 33 33 } 34 34 35 inline int is nan() const35 inline int is_nan() const 36 36 { 37 37 return ((bits & 0x7c00u) == 0x7c00u) && (bits & 0x03ffu); 38 38 } 39 39 40 inline int is finite() const40 inline int is_finite() const 41 41 { 42 42 return (bits & 0x7c00u) != 0x7c00u; 43 43 } 44 44 45 inline int is inf() const45 inline int is_inf() const 46 46 { 47 47 return (uint16_t)(bits << 1) == (0x7c00u << 1); 48 48 } 49 49 50 inline int is normal() const50 inline int is_normal() const 51 51 { 52 return (is finite() && (bits & 0x7c00u))  ((bits & 0x7fffu) == 0);52 return (is_finite() && (bits & 0x7c00u))  ((bits & 0x7fffu) == 0); 53 53 } 54 54 
trunk/test/half.cpp
r872 r874 29 29 CPPUNIT_TEST(test_half_makeslow); 30 30 CPPUNIT_TEST(test_half_makefast); 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);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); 35 35 CPPUNIT_TEST(test_half_classify); 36 36 CPPUNIT_TEST(test_half_to_float); … … 79 79 } 80 80 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());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()); 146 146 } 147 147 … … 151 151 { 152 152 half h = half::makebits(i); 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());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()); 163 163 } 164 164 else 165 165 { 166 CPPUNIT_ASSERT(h.is finite());166 CPPUNIT_ASSERT(h.is_finite()); 167 167 } 168 168 } … … 183 183 float f = (float)h; 184 184 half g = (half)f; 185 if (h.is nan())185 if (h.is_nan()) 186 186 { 187 187 CPPUNIT_ASSERT(isnan(f)); 188 CPPUNIT_ASSERT(g.is nan());188 CPPUNIT_ASSERT(g.is_nan()); 189 189 } 190 190 else
Note: See TracChangeset
for help on using the changeset viewer.