1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_divsf3
10 COMPILER_RT_ABI
float __divsf3(float a
, float b
);
12 int test__divsf3(float a
, float b
, uint32_t expected
)
14 float x
= __divsf3(a
, b
);
15 int ret
= compareResultF(x
, expected
);
18 printf("error in test__divsf3(%.20e, %.20e) = %.20e, "
19 "expected %.20e\n", a
, b
, x
,
27 // Returned NaNs are assumed to be qNaN by default
30 if (test__divsf3(makeQNaN32(), 3.F
, UINT32_C(0x7fc00000)))
33 if (test__divsf3(makeNaN32(UINT32_C(0x123)), 3.F
, UINT32_C(0x7fc00000)))
36 if (test__divsf3(3.F
, makeQNaN32(), UINT32_C(0x7fc00000)))
39 if (test__divsf3(3.F
, makeNaN32(UINT32_C(0x123)), UINT32_C(0x7fc00000)))
42 // +Inf / positive = +Inf
43 if (test__divsf3(makeInf32(), 3.F
, UINT32_C(0x7f800000)))
45 // +Inf / negative = -Inf
46 if (test__divsf3(makeInf32(), -3.F
, UINT32_C(0xff800000)))
48 // -Inf / positive = -Inf
49 if (test__divsf3(makeNegativeInf32(), 3.F
, UINT32_C(0xff800000)))
51 // -Inf / negative = +Inf
52 if (test__divsf3(makeNegativeInf32(), -3.F
, UINT32_C(0x7f800000)))
56 if (test__divsf3(makeInf32(), makeInf32(), UINT32_C(0x7fc00000)))
59 if (test__divsf3(+0x0.0p
+0F
, +0x0.0p
+0F
, UINT32_C(0x7fc00000)))
62 if (test__divsf3(+0x0.0p
+0F
, makeInf32(), UINT32_C(0x0)))
65 if (test__divsf3(makeInf32(), +0x0.0p
+0F
, UINT32_C(0x7f800000)))
68 // positive / +0.0 = +Inf
69 if (test__divsf3(+1.F
, +0x0.0p
+0F
, UINT32_C(0x7f800000)))
71 // positive / -0.0 = -Inf
72 if (test__divsf3(+1.F
, -0x0.0p
+0F
, UINT32_C(0xff800000)))
74 // negative / +0.0 = -Inf
75 if (test__divsf3(-1.F
, +0x0.0p
+0F
, UINT32_C(0xff800000)))
77 // negative / -0.0 = +Inf
78 if (test__divsf3(-1.F
, -0x0.0p
+0F
, UINT32_C(0x7f800000)))
82 if (test__divsf3(1.F
, 3.F
, UINT32_C(0x3eaaaaab)))
84 // smallest normal result
85 if (test__divsf3(0x1.0p
-125F
, 2.F
, UINT32_C(0x00800000)))
88 // divisor is exactly 1.0
89 if (test__divsf3(0x1.0p
+0F
, 0x1.0p
+0F
, UINT32_C(0x3f800000)))
91 // divisor is truncated to exactly 1.0 in UQ1.15
92 if (test__divsf3(0x1.0p
+0F
, 0x1.0001p
+0F
, UINT32_C(0x3f7fff00)))
95 // smallest normal value divided by 2.0
96 if (test__divsf3(0x1.0p
-126F
, 2.0F
, UINT32_C(0x00400000)))
98 // smallest subnormal result
99 if (test__divsf3(0x1.0p
-126F
, 0x1p
+23F
, UINT32_C(0x00000001)))
102 // some misc test cases obtained by fuzzing against h/w implementation
103 if (test__divsf3(-0x1.3e75e6p
-108F
, -0x1.cf372p
+38F
, UINT32_C(0x00000006)))
105 if (test__divsf3(0x1.e77c54p
+81F
, -0x1.e77c52p
-47F
, UINT32_C(0xff800000)))
107 if (test__divsf3(0x1.fffffep
-126F
, 2.F
, UINT32_C(0x00800000)))