| 245 | } |
| 246 | |
| 247 | TEST(TestWithinUlp, Double) { |
| 248 | for (double f : {0.0, 1e-20, 1.0, 2345678.9}) { |
| 249 | CheckWithinUlp(f, f, 0); |
| 250 | CheckWithinUlp(f, f, 1); |
| 251 | CheckWithinUlp(f, f, 42); |
| 252 | } |
| 253 | CheckWithinUlp(-0.0, 0.0, 1); |
| 254 | CheckWithinUlp(1.0, 1.0000000000000002, 1); |
| 255 | CheckWithinUlp(1.0, 1.0000000000000007, 3); |
| 256 | CheckNotWithinUlp(1.0, 1.0000000000000002, 0); |
| 257 | CheckNotWithinUlp(1.0, 1.0000000000000007, 2); |
| 258 | CheckNotWithinUlp(1.0, 1.0000000000000007, 1); |
| 259 | // left and right have a different exponent but are still very close |
| 260 | CheckWithinUlp(1.0, 0.9999999999999999, 1); |
| 261 | CheckWithinUlp(1.0, 0.9999999999999988, 11); |
| 262 | CheckNotWithinUlp(1.0, 0.9999999999999988, 10); |
| 263 | CheckWithinUlp(1.0000000000000002, 0.9999999999999999, 2); |
| 264 | CheckNotWithinUlp(1.0000000000000002, 0.9999999999999999, 1); |
| 265 | CheckWithinUlp(0.9999999999999988, 1.0000000000000007, 14); |
| 266 | CheckNotWithinUlp(0.9999999999999988, 1.0000000000000007, 13); |
| 267 | |
| 268 | CheckWithinUlp(123.4567, 123.45670000000015, 11); |
| 269 | CheckNotWithinUlp(123.4567, 123.45670000000015, 10); |
| 270 | |
| 271 | CheckWithinUlp(HUGE_VAL, HUGE_VAL, 10); |
| 272 | CheckWithinUlp(-HUGE_VAL, -HUGE_VAL, 10); |
| 273 | CheckWithinUlp(std::nan(""), std::nan(""), 10); |
| 274 | CheckNotWithinUlp(HUGE_VAL, -HUGE_VAL, 10); |
| 275 | CheckNotWithinUlp(12.34, -HUGE_VAL, 10); |
| 276 | CheckNotWithinUlp(12.34, std::nan(""), 10); |
| 277 | CheckNotWithinUlp(12.34, -12.34, 10); |
| 278 | CheckNotWithinUlp(0.0, 1e-20, 10); |
| 279 | } |
| 280 | |
| 281 | TEST(TestWithinUlp, Float) { |
| 282 | for (float f : {0.0f, 1e-8f, 1.0f, 123.456f}) { |
nothing calls this directly
no test coverage detected