1 #define MAIN_(x) A_CAST_2(x, _math)
5 #if defined(__MINGW32__) && A_PREREQ_GNUC(3, 0)
6 #pragma GCC diagnostic ignored "-Wfloat-conversion"
7 #endif /* __MINGW32__ */
8 #if A_PREREQ_GNUC(4, 6) || __has_warning("-Wdouble-promotion")
9 #pragma GCC diagnostic ignored "-Wdouble-promotion"
10 #endif /* -Wdouble-promotion */
12 static void test_u32_sqrt(void)
14 TEST_BUG(a_u32_sqrt(A_U32_C(~0)) == A_U16_C(0xFFFF));
15 TEST_BUG(a_u32_sqrt(A_U32_C(0x10000)) == A_U16_C(0x100));
16 TEST_BUG(a_u32_sqrt(A_U32_C(0xFFFFFFFF)) == A_U16_C(0xFFFF));
19 static void test_u64_sqrt(void)
21 TEST_BUG(a_u64_sqrt(A_U64_C(~0)) == A_U32_C(0xFFFFFFFF));
22 TEST_BUG(a_u64_sqrt(A_U64_C(0x100000000)) == A_U32_C(0x10000));
23 TEST_BUG(a_u64_sqrt(A_U64_C(0xFFFFFFFFFFFFFFFF)) == A_U32_C(0xFFFFFFFF));
26 static void test_f32_rsqrt(void)
34 A_F32_C(2.5) * A_F32_C(2.5),
36 for (unsigned int i
= 0; i
!= sizeof(data
) / sizeof(a_f32
); ++i
)
38 debug("1/sqrt(%g):\t%-10g%-10g\n", data
[i
], 1 / a_f32_sqrt(data
[i
]), a_f32_rsqrt(data
[i
]));
42 static void test_f64_rsqrt(void)
50 A_F64_C(2.5) * A_F64_C(2.5),
52 for (unsigned int i
= 0; i
!= sizeof(data
) / sizeof(a_f64
); ++i
)
54 debug("1/sqrt(%g):\t%-10g%-10g\n", data
[i
], 1 / a_f64_sqrt(data
[i
]), a_f64_rsqrt(data
[i
]));
58 int MAIN(int argc
, char *argv
[]) // NOLINT(misc-definitions-in-headers)
67 a_f64 min
= A_F64_MIN
;
68 a_f64 max
= A_F64_MAX
;
69 a_f64 inf
= A_F64_INF
;
70 a_f64 nan
= A_F64_NAN
;
71 debug("64 min = %-12g max = %g\n", min
, max
);
72 debug("64 inf = %-12g nan = %g\n", inf
, nan
);
75 a_f32 min
= A_F32_MIN
;
76 a_f32 max
= A_F32_MAX
;
77 a_f32 inf
= A_F32_INF
;
78 a_f32 nan
= A_F32_NAN
;
79 debug("32 min = %-12g max = %g\n", min
, max
);
80 debug("32 inf = %-12g nan = %g\n", inf
, nan
);
83 a_float min
= A_FLOAT_MIN
;
84 a_float max
= A_FLOAT_MAX
;
85 a_float inf
= A_FLOAT_INF
;
86 a_float nan
= A_FLOAT_NAN
;
87 debug("min = " A_FLOAT_PRI("-12", "g ") "max = " A_FLOAT_PRI("", "g\n"), min
, max
);
88 debug("inf = " A_FLOAT_PRI("-12", "g ") "nan = " A_FLOAT_PRI("", "g\n"), inf
, nan
);
92 a_float x
= A_FLOAT_EPSILON
/ 2;
93 TEST_BUG(isinf(a_float_expm1(A_FLOAT_INF
)));
94 TEST_BUG(isnan(a_float_expm1(A_FLOAT_NAN
)));
95 debug("expm1(" A_FLOAT_PRI(".15", "g") ")=" A_FLOAT_PRI(".15", "g\n"), x
, a_float_expm1(x
));
96 debug("exp(" A_FLOAT_PRI(".15", "g") ")-1=" A_FLOAT_PRI(".15", "g\n"), x
, a_float_exp(x
) - 1);
100 a_float x
= A_FLOAT_EPSILON
/ 2;
101 TEST_BUG(isinf(a_float_log1p(A_FLOAT_INF
)));
102 TEST_BUG(isnan(a_float_log1p(A_FLOAT_NAN
)));
103 debug("log1p(" A_FLOAT_PRI(".15", "g") ")=" A_FLOAT_PRI(".15", "g\n"), x
, a_float_log1p(x
));
104 debug("log(1+" A_FLOAT_PRI(".15", "g") ")=" A_FLOAT_PRI(".15", "g\n"), x
, a_float_log(x
+ 1));
108 a_float x
= A_FLOAT_MAX
/ A_FLOAT_SQRT2
;
109 a_float y
= A_FLOAT_MAX
/ A_FLOAT_SQRT2
;
110 TEST_BUG(!isinf(a_float_hypot(x
, y
)));
111 TEST_BUG(isinf(a_float_hypot(A_FLOAT_INF
, A_FLOAT_NAN
)));
112 TEST_BUG(isinf(a_float_hypot(A_FLOAT_NAN
, A_FLOAT_INF
)));
113 TEST_BUG(isnan(a_float_hypot(A_FLOAT_NAN
, A_FLOAT_NAN
)));
116 a_float x
= A_FLOAT_MAX
/ A_FLOAT_SQRT3
;
117 a_float y
= A_FLOAT_MAX
/ A_FLOAT_SQRT3
;
118 a_float z
= A_FLOAT_MAX
/ A_FLOAT_SQRT3
;
119 TEST_BUG(!isinf(a_float_hypot3(x
, y
, z
)));
120 TEST_BUG(isinf(a_float_hypot3(A_FLOAT_INF
, A_FLOAT_NAN
, A_FLOAT_NAN
)));
121 TEST_BUG(isinf(a_float_hypot3(A_FLOAT_NAN
, A_FLOAT_INF
, A_FLOAT_NAN
)));
122 TEST_BUG(isinf(a_float_hypot3(A_FLOAT_NAN
, A_FLOAT_NAN
, A_FLOAT_INF
)));
123 TEST_BUG(isnan(a_float_hypot3(A_FLOAT_NAN
, A_FLOAT_NAN
, A_FLOAT_NAN
)));