1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_divsf3
3
4#include "int_lib.h"
5#include <stdio.h>
6
7#include "fp_test.h"
8
9// Returns: a / b
10COMPILER_RT_ABI float __divsf3(float a, float b);
11
12int test__divsf3(float a, float b, uint32_t expected)
13{
14 float x = __divsf3(a, b);
15 int ret = compareResultF(result: x, expected);
16
17 if (ret){
18 printf(format: "error in test__divsf3(%.20e, %.20e) = %.20e, "
19 "expected %.20e\n", a, b, x,
20 fromRep32(x: expected));
21 }
22 return ret;
23}
24
25int main()
26{
27 // Returned NaNs are assumed to be qNaN by default
28
29 // qNaN / any = qNaN
30 if (test__divsf3(a: makeQNaN32(), b: 3.F, UINT32_C(0x7fc00000)))
31 return 1;
32 // NaN / any = NaN
33 if (test__divsf3(a: makeNaN32(UINT32_C(0x123)), b: 3.F, UINT32_C(0x7fc00000)))
34 return 1;
35 // any / qNaN = qNaN
36 if (test__divsf3(a: 3.F, b: makeQNaN32(), UINT32_C(0x7fc00000)))
37 return 1;
38 // any / NaN = NaN
39 if (test__divsf3(a: 3.F, b: makeNaN32(UINT32_C(0x123)), UINT32_C(0x7fc00000)))
40 return 1;
41
42 // +Inf / positive = +Inf
43 if (test__divsf3(a: makeInf32(), b: 3.F, UINT32_C(0x7f800000)))
44 return 1;
45 // +Inf / negative = -Inf
46 if (test__divsf3(a: makeInf32(), b: -3.F, UINT32_C(0xff800000)))
47 return 1;
48 // -Inf / positive = -Inf
49 if (test__divsf3(a: makeNegativeInf32(), b: 3.F, UINT32_C(0xff800000)))
50 return 1;
51 // -Inf / negative = +Inf
52 if (test__divsf3(a: makeNegativeInf32(), b: -3.F, UINT32_C(0x7f800000)))
53 return 1;
54
55 // Inf / Inf = NaN
56 if (test__divsf3(a: makeInf32(), b: makeInf32(), UINT32_C(0x7fc00000)))
57 return 1;
58 // 0.0 / 0.0 = NaN
59 if (test__divsf3(a: +0x0.0p+0F, b: +0x0.0p+0F, UINT32_C(0x7fc00000)))
60 return 1;
61 // +0.0 / +Inf = +0.0
62 if (test__divsf3(a: +0x0.0p+0F, b: makeInf32(), UINT32_C(0x0)))
63 return 1;
64 // +Inf / +0.0 = +Inf
65 if (test__divsf3(a: makeInf32(), b: +0x0.0p+0F, UINT32_C(0x7f800000)))
66 return 1;
67
68 // positive / +0.0 = +Inf
69 if (test__divsf3(a: +1.F, b: +0x0.0p+0F, UINT32_C(0x7f800000)))
70 return 1;
71 // positive / -0.0 = -Inf
72 if (test__divsf3(a: +1.F, b: -0x0.0p+0F, UINT32_C(0xff800000)))
73 return 1;
74 // negative / +0.0 = -Inf
75 if (test__divsf3(a: -1.F, b: +0x0.0p+0F, UINT32_C(0xff800000)))
76 return 1;
77 // negative / -0.0 = +Inf
78 if (test__divsf3(a: -1.F, b: -0x0.0p+0F, UINT32_C(0x7f800000)))
79 return 1;
80
81 // 1/3
82 if (test__divsf3(a: 1.F, b: 3.F, UINT32_C(0x3eaaaaab)))
83 return 1;
84 // smallest normal result
85 if (test__divsf3(a: 0x1.0p-125F, b: 2.F, UINT32_C(0x00800000)))
86 return 1;
87
88 // divisor is exactly 1.0
89 if (test__divsf3(a: 0x1.0p+0F, b: 0x1.0p+0F, UINT32_C(0x3f800000)))
90 return 1;
91 // divisor is truncated to exactly 1.0 in UQ1.15
92 if (test__divsf3(a: 0x1.0p+0F, b: 0x1.0001p+0F, UINT32_C(0x3f7fff00)))
93 return 1;
94
95 // smallest normal value divided by 2.0
96 if (test__divsf3(a: 0x1.0p-126F, b: 2.0F, UINT32_C(0x00400000)))
97 return 1;
98 // smallest subnormal result
99 if (test__divsf3(a: 0x1.0p-126F, b: 0x1p+23F, UINT32_C(0x00000001)))
100 return 1;
101
102 // some misc test cases obtained by fuzzing against h/w implementation
103 if (test__divsf3(a: -0x1.3e75e6p-108F, b: -0x1.cf372p+38F, UINT32_C(0x00000006)))
104 return 1;
105 if (test__divsf3(a: 0x1.e77c54p+81F, b: -0x1.e77c52p-47F, UINT32_C(0xff800000)))
106 return 1;
107 if (test__divsf3(a: 0x1.fffffep-126F, b: 2.F, UINT32_C(0x00800000)))
108 return 1;
109
110 return 0;
111}
112

source code of compiler-rt/test/builtins/Unit/divsf3_test.c