|
| 1 | +// Test case for bug fix: finite / +INFINITY should NOT trigger --nan-check |
| 2 | +// According to IEEE 754-2019 Section 6.1: "division(x, ∞) for finite x" |
| 3 | +// should produce 0.0, not NaN. Hence, none of the operations below should |
| 4 | +// trigger nan-check assertions. |
| 5 | + |
| 6 | +#include <assert.h> |
| 7 | +#include <math.h> |
| 8 | +#include <stdint.h> |
| 9 | + |
| 10 | +union float_bits |
| 11 | +{ |
| 12 | + uint32_t u; |
| 13 | + float f; |
| 14 | +}; |
| 15 | + |
| 16 | +int main(void) |
| 17 | +{ |
| 18 | + // Test case 1: Using union to create +INFINITY as mentioned in the bug report |
| 19 | + union float_bits a, b; |
| 20 | + a.u = 1065353216; // 1.0 |
| 21 | + b.u = 2139095040; // +INF |
| 22 | + |
| 23 | + // This should produce 0.0, not NaN - should NOT trigger nan-check failure |
| 24 | + float result1 = a.f / b.f; |
| 25 | + assert(fpclassify(result1) == FP_ZERO && !signbit(result1)); |
| 26 | + |
| 27 | + // Test case 2: Direct assignment as mentioned in the bug report |
| 28 | + float x = 1.0f; |
| 29 | + float y = INFINITY; |
| 30 | + float result2 = x / y; |
| 31 | + assert(fpclassify(result2) == FP_ZERO && !signbit(result2)); |
| 32 | + |
| 33 | + // Test case 3: Negative finite / infinity should also be 0.0 (negative zero) |
| 34 | + float neg_x = -1.0f; |
| 35 | + float result3 = neg_x / INFINITY; |
| 36 | + assert(fpclassify(result3) == FP_ZERO && signbit(result3)); |
| 37 | + |
| 38 | + // Test case 4: Various finite values divided by infinity |
| 39 | + float nd_positive = __VERIFIER_nondet_float(); |
| 40 | + __CPROVER_assume(isfinite(nd_positive) && nd_positive > 0); |
| 41 | + float result4 = nd_positive / INFINITY; |
| 42 | + assert(fpclassify(result4) == FP_ZERO && !signbit(result4)); |
| 43 | + float nd_negative = __VERIFIER_nondet_float(); |
| 44 | + __CPROVER_assume(isfinite(nd_negative) && nd_negative < 0); |
| 45 | + float result5 = nd_negative / INFINITY; |
| 46 | + assert(fpclassify(result5) == FP_ZERO && signbit(result5)); |
| 47 | + |
| 48 | + return 0; |
| 49 | +} |
0 commit comments