| 104 | { |
| 105 | |
| 106 | void |
| 107 | testNormalizedRounding (int n) |
| 108 | { |
| 109 | cout << "rounding normalized numbers to " << n << "-bit precision\n"; |
| 110 | |
| 111 | float eExpected = (n < 10) ? HALF_EPSILON * 0.5f * (1 << (10 - n)) : 0; |
| 112 | float eMax = 0; |
| 113 | |
| 114 | for (int i = 0; i < 200000; i++) |
| 115 | { |
| 116 | half h (drand () * HALF_MAX); |
| 117 | |
| 118 | if (h < HALF_NRM_MIN) continue; |
| 119 | |
| 120 | if (i & 1) h = -h; |
| 121 | |
| 122 | half r (h.round (n)); |
| 123 | float e = 1.0f - r / h; |
| 124 | |
| 125 | if (e < 0) e = -e; |
| 126 | |
| 127 | if (e > eExpected) |
| 128 | { |
| 129 | cout << "half = " << h << ", rounded = " << r << ", error = " << e |
| 130 | << ", expected error = " << eExpected << endl; |
| 131 | |
| 132 | printBits (cout, h); |
| 133 | cout << endl; |
| 134 | printBits (cout, r); |
| 135 | cout << endl; |
| 136 | |
| 137 | assert (false); |
| 138 | } |
| 139 | |
| 140 | if (e > eMax) eMax = e; |
| 141 | } |
| 142 | |
| 143 | cout << "max error = " << eMax << endl; |
| 144 | cout << "max expected error = " << eExpected << endl; |
| 145 | cout << "ok\n\n" << flush; |
| 146 | } |
| 147 | |
| 148 | void |
| 149 | testDenormalizedRounding (int n) |
no test coverage detected