Skip to content

Commit 67f0ec6

Browse files
Add FMA special-case tests: NaN, infinity, 0*inf
Test IEEE 754 FMA special cases that were previously handled by the C library model but are now handled by float_utilst::fma: - fma(NaN, y, z) = NaN - fma(x, NaN, z) = NaN - fma(x, y, NaN) = NaN - fma(0, inf, z) = NaN (0 * inf undefined) - fma(inf, 0, z) = NaN - fma(inf, x, -inf) = NaN (inf + (-inf) undefined) - fma(inf, x, z) = +inf for finite z - fma(x, y, inf) = +inf for finite x*y Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
1 parent 6f7f3b4 commit 67f0ec6

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// IEEE 754 FMA special cases
2+
#include <assert.h>
3+
#include <math.h>
4+
5+
int main()
6+
{
7+
// fma(NaN, y, z) = NaN
8+
assert(isnan(fmaf(NAN, 1.0f, 0.0f)));
9+
10+
// fma(x, NaN, z) = NaN
11+
assert(isnan(fmaf(1.0f, NAN, 0.0f)));
12+
13+
// fma(x, y, NaN) = NaN
14+
assert(isnan(fmaf(1.0f, 1.0f, NAN)));
15+
16+
// fma(0, inf, z) = NaN (0 * inf is undefined)
17+
assert(isnan(fmaf(0.0f, INFINITY, 1.0f)));
18+
19+
// fma(inf, 0, z) = NaN
20+
assert(isnan(fmaf(INFINITY, 0.0f, 1.0f)));
21+
22+
// fma(inf, x, -inf) = NaN when inf*x = +inf (inf + (-inf) is undefined)
23+
assert(isnan(fmaf(INFINITY, 1.0f, -INFINITY)));
24+
25+
// fma(inf, x, z) = +inf for finite z
26+
assert(isinf(fmaf(INFINITY, 2.0f, 3.0f)));
27+
28+
// fma(x, y, inf) = +inf for finite x*y
29+
assert(isinf(fmaf(2.0f, 3.0f, INFINITY)));
30+
31+
return 0;
32+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
special_cases.c
3+
--floatbv --no-built-in-assertions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
IEEE 754 FMA special cases: NaN propagation, 0*inf, inf+(-inf), inf results.

0 commit comments

Comments
 (0)