| 95 | } |
| 96 | |
| 97 | void |
| 98 | testToFloat () |
| 99 | { |
| 100 | std::cout << "running testToFloat" << std::endl; |
| 101 | |
| 102 | constexpr int iMax = (1 << 16); |
| 103 | |
| 104 | // |
| 105 | // for each 16-bit bit pattern... |
| 106 | // |
| 107 | |
| 108 | for (unsigned int s = 0; s < iMax; s++) |
| 109 | { |
| 110 | half hs (half::FromBits, static_cast<unsigned short> (s)); |
| 111 | assert (hs.bits () == s); |
| 112 | |
| 113 | // |
| 114 | // cast these bits to a float, using the cast-to-float |
| 115 | // operator. |
| 116 | // |
| 117 | |
| 118 | float f = float (hs); // = _toFloat[s] |
| 119 | |
| 120 | // |
| 121 | // Cast that float back to a half. |
| 122 | // |
| 123 | |
| 124 | half h = half (f); |
| 125 | |
| 126 | // |
| 127 | // halfToFloat() above is what generated the _toFloat table. |
| 128 | // The i value return is the integer bit pattern of the corresponding |
| 129 | // float. |
| 130 | // |
| 131 | |
| 132 | half::uif uif; |
| 133 | uif.i = halfToFloat (s); |
| 134 | |
| 135 | // |
| 136 | // Equality operators fail for inf and nan, so handle them |
| 137 | // specially. |
| 138 | // |
| 139 | |
| 140 | if (isnan (f)) |
| 141 | { |
| 142 | assert (h.isNan ()); |
| 143 | assert (isnan (uif.f)); |
| 144 | } |
| 145 | else if (isinf (f)) |
| 146 | { |
| 147 | assert (h.isInfinity ()); |
| 148 | assert (isinf (uif.f)); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | assert (f == uif.f); |
| 153 | } |
| 154 | } |
nothing calls this directly
no test coverage detected