1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: MIT (https://spdx.org/licenses/MIT) 4 * PURPOSE: Tests for fabs / fabsf 5 * COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org> 6 */ 7 8 /* Don't use the inline fabsf, unless required */ 9 #if !defined(_CRTBLD) && defined(_M_ARM) 10 #define _CRTBLD 11 #endif 12 #include "math_helpers.h" 13 14 #ifdef _MSC_VER 15 #pragma function(fabs) 16 // fabsf is not available as an intrinsic 17 #endif 18 19 static TESTENTRY_DBL s_fabs_tests[] = 20 { 21 /* Special values */ 22 { 0x7FF0000000000000ull /* INF */, 0x7FF0000000000000ull /* INF */ }, 23 #ifndef _M_IX86 24 { 0x7FF0000000000001ull /* NAN(SNAN) */, 0x7FF0000000000001ull /* NAN(SNAN) */ }, 25 { 0x7FF7FFFFFFFFFFFFull /* NAN(SNAN) */, 0x7FF7FFFFFFFFFFFFull /* NAN(SNAN) */ }, 26 #else 27 { 0x7FF0000000000001ull /* NAN(SNAN) */, 0x7FF8000000000001ull /* NAN */ }, 28 { 0x7FF7FFFFFFFFFFFFull /* NAN(SNAN) */, 0x7FFFFFFFFFFFFFFFull /* NAN */ }, 29 #endif 30 { 0x7FF8000000000000ull /* NAN */, 0x7FF8000000000000ull /* NAN */ }, 31 { 0x7FF8000000000001ull /* NAN */, 0x7FF8000000000001ull /* NAN */ }, 32 { 0x7FFFFFFFFFFFFFFFull /* NAN */, 0x7FFFFFFFFFFFFFFFull /* NAN */ }, 33 { 0xFFF0000000000000ull /* -INF */, 0x7FF0000000000000ull /* INF */ }, 34 #ifndef _M_IX86 35 { 0xFFF0000000000001ull /* -NAN(SNAN) */, 0xFFF0000000000001ull /* NAN(SNAN) */ }, 36 { 0xFFF7FFFFFFFFFFFFull /* -NAN(SNAN) */, 0xFFF7FFFFFFFFFFFFull /* NAN(SNAN) */ }, 37 #else 38 { 0xFFF0000000000001ull /* -NAN(SNAN) */, 0xFFF8000000000001ull /* -NAN */ }, 39 { 0xFFF7FFFFFFFFFFFFull /* -NAN(SNAN) */, 0xFFFFFFFFFFFFFFFFull /* -NAN */ }, 40 #endif 41 { 0xFFF8000000000000ull /* -NAN(IND) */, 0xFFF8000000000000ull /* -NAN(IND) */ }, 42 { 0xFFF8000000000001ull /* -NAN */, 0xFFF8000000000001ull /* -NAN */ }, 43 { 0xFFFFFFFFFFFFFFFFull /* -NAN */, 0xFFFFFFFFFFFFFFFFull /* -NAN */ }, 44 45 /* Some random floats */ 46 { 0x0000000000000000 /* 0.000000000000000e+000 */, 0x0000000000000000 /* 0.000000000000000e+000 */ }, 47 { 0x8000000000000000 /* -0.000000000000000e+000 */, 0x0000000000000000 /* 0.000000000000000e+000 */ }, 48 { 0x0123456789abcdef /* 3.512700564088504e-303 */, 0x0123456789abcdef /* 3.512700564088504e-303 */ }, 49 { 0x8123456789abcdef /* -3.512700564088504e-303 */, 0x0123456789abcdef /* 3.512700564088504e-303 */ }, 50 { 0x472ad8b31f506c9e /* 6.969745516432332e+034 */, 0x472ad8b31f506c9e /* 6.969745516432332e+034 */ }, 51 { 0xc72ad8b31f506c9e /* -6.969745516432332e+034 */, 0x472ad8b31f506c9e /* 6.969745516432332e+034 */ }, 52 { 0x1d289e506fa47cb3 /* 3.261613668384938e-168 */, 0x1d289e506fa47cb3 /* 3.261613668384938e-168 */ }, 53 { 0x9d289e506fa47cb3 /* -3.261613668384938e-168 */, 0x1d289e506fa47cb3 /* 3.261613668384938e-168 */ }, 54 }; 55 56 57 void Test_fabs(void) 58 { 59 int i; 60 61 for (i = 0; i < _countof(s_fabs_tests); i++) 62 { 63 double x = u64_to_dbl(s_fabs_tests[i].x); 64 double z = fabs(x); 65 ok_eq_dbl_exact("fabs", s_fabs_tests[i].x, z, s_fabs_tests[i].result); 66 } 67 } 68 69 static TESTENTRY_FLT s_fabsf_tests[] = 70 { 71 /* Special values */ 72 { 0x7F800000 /* INF */, 0x7F800000 /* INF */ }, 73 { 0x7F800001 /* NAN(SNAN) */, 0x7FC00001 /* NAN */ }, 74 { 0x7FBFFFFF /* NAN(SNAN) */, 0x7FFFFFFF /* NAN */ }, 75 { 0x7FC00000 /* NAN */, 0x7FC00000 /* NAN */ }, 76 { 0x7FC00001 /* NAN */, 0x7FC00001 /* NAN */ }, 77 { 0x7FCFFFFF /* NAN */, 0x7FCFFFFF /* NAN */ }, 78 { 0xFF800000 /* -INF */, 0x7F800000 /* INF */ }, 79 { 0xFF800001 /* -NAN(SNAN) */, 0xFFC00001 /* -NAN */ }, 80 { 0xFFBFFFFF /* -NAN(SNAN) */, 0xFFFFFFFF /* -NAN */ }, 81 { 0xFFC00000 /* -NAN(IND) */, 0xFFC00000 /* -NAN */ }, 82 { 0xFFC00001 /* -NAN */, 0xFFC00001 /* -NAN */ }, 83 { 0xFFCFFFFF /* -NAN */, 0xFFCFFFFF /* -NAN */ }, 84 85 /* Some random floats */ 86 { 0x00000000 /* 0.000000e+000 */, 0x00000000 /* 0.000000e+000 */ }, 87 { 0x80000000 /* -0.000000e+000 */, 0x00000000 /* 0.000000e+000 */ }, 88 { 0x01234567 /* 2.998817e-038 */, 0x01234567 /* 2.998817e-038 */ }, 89 { 0x81234567 /* -2.998817e-038 */, 0x01234567 /* 2.998817e-038 */ }, 90 { 0x472ad8b3 /* 4.373670e+004 */, 0x472ad8b3 /* 4.373670e+004 */ }, 91 { 0xc72ad8b3 /* -4.373670e+004 */, 0x472ad8b3 /* 4.373670e+004 */ }, 92 { 0x1d289e50 /* 2.231646e-021 */, 0x1d289e50 /* 2.231646e-021 */ }, 93 { 0x9d289e50 /* -2.231646e-021 */, 0x1d289e50 /* 2.231646e-021 */ }, 94 }; 95 96 void Test_fabsf(void) 97 { 98 int i; 99 100 for (i = 0; i < _countof(s_fabsf_tests); i++) 101 { 102 float x = u32_to_flt(s_fabsf_tests[i].x); 103 float z = fabsf(x); 104 ok_eq_flt_exact("fabsf", s_fabsf_tests[i].x, z, s_fabsf_tests[i].result); 105 } 106 } 107 108 START_TEST(fabs) 109 { 110 Test_fabs(); 111 Test_fabsf(); 112 } 113