diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1683,6 +1683,7 @@ ) add_subdirectory(generic) +add_subdirectory(smoke) if(NOT LLVM_LIBC_FULL_BUILD) add_subdirectory(exhaustive) diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt copy from libc/test/src/math/CMakeLists.txt copy to libc/test/src/math/smoke/CMakeLists.txt --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -1,20 +1,11 @@ -add_custom_target(libc_math_unittests) - -add_library( - libc_math_test_utils - RandUtils.cpp - RandUtils.h -) +add_custom_target(libc-math-smoke-tests) add_fp_unittest( cosf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS cosf_test.cpp - HDRS - sdcomp26094.h DEPENDS libc.src.errno.errno libc.src.math.cosf @@ -22,27 +13,12 @@ libc.src.__support.FPUtil.fp_bits ) -add_fp_unittest( - cos_test - NEED_MPFR - SUITE - libc_math_unittests - SRCS - cos_test.cpp - DEPENDS - libc.src.math.cos - libc.src.__support.FPUtil.fp_bits -) - add_fp_unittest( sinf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS sinf_test.cpp - HDRS - sdcomp26094.h DEPENDS libc.src.errno.errno libc.src.math.sinf @@ -50,27 +26,12 @@ libc.src.__support.FPUtil.fp_bits ) -add_fp_unittest( - sin_test - NEED_MPFR - SUITE - libc_math_unittests - SRCS - sin_test.cpp - DEPENDS - libc.src.math.sin - libc.src.__support.FPUtil.fp_bits -) - add_fp_unittest( sincosf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS sincosf_test.cpp - HDRS - sdcomp26094.h DEPENDS libc.src.errno.errno libc.src.math.sincosf @@ -80,13 +41,10 @@ add_fp_unittest( tanf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS tanf_test.cpp - HDRS - sdcomp26094.h DEPENDS libc.src.errno.errno libc.src.math.tanf @@ -96,9 +54,8 @@ add_fp_unittest( fabs_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fabs_test.cpp HDRS @@ -111,9 +68,8 @@ add_fp_unittest( fabsf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fabsf_test.cpp HDRS @@ -126,9 +82,8 @@ add_fp_unittest( fabsl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fabsl_test.cpp HDRS @@ -141,9 +96,8 @@ add_fp_unittest( trunc_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS trunc_test.cpp HDRS @@ -156,9 +110,8 @@ add_fp_unittest( truncf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS truncf_test.cpp HDRS @@ -171,9 +124,8 @@ add_fp_unittest( truncl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS truncl_test.cpp HDRS @@ -186,9 +138,8 @@ add_fp_unittest( ceil_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ceil_test.cpp HDRS @@ -201,9 +152,8 @@ add_fp_unittest( ceilf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ceilf_test.cpp HDRS @@ -216,9 +166,8 @@ add_fp_unittest( ceill_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ceill_test.cpp HDRS @@ -231,9 +180,8 @@ add_fp_unittest( floor_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS floor_test.cpp HDRS @@ -246,9 +194,8 @@ add_fp_unittest( floorf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS floorf_test.cpp HDRS @@ -261,9 +208,8 @@ add_fp_unittest( floorl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS floorl_test.cpp HDRS @@ -276,9 +222,8 @@ add_fp_unittest( round_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS round_test.cpp HDRS @@ -291,9 +236,8 @@ add_fp_unittest( roundf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS roundf_test.cpp HDRS @@ -306,9 +250,8 @@ add_fp_unittest( roundl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS roundl_test.cpp HDRS @@ -321,9 +264,8 @@ add_fp_unittest( lround_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS lround_test.cpp HDRS @@ -340,9 +282,8 @@ add_fp_unittest( lroundf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS lroundf_test.cpp HDRS @@ -359,9 +300,8 @@ add_fp_unittest( lroundl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS lroundl_test.cpp HDRS @@ -378,9 +318,8 @@ add_fp_unittest( llround_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS llround_test.cpp HDRS @@ -397,9 +336,8 @@ add_fp_unittest( llroundf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS llroundf_test.cpp HDRS @@ -416,9 +354,8 @@ add_fp_unittest( llroundl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS llroundl_test.cpp HDRS @@ -435,9 +372,8 @@ add_fp_unittest( rint_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS rint_test.cpp HDRS @@ -451,9 +387,8 @@ add_fp_unittest( rintf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS rintf_test.cpp HDRS @@ -467,9 +402,8 @@ add_fp_unittest( rintl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS rintl_test.cpp HDRS @@ -483,9 +417,8 @@ add_fp_unittest( lrint_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS lrint_test.cpp HDRS @@ -499,9 +432,8 @@ add_fp_unittest( lrintf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS lrintf_test.cpp HDRS @@ -515,9 +447,8 @@ add_fp_unittest( lrintl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS lrintl_test.cpp HDRS @@ -531,9 +462,8 @@ add_fp_unittest( llrint_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS llrint_test.cpp HDRS @@ -547,9 +477,8 @@ add_fp_unittest( llrintf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS llrintf_test.cpp HDRS @@ -563,9 +492,8 @@ add_fp_unittest( llrintl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS llrintl_test.cpp HDRS @@ -579,9 +507,8 @@ add_fp_unittest( expf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS expf_test.cpp DEPENDS @@ -593,9 +520,8 @@ add_fp_unittest( exp_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS exp_test.cpp DEPENDS @@ -607,9 +533,8 @@ add_fp_unittest( exp2f_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS exp2f_test.cpp DEPENDS @@ -621,9 +546,8 @@ add_fp_unittest( exp2_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS exp2_test.cpp DEPENDS @@ -635,9 +559,8 @@ add_fp_unittest( exp10f_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS exp10f_test.cpp DEPENDS @@ -649,9 +572,8 @@ add_fp_unittest( exp10_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS exp10_test.cpp DEPENDS @@ -664,7 +586,7 @@ add_fp_unittest( copysign_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS copysign_test.cpp HDRS @@ -678,7 +600,7 @@ add_fp_unittest( copysignf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS copysignf_test.cpp HDRS @@ -692,7 +614,7 @@ add_fp_unittest( copysignl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS copysignl_test.cpp HDRS @@ -705,9 +627,8 @@ add_fp_unittest( frexp_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS frexp_test.cpp HDRS @@ -720,9 +641,8 @@ add_fp_unittest( frexpf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS frexpf_test.cpp HDRS @@ -735,9 +655,8 @@ add_fp_unittest( frexpl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS frexpl_test.cpp HDRS @@ -753,7 +672,7 @@ add_fp_unittest( ilogb_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ilogb_test.cpp HDRS @@ -768,7 +687,7 @@ add_fp_unittest( ilogbf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ilogbf_test.cpp HDRS @@ -784,7 +703,7 @@ add_fp_unittest( ilogbl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ilogbl_test.cpp HDRS @@ -799,7 +718,7 @@ add_fp_unittest( ldexp_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ldexp_test.cpp HDRS @@ -814,7 +733,7 @@ add_fp_unittest( ldexpf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ldexpf_test.cpp HDRS @@ -829,7 +748,7 @@ add_fp_unittest( ldexpl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS ldexpl_test.cpp HDRS @@ -844,7 +763,7 @@ add_fp_unittest( logb_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS logb_test.cpp DEPENDS @@ -856,7 +775,7 @@ add_fp_unittest( logbf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS logbf_test.cpp DEPENDS @@ -868,7 +787,7 @@ add_fp_unittest( logbl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS logbl_test.cpp HDRS @@ -882,7 +801,7 @@ add_fp_unittest( modf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS modf_test.cpp HDRS @@ -899,7 +818,7 @@ add_fp_unittest( modff_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS modff_test.cpp HDRS @@ -916,7 +835,7 @@ add_fp_unittest( modfl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS modfl_test.cpp HDRS @@ -931,7 +850,7 @@ add_fp_unittest( fdimf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fdimf_test.cpp HDRS @@ -946,7 +865,7 @@ add_fp_unittest( fdim_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fdim_test.cpp HDRS @@ -961,7 +880,7 @@ add_fp_unittest( fdiml_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fdiml_test.cpp HDRS @@ -978,7 +897,7 @@ add_fp_unittest( fminf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fminf_test.cpp HDRS @@ -992,7 +911,7 @@ add_fp_unittest( fmin_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fmin_test.cpp HDRS @@ -1006,7 +925,7 @@ add_fp_unittest( fminl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fminl_test.cpp HDRS @@ -1020,7 +939,7 @@ add_fp_unittest( fmaxf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fmaxf_test.cpp HDRS @@ -1034,7 +953,7 @@ add_fp_unittest( fmax_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fmax_test.cpp HDRS @@ -1048,7 +967,7 @@ add_fp_unittest( fmaxl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fmaxl_test.cpp HDRS @@ -1062,9 +981,8 @@ add_fp_unittest( sqrtf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS sqrtf_test.cpp DEPENDS @@ -1075,9 +993,8 @@ add_fp_unittest( sqrt_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS sqrt_test.cpp DEPENDS @@ -1088,9 +1005,8 @@ add_fp_unittest( sqrtl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS sqrtl_test.cpp DEPENDS @@ -1101,9 +1017,8 @@ add_fp_unittest( generic_sqrtf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS generic_sqrtf_test.cpp DEPENDS @@ -1116,9 +1031,8 @@ add_fp_unittest( generic_sqrt_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS generic_sqrt_test.cpp DEPENDS @@ -1131,9 +1045,8 @@ add_fp_unittest( generic_sqrtl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS generic_sqrtl_test.cpp DEPENDS @@ -1146,9 +1059,8 @@ add_fp_unittest( remquof_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS remquof_test.cpp HDRS @@ -1162,9 +1074,8 @@ add_fp_unittest( remquo_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS remquo_test.cpp HDRS @@ -1178,9 +1089,8 @@ add_fp_unittest( remquol_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS remquol_test.cpp HDRS @@ -1194,9 +1104,8 @@ add_fp_unittest( hypotf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS hypotf_test.cpp DEPENDS @@ -1207,9 +1116,8 @@ add_fp_unittest( hypot_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS hypot_test.cpp DEPENDS @@ -1223,7 +1131,7 @@ add_fp_unittest( nextafter_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS nextafter_test.cpp HDRS @@ -1238,7 +1146,7 @@ add_fp_unittest( nextafterf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS nextafterf_test.cpp HDRS @@ -1254,7 +1162,7 @@ add_fp_unittest( nextafterl_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS nextafterl_test.cpp HDRS @@ -1270,9 +1178,8 @@ # correctly rounded for the default rounding mode round-to-nearest tie-to-even. add_fp_unittest( fmaf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fmaf_test.cpp DEPENDS @@ -1285,9 +1192,8 @@ add_fp_unittest( fma_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fma_test.cpp DEPENDS @@ -1297,50 +1203,35 @@ ) add_fp_unittest( - tan_test - NEED_MPFR + expm1f_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS - tan_test.cpp + expm1f_test.cpp DEPENDS - libc.src.math.tan + libc.src.errno.errno + libc.include.math + libc.src.math.expm1f libc.src.__support.FPUtil.fp_bits ) add_fp_unittest( - expm1f_test - NEED_MPFR + log_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS - expm1f_test.cpp + log_test.cpp DEPENDS libc.src.errno.errno libc.include.math - libc.src.math.expm1f + libc.src.math.log libc.src.__support.FPUtil.fp_bits ) -add_fp_unittest( - log_test - NEED_MPFR - SUITE - libc_math_unittests - SRCS - log_test.cpp - DEPENDS - libc.src.errno.errno - libc.include.math - libc.src.math.log - libc.src.__support.FPUtil.fp_bits -) - add_fp_unittest( logf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS logf_test.cpp DEPENDS @@ -1351,24 +1242,22 @@ ) add_fp_unittest( -log2_test - NEED_MPFR - SUITE - libc_math_unittests - SRCS - log2_test.cpp - DEPENDS - libc.src.errno.errno - libc.include.math - libc.src.math.log2 - libc.src.__support.FPUtil.fp_bits + log2_test + SUITE + libc-math-smoke-tests + SRCS + log2_test.cpp + DEPENDS + libc.src.errno.errno + libc.include.math + libc.src.math.log2 + libc.src.__support.FPUtil.fp_bits ) add_fp_unittest( log2f_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS log2f_test.cpp DEPENDS @@ -1379,24 +1268,22 @@ ) add_fp_unittest( - log10_test - NEED_MPFR - SUITE - libc_math_unittests - SRCS - log10_test.cpp - DEPENDS - libc.src.errno.errno - libc.include.math - libc.src.math.log10 - libc.src.__support.FPUtil.fp_bits + log10_test + SUITE + libc-math-smoke-tests + SRCS + log10_test.cpp + DEPENDS + libc.src.errno.errno + libc.include.math + libc.src.math.log10 + libc.src.__support.FPUtil.fp_bits ) add_fp_unittest( log10f_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS log10f_test.cpp DEPENDS @@ -1407,24 +1294,22 @@ ) add_fp_unittest( -log1p_test - NEED_MPFR - SUITE - libc_math_unittests - SRCS - log1p_test.cpp - DEPENDS - libc.src.errno.errno - libc.include.math - libc.src.math.log1p - libc.src.__support.FPUtil.fp_bits + log1p_test + SUITE + libc-math-smoke-tests + SRCS + log1p_test.cpp + DEPENDS + libc.src.errno.errno + libc.include.math + libc.src.math.log1p + libc.src.__support.FPUtil.fp_bits ) add_fp_unittest( log1pf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS log1pf_test.cpp DEPENDS @@ -1437,7 +1322,7 @@ add_fp_unittest( fmodf_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fmodf_test.cpp HDRS @@ -1455,7 +1340,7 @@ add_fp_unittest( fmod_test SUITE - libc_math_unittests + libc-math-smoke-tests SRCS fmod_test.cpp HDRS @@ -1470,30 +1355,12 @@ UNIT_TEST_ONLY ) -add_fp_unittest( - explogxf_test - NEED_MPFR - SUITE - libc_math_unittests - HDRS - in_float_range_test_helper.h - SRCS - explogxf_test.cpp - DEPENDS - libc.include.math - libc.src.math.generic.explogxf - libc.src.__support.FPUtil.fp_bits -) - add_fp_unittest( coshf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS coshf_test.cpp - HDRS - sdcomp26094.h DEPENDS libc.src.errno.errno libc.src.math.coshf @@ -1503,13 +1370,10 @@ add_fp_unittest( sinhf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS sinhf_test.cpp - HDRS - sdcomp26094.h DEPENDS libc.src.errno.errno libc.src.math.sinhf @@ -1519,9 +1383,8 @@ add_fp_unittest( tanhf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS tanhf_test.cpp DEPENDS @@ -1531,9 +1394,8 @@ add_fp_unittest( atanhf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS atanhf_test.cpp DEPENDS @@ -1544,9 +1406,8 @@ add_fp_unittest( asinhf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS asinhf_test.cpp DEPENDS @@ -1557,9 +1418,8 @@ add_fp_unittest( acoshf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS acoshf_test.cpp DEPENDS @@ -1570,9 +1430,8 @@ add_fp_unittest( asinf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS asinf_test.cpp DEPENDS @@ -1583,9 +1442,8 @@ add_fp_unittest( acosf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS acosf_test.cpp DEPENDS @@ -1596,9 +1454,8 @@ add_fp_unittest( atanf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS atanf_test.cpp DEPENDS @@ -1607,25 +1464,10 @@ libc.src.__support.FPUtil.fp_bits ) -add_fp_unittest( - inv_trigf_utils_test - NEED_MPFR - SUITE - libc_math_unittests - HDRS - in_float_range_test_helper.h - SRCS - inv_trigf_utils_test.cpp - DEPENDS - libc.src.math.generic.inv_trigf_utils - libc.src.__support.FPUtil.fp_bits -) - add_fp_unittest( scalbn_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS scalbn_test.cpp HDRS @@ -1639,9 +1481,8 @@ add_fp_unittest( scalbnf_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS scalbnf_test.cpp HDRS @@ -1655,9 +1496,8 @@ add_fp_unittest( scalbnl_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS scalbnl_test.cpp HDRS @@ -1671,9 +1511,8 @@ add_fp_unittest( erff_test - NEED_MPFR SUITE - libc_math_unittests + libc-math-smoke-tests SRCS erff_test.cpp DEPENDS @@ -1681,10 +1520,3 @@ libc.src.math.erff libc.src.__support.FPUtil.fp_bits ) - -add_subdirectory(generic) - -if(NOT LLVM_LIBC_FULL_BUILD) - add_subdirectory(exhaustive) - add_subdirectory(differential_testing) -endif() diff --git a/libc/test/src/math/smoke/CeilTest.h b/libc/test/src/math/smoke/CeilTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/CeilTest.h @@ -0,0 +1,68 @@ +//===-- Utility class to test ceil[f|l] -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class CeilTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*CeilFunc)(T); + + void testSpecialNumbers(CeilFunc func) { + EXPECT_FP_EQ(zero, func(zero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); + + EXPECT_FP_EQ(inf, func(inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); + + EXPECT_FP_EQ(aNaN, func(aNaN)); + } + + void testRoundedNumbers(CeilFunc func) { + EXPECT_FP_EQ(T(1.0), func(T(1.0))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.0))); + EXPECT_FP_EQ(T(10.0), func(T(10.0))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.0))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.0))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0))); + } + + void testFractions(CeilFunc func) { + EXPECT_FP_EQ(T(1.0), func(T(0.5))); + EXPECT_FP_EQ(T(-0.0), func(T(-0.5))); + EXPECT_FP_EQ(T(1.0), func(T(0.115))); + EXPECT_FP_EQ(T(-0.0), func(T(-0.115))); + EXPECT_FP_EQ(T(1.0), func(T(0.715))); + EXPECT_FP_EQ(T(-0.0), func(T(-0.715))); + EXPECT_FP_EQ(T(2.0), func(T(1.3))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.3))); + EXPECT_FP_EQ(T(2.0), func(T(1.5))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.5))); + EXPECT_FP_EQ(T(2.0), func(T(1.75))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.75))); + EXPECT_FP_EQ(T(11.0), func(T(10.32))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); + EXPECT_FP_EQ(T(11.0), func(T(10.65))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.65))); + EXPECT_FP_EQ(T(1235.0), func(T(1234.38))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); + EXPECT_FP_EQ(T(1235.0), func(T(1234.96))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96))); + } +}; + +#define LIST_CEIL_TESTS(T, func) \ + using LlvmLibcCeilTest = CeilTest; \ + TEST_F(LlvmLibcCeilTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcCeilTest, RoundedNubmers) { testRoundedNumbers(&func); } \ + TEST_F(LlvmLibcCeilTest, Fractions) { testFractions(&func); } diff --git a/libc/test/src/math/smoke/CopySignTest.h b/libc/test/src/math/smoke/CopySignTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/CopySignTest.h @@ -0,0 +1,52 @@ +//===-- Utility class to test copysign[f|l] ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class CopySignTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*CopySignFunc)(T, T); + + void testSpecialNumbers(CopySignFunc func) { + EXPECT_FP_EQ(aNaN, func(aNaN, -1.0)); + EXPECT_FP_EQ(aNaN, func(aNaN, 1.0)); + + EXPECT_FP_EQ(neg_inf, func(inf, -1.0)); + EXPECT_FP_EQ(inf, func(neg_inf, 1.0)); + + EXPECT_FP_EQ(neg_zero, func(zero, -1.0)); + EXPECT_FP_EQ(zero, func(neg_zero, 1.0)); + } + + void testRange(CopySignFunc func) { + constexpr UIntType COUNT = 100'000; + constexpr UIntType STEP = UIntType(-1) / COUNT; + for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) { + T x = T(FPBits(v)); + if (isnan(x) || isinf(x)) + continue; + + double res1 = func(x, -x); + ASSERT_FP_EQ(res1, -x); + + double res2 = func(x, x); + ASSERT_FP_EQ(res2, x); + } + } +}; + +#define LIST_COPYSIGN_TESTS(T, func) \ + using LlvmLibcCopySignTest = CopySignTest; \ + TEST_F(LlvmLibcCopySignTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcCopySignTest, Range) { testRange(&func); } diff --git a/libc/test/src/math/smoke/FAbsTest.h b/libc/test/src/math/smoke/FAbsTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FAbsTest.h @@ -0,0 +1,37 @@ +//===-- Utility class to test fabs[f|l] -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class FAbsTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*FabsFunc)(T); + + void testSpecialNumbers(FabsFunc func) { + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN)); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf)); + EXPECT_FP_EQ_ALL_ROUNDING(inf, func(neg_inf)); + + EXPECT_FP_EQ_ALL_ROUNDING(zero, func(zero)); + EXPECT_FP_EQ_ALL_ROUNDING(zero, func(neg_zero)); + + EXPECT_FP_EQ_ALL_ROUNDING(T(1), func(T(1))); + EXPECT_FP_EQ_ALL_ROUNDING(T(1), func(T(-1))); + } +}; + +#define LIST_FABS_TESTS(T, func) \ + using LlvmLibcFAbsTest = FAbsTest; \ + TEST_F(LlvmLibcFAbsTest, SpecialNumbers) { testSpecialNumbers(&func); } diff --git a/libc/test/src/math/smoke/FDimTest.h b/libc/test/src/math/smoke/FDimTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FDimTest.h @@ -0,0 +1,82 @@ +//===-- Utility class to test different flavors of fdim ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +template +class FDimTestTemplate : public __llvm_libc::testing::Test { +public: + using FuncPtr = T (*)(T, T); + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + + void test_na_n_arg(FuncPtr func) { + EXPECT_FP_EQ(nan, func(nan, inf)); + EXPECT_FP_EQ(nan, func(neg_inf, nan)); + EXPECT_FP_EQ(nan, func(nan, zero)); + EXPECT_FP_EQ(nan, func(neg_zero, nan)); + EXPECT_FP_EQ(nan, func(nan, T(-1.2345))); + EXPECT_FP_EQ(nan, func(T(1.2345), nan)); + EXPECT_FP_EQ(func(nan, nan), nan); + } + + void test_inf_arg(FuncPtr func) { + EXPECT_FP_EQ(zero, func(neg_inf, inf)); + EXPECT_FP_EQ(inf, func(inf, zero)); + EXPECT_FP_EQ(zero, func(neg_zero, inf)); + EXPECT_FP_EQ(inf, func(inf, T(1.2345))); + EXPECT_FP_EQ(zero, func(T(-1.2345), inf)); + } + + void test_neg_inf_arg(FuncPtr func) { + EXPECT_FP_EQ(inf, func(inf, neg_inf)); + EXPECT_FP_EQ(zero, func(neg_inf, zero)); + EXPECT_FP_EQ(inf, func(neg_zero, neg_inf)); + EXPECT_FP_EQ(zero, func(neg_inf, T(-1.2345))); + EXPECT_FP_EQ(inf, func(T(1.2345), neg_inf)); + } + + void test_both_zero(FuncPtr func) { + EXPECT_FP_EQ(zero, func(zero, zero)); + EXPECT_FP_EQ(zero, func(zero, neg_zero)); + EXPECT_FP_EQ(zero, func(neg_zero, zero)); + EXPECT_FP_EQ(zero, func(neg_zero, neg_zero)); + } + + void test_in_range(FuncPtr func) { + constexpr UIntType COUNT = 100'001; + constexpr UIntType STEP = UIntType(-1) / COUNT; + for (UIntType i = 0, v = 0, w = UIntType(-1); i <= COUNT; + ++i, v += STEP, w -= STEP) { + T x = T(FPBits(v)), y = T(FPBits(w)); + if (isnan(x) || isinf(x)) + continue; + if (isnan(y) || isinf(y)) + continue; + + if (x > y) { + EXPECT_FP_EQ(x - y, func(x, y)); + } else { + EXPECT_FP_EQ(zero, func(x, y)); + } + } + } + +private: + // constexpr does not work on FPBits yet, so we cannot have these constants as + // static. + const T nan = T(__llvm_libc::fputil::FPBits::build_quiet_nan(1)); + const T inf = T(__llvm_libc::fputil::FPBits::inf()); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); + const T zero = T(__llvm_libc::fputil::FPBits::zero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); +}; diff --git a/libc/test/src/math/smoke/FMaxTest.h b/libc/test/src/math/smoke/FMaxTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FMaxTest.h @@ -0,0 +1,82 @@ +//===-- Utility class to test fmin[f|l] -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class FMaxTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*FMaxFunc)(T, T); + + void testNaN(FMaxFunc func) { + EXPECT_FP_EQ(inf, func(aNaN, inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN)); + EXPECT_FP_EQ(0.0, func(aNaN, 0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, aNaN)); + EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345))); + EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN)); + EXPECT_FP_EQ(aNaN, func(aNaN, aNaN)); + } + + void testInfArg(FMaxFunc func) { + EXPECT_FP_EQ(inf, func(neg_inf, inf)); + EXPECT_FP_EQ(inf, func(inf, 0.0)); + EXPECT_FP_EQ(inf, func(-0.0, inf)); + EXPECT_FP_EQ(inf, func(inf, T(1.2345))); + EXPECT_FP_EQ(inf, func(T(-1.2345), inf)); + } + + void testNegInfArg(FMaxFunc func) { + EXPECT_FP_EQ(inf, func(inf, neg_inf)); + EXPECT_FP_EQ(0.0, func(neg_inf, 0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, neg_inf)); + EXPECT_FP_EQ(T(-1.2345), func(neg_inf, T(-1.2345))); + EXPECT_FP_EQ(T(1.2345), func(T(1.2345), neg_inf)); + } + + void testBothZero(FMaxFunc func) { + EXPECT_FP_EQ(0.0, func(0.0, 0.0)); + EXPECT_FP_EQ(0.0, func(-0.0, 0.0)); + EXPECT_FP_EQ(0.0, func(0.0, -0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, -0.0)); + } + + void testRange(FMaxFunc func) { + constexpr UIntType COUNT = 100'001; + constexpr UIntType STEP = UIntType(-1) / COUNT; + for (UIntType i = 0, v = 0, w = UIntType(-1); i <= COUNT; + ++i, v += STEP, w -= STEP) { + T x = T(FPBits(v)), y = T(FPBits(w)); + if (isnan(x) || isinf(x)) + continue; + if (isnan(y) || isinf(y)) + continue; + if ((x == 0) && (y == 0)) + continue; + + if (x > y) { + EXPECT_FP_EQ(x, func(x, y)); + } else { + EXPECT_FP_EQ(y, func(x, y)); + } + } + } +}; + +#define LIST_FMAX_TESTS(T, func) \ + using LlvmLibcFMaxTest = FMaxTest; \ + TEST_F(LlvmLibcFMaxTest, NaN) { testNaN(&func); } \ + TEST_F(LlvmLibcFMaxTest, InfArg) { testInfArg(&func); } \ + TEST_F(LlvmLibcFMaxTest, NegInfArg) { testNegInfArg(&func); } \ + TEST_F(LlvmLibcFMaxTest, BothZero) { testBothZero(&func); } \ + TEST_F(LlvmLibcFMaxTest, Range) { testRange(&func); } diff --git a/libc/test/src/math/smoke/FMinTest.h b/libc/test/src/math/smoke/FMinTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FMinTest.h @@ -0,0 +1,82 @@ +//===-- Utility class to test fmin[f|l] -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class FMinTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*FMinFunc)(T, T); + + void testNaN(FMinFunc func) { + EXPECT_FP_EQ(inf, func(aNaN, inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN)); + EXPECT_FP_EQ(0.0, func(aNaN, 0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, aNaN)); + EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345))); + EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN)); + EXPECT_FP_EQ(aNaN, func(aNaN, aNaN)); + } + + void testInfArg(FMinFunc func) { + EXPECT_FP_EQ(neg_inf, func(neg_inf, inf)); + EXPECT_FP_EQ(0.0, func(inf, 0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, inf)); + EXPECT_FP_EQ(T(1.2345), func(inf, T(1.2345))); + EXPECT_FP_EQ(T(-1.2345), func(T(-1.2345), inf)); + } + + void testNegInfArg(FMinFunc func) { + EXPECT_FP_EQ(neg_inf, func(inf, neg_inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, 0.0)); + EXPECT_FP_EQ(neg_inf, func(-0.0, neg_inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, T(-1.2345))); + EXPECT_FP_EQ(neg_inf, func(T(1.2345), neg_inf)); + } + + void testBothZero(FMinFunc func) { + EXPECT_FP_EQ(0.0, func(0.0, 0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, 0.0)); + EXPECT_FP_EQ(-0.0, func(0.0, -0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, -0.0)); + } + + void testRange(FMinFunc func) { + constexpr UIntType COUNT = 100'001; + constexpr UIntType STEP = UIntType(-1) / COUNT; + for (UIntType i = 0, v = 0, w = UIntType(-1); i <= COUNT; + ++i, v += STEP, w -= STEP) { + T x = T(FPBits(v)), y = T(FPBits(w)); + if (isnan(x) || isinf(x)) + continue; + if (isnan(y) || isinf(y)) + continue; + if ((x == 0) && (y == 0)) + continue; + + if (x > y) { + EXPECT_FP_EQ(y, func(x, y)); + } else { + EXPECT_FP_EQ(x, func(x, y)); + } + } + } +}; + +#define LIST_FMIN_TESTS(T, func) \ + using LlvmLibcFMinTest = FMinTest; \ + TEST_F(LlvmLibcFMinTest, NaN) { testNaN(&func); } \ + TEST_F(LlvmLibcFMinTest, InfArg) { testInfArg(&func); } \ + TEST_F(LlvmLibcFMinTest, NegInfArg) { testNegInfArg(&func); } \ + TEST_F(LlvmLibcFMinTest, BothZero) { testBothZero(&func); } \ + TEST_F(LlvmLibcFMinTest, Range) { testRange(&func); } diff --git a/libc/test/src/math/smoke/FModTest.h b/libc/test/src/math/smoke/FModTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FModTest.h @@ -0,0 +1,270 @@ +//===-- Utility class to test fmod special numbers ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include +#include + +#define TEST_SPECIAL(x, y, expected, dom_err, expected_exception) \ + EXPECT_FP_EQ(expected, f(x, y)); \ + EXPECT_MATH_ERRNO((dom_err) ? EDOM : 0); \ + EXPECT_FP_EXCEPTION(expected_exception); \ + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT) + +#define TEST_REGULAR(x, y, expected) TEST_SPECIAL(x, y, expected, false, 0) + +template class FmodTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*FModFunc)(T, T); + + void testSpecialNumbers(FModFunc f) { + using nl = std::numeric_limits; + + // fmod (+0, y) == +0 for y != 0. + TEST_SPECIAL(0.0, 3.0, 0.0, false, 0); + TEST_SPECIAL(0.0, nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(0.0, -nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(0.0, nl::min(), 0.0, false, 0); + TEST_SPECIAL(0.0, -nl::min(), 0.0, false, 0); + TEST_SPECIAL(0.0, nl::max(), 0.0, false, 0); + TEST_SPECIAL(0.0, -nl::max(), 0.0, false, 0); + + // fmod (-0, y) == -0 for y != 0. + TEST_SPECIAL(neg_zero, 3.0, neg_zero, false, 0); + TEST_SPECIAL(neg_zero, nl::denorm_min(), neg_zero, false, 0); + TEST_SPECIAL(neg_zero, -nl::denorm_min(), neg_zero, false, 0); + TEST_SPECIAL(neg_zero, nl::min(), neg_zero, false, 0); + TEST_SPECIAL(neg_zero, -nl::min(), neg_zero, false, 0); + TEST_SPECIAL(neg_zero, nl::max(), neg_zero, false, 0); + TEST_SPECIAL(neg_zero, -nl::max(), neg_zero, false, 0); + + // fmod (+inf, y) == nl::quiet_NaN() plus invalid exception. + TEST_SPECIAL(inf, 3.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, -1.1L, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, nl::denorm_min(), nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, nl::min(), nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, nl::max(), nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, inf, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(inf, neg_inf, nl::quiet_NaN(), true, FE_INVALID); + + // fmod (-inf, y) == nl::quiet_NaN() plus invalid exception. + TEST_SPECIAL(neg_inf, 3.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, -1.1L, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, nl::denorm_min(), nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, nl::min(), nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, nl::max(), nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, inf, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_inf, neg_inf, nl::quiet_NaN(), true, FE_INVALID); + + // fmod (x, +0) == nl::quiet_NaN() plus invalid exception. + TEST_SPECIAL(3.0, 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(-1.1L, 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(0.0, 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_zero, 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(nl::denorm_min(), 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(nl::min(), 0.0, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(nl::max(), 0.0, nl::quiet_NaN(), true, FE_INVALID); + + // fmod (x, -0) == nl::quiet_NaN() plus invalid exception. + TEST_SPECIAL(3.0, neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(-1.1L, neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(0.0, neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(neg_zero, neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(nl::denorm_min(), neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(nl::min(), neg_zero, nl::quiet_NaN(), true, FE_INVALID); + TEST_SPECIAL(nl::max(), neg_zero, nl::quiet_NaN(), true, FE_INVALID); + + // fmod (x, +inf) == x for x not infinite. + TEST_SPECIAL(0.0, inf, 0.0, false, 0); + TEST_SPECIAL(neg_zero, inf, neg_zero, false, 0); + TEST_SPECIAL(nl::denorm_min(), inf, nl::denorm_min(), false, 0); + TEST_SPECIAL(nl::min(), inf, nl::min(), false, 0); + TEST_SPECIAL(nl::max(), inf, nl::max(), false, 0); + TEST_SPECIAL(3.0, inf, 3.0, false, 0); + // fmod (x, -inf) == x for x not infinite. + TEST_SPECIAL(0.0, neg_inf, 0.0, false, 0); + TEST_SPECIAL(neg_zero, neg_inf, neg_zero, false, 0); + TEST_SPECIAL(nl::denorm_min(), neg_inf, nl::denorm_min(), false, 0); + TEST_SPECIAL(nl::min(), neg_inf, nl::min(), false, 0); + TEST_SPECIAL(nl::max(), neg_inf, nl::max(), false, 0); + TEST_SPECIAL(3.0, neg_inf, 3.0, false, 0); + + TEST_SPECIAL(0.0, nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(0.0, -nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(neg_zero, nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(neg_zero, -nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(1.0, nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(1.0, -nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(inf, nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(inf, -nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(neg_inf, nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(neg_inf, -nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(0.0, nl::signaling_NaN(), nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(0.0, -nl::signaling_NaN(), nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(neg_zero, nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(neg_zero, -nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(1.0, nl::signaling_NaN(), nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(1.0, -nl::signaling_NaN(), nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(inf, nl::signaling_NaN(), nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(inf, -nl::signaling_NaN(), nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(neg_inf, nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(neg_inf, -nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(nl::quiet_NaN(), 0.0, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(-nl::quiet_NaN(), 0.0, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(nl::quiet_NaN(), neg_zero, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(-nl::quiet_NaN(), neg_zero, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(nl::quiet_NaN(), 1.0, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(-nl::quiet_NaN(), 1.0, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(nl::quiet_NaN(), inf, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(-nl::quiet_NaN(), inf, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(nl::quiet_NaN(), neg_inf, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(-nl::quiet_NaN(), neg_inf, nl::quiet_NaN(), false, 0); + TEST_SPECIAL(nl::signaling_NaN(), 0.0, nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), 0.0, nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), neg_zero, nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), neg_zero, nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), 1.0, nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), 1.0, nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), inf, nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), inf, nl::quiet_NaN(), false, FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), neg_inf, nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), neg_inf, nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(nl::quiet_NaN(), nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(nl::quiet_NaN(), -nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(-nl::quiet_NaN(), nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(-nl::quiet_NaN(), -nl::quiet_NaN(), nl::quiet_NaN(), false, 0); + TEST_SPECIAL(nl::quiet_NaN(), nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(nl::quiet_NaN(), -nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(-nl::quiet_NaN(), nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(-nl::quiet_NaN(), -nl::signaling_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), nl::quiet_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), -nl::quiet_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), nl::quiet_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), -nl::quiet_NaN(), nl::quiet_NaN(), false, + FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), nl::signaling_NaN(), nl::quiet_NaN(), + false, FE_INVALID); + TEST_SPECIAL(nl::signaling_NaN(), -nl::signaling_NaN(), nl::quiet_NaN(), + false, FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), nl::signaling_NaN(), nl::quiet_NaN(), + false, FE_INVALID); + TEST_SPECIAL(-nl::signaling_NaN(), -nl::signaling_NaN(), nl::quiet_NaN(), + false, FE_INVALID); + + TEST_SPECIAL(6.5, 2.25L, 2.0L, false, 0); + TEST_SPECIAL(-6.5, 2.25L, -2.0L, false, 0); + TEST_SPECIAL(6.5, -2.25L, 2.0L, false, 0); + TEST_SPECIAL(-6.5, -2.25L, -2.0L, false, 0); + + TEST_SPECIAL(nl::max(), nl::max(), 0.0, false, 0); + TEST_SPECIAL(nl::max(), -nl::max(), 0.0, false, 0); + TEST_SPECIAL(nl::max(), nl::min(), 0.0, false, 0); + TEST_SPECIAL(nl::max(), -nl::min(), 0.0, false, 0); + TEST_SPECIAL(nl::max(), nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(nl::max(), -nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(-nl::max(), nl::max(), neg_zero, false, 0); + TEST_SPECIAL(-nl::max(), -nl::max(), neg_zero, false, 0); + TEST_SPECIAL(-nl::max(), nl::min(), neg_zero, false, 0); + TEST_SPECIAL(-nl::max(), -nl::min(), neg_zero, false, 0); + TEST_SPECIAL(-nl::max(), nl::denorm_min(), neg_zero, false, 0); + TEST_SPECIAL(-nl::max(), -nl::denorm_min(), neg_zero, false, 0); + + TEST_SPECIAL(nl::min(), nl::max(), nl::min(), false, 0); + TEST_SPECIAL(nl::min(), -nl::max(), nl::min(), false, 0); + TEST_SPECIAL(nl::min(), nl::min(), 0.0, false, 0); + TEST_SPECIAL(nl::min(), -nl::min(), 0.0, false, 0); + TEST_SPECIAL(nl::min(), nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(nl::min(), -nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(-nl::min(), nl::max(), -nl::min(), false, 0); + TEST_SPECIAL(-nl::min(), -nl::max(), -nl::min(), false, 0); + TEST_SPECIAL(-nl::min(), nl::min(), neg_zero, false, 0); + TEST_SPECIAL(-nl::min(), -nl::min(), neg_zero, false, 0); + TEST_SPECIAL(-nl::min(), nl::denorm_min(), neg_zero, false, 0); + TEST_SPECIAL(-nl::min(), -nl::denorm_min(), neg_zero, false, 0); + + TEST_SPECIAL(nl::denorm_min(), nl::max(), nl::denorm_min(), false, 0); + TEST_SPECIAL(nl::denorm_min(), -nl::max(), nl::denorm_min(), false, 0); + TEST_SPECIAL(nl::denorm_min(), nl::min(), nl::denorm_min(), false, 0); + TEST_SPECIAL(nl::denorm_min(), -nl::min(), nl::denorm_min(), false, 0); + TEST_SPECIAL(nl::denorm_min(), nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(nl::denorm_min(), -nl::denorm_min(), 0.0, false, 0); + TEST_SPECIAL(-nl::denorm_min(), nl::max(), -nl::denorm_min(), false, 0); + TEST_SPECIAL(-nl::denorm_min(), -nl::max(), -nl::denorm_min(), false, 0); + TEST_SPECIAL(-nl::denorm_min(), nl::min(), -nl::denorm_min(), false, 0); + TEST_SPECIAL(-nl::denorm_min(), -nl::min(), -nl::denorm_min(), false, 0); + TEST_SPECIAL(-nl::denorm_min(), nl::denorm_min(), neg_zero, false, 0); + TEST_SPECIAL(-nl::denorm_min(), -nl::denorm_min(), neg_zero, false, 0); + } + + void testRegularExtreme(FModFunc f) { + + TEST_REGULAR(0x1p127L, 0x3p-149L, 0x1p-149L); + TEST_REGULAR(0x1p127L, -0x3p-149L, 0x1p-149L); + TEST_REGULAR(0x1p127L, 0x3p-148L, 0x1p-147L); + TEST_REGULAR(0x1p127L, -0x3p-148L, 0x1p-147L); + TEST_REGULAR(0x1p127L, 0x3p-126L, 0x1p-125L); + TEST_REGULAR(0x1p127L, -0x3p-126L, 0x1p-125L); + TEST_REGULAR(-0x1p127L, 0x3p-149L, -0x1p-149L); + TEST_REGULAR(-0x1p127L, -0x3p-149L, -0x1p-149L); + TEST_REGULAR(-0x1p127L, 0x3p-148L, -0x1p-147L); + TEST_REGULAR(-0x1p127L, -0x3p-148L, -0x1p-147L); + TEST_REGULAR(-0x1p127L, 0x3p-126L, -0x1p-125L); + TEST_REGULAR(-0x1p127L, -0x3p-126L, -0x1p-125L); + + if constexpr (sizeof(T) >= sizeof(double)) { + TEST_REGULAR(0x1p1023L, 0x3p-1074L, 0x1p-1073L); + TEST_REGULAR(0x1p1023L, -0x3p-1074L, 0x1p-1073L); + TEST_REGULAR(0x1p1023L, 0x3p-1073L, 0x1p-1073L); + TEST_REGULAR(0x1p1023L, -0x3p-1073L, 0x1p-1073L); + TEST_REGULAR(0x1p1023L, 0x3p-1022L, 0x1p-1021L); + TEST_REGULAR(0x1p1023L, -0x3p-1022L, 0x1p-1021L); + TEST_REGULAR(-0x1p1023L, 0x3p-1074L, -0x1p-1073L); + TEST_REGULAR(-0x1p1023L, -0x3p-1074L, -0x1p-1073L); + TEST_REGULAR(-0x1p1023L, 0x3p-1073L, -0x1p-1073L); + TEST_REGULAR(-0x1p1023L, -0x3p-1073L, -0x1p-1073L); + TEST_REGULAR(-0x1p1023L, 0x3p-1022L, -0x1p-1021L); + TEST_REGULAR(-0x1p1023L, -0x3p-1022L, -0x1p-1021L); + } + } +}; + +#define LIST_FMOD_TESTS(T, func) \ + using LlvmLibcFmodTest = FmodTest; \ + TEST_F(LlvmLibcFmodTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcFmodTest, RegularExtreme) { testRegularExtreme(&func); } + +#endif // LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H diff --git a/libc/test/src/math/smoke/FloorTest.h b/libc/test/src/math/smoke/FloorTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FloorTest.h @@ -0,0 +1,68 @@ +//===-- Utility class to test floor[f|l] ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class FloorTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*FloorFunc)(T); + + void testSpecialNumbers(FloorFunc func) { + EXPECT_FP_EQ(zero, func(zero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); + + EXPECT_FP_EQ(inf, func(inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); + + EXPECT_FP_EQ(aNaN, func(aNaN)); + } + + void testRoundedNumbers(FloorFunc func) { + EXPECT_FP_EQ(T(1.0), func(T(1.0))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.0))); + EXPECT_FP_EQ(T(10.0), func(T(10.0))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.0))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.0))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0))); + } + + void testFractions(FloorFunc func) { + EXPECT_FP_EQ(T(0.0), func(T(0.5))); + EXPECT_FP_EQ(T(-1.0), func(T(-0.5))); + EXPECT_FP_EQ(T(0.0), func(T(0.115))); + EXPECT_FP_EQ(T(-1.0), func(T(-0.115))); + EXPECT_FP_EQ(T(0.0), func(T(0.715))); + EXPECT_FP_EQ(T(-1.0), func(T(-0.715))); + EXPECT_FP_EQ(T(1.0), func(T(1.3))); + EXPECT_FP_EQ(T(-2.0), func(T(-1.3))); + EXPECT_FP_EQ(T(1.0), func(T(1.5))); + EXPECT_FP_EQ(T(-2.0), func(T(-1.5))); + EXPECT_FP_EQ(T(1.0), func(T(1.75))); + EXPECT_FP_EQ(T(-2.0), func(T(-1.75))); + EXPECT_FP_EQ(T(10.0), func(T(10.32))); + EXPECT_FP_EQ(T(-11.0), func(T(-10.32))); + EXPECT_FP_EQ(T(10.0), func(T(10.65))); + EXPECT_FP_EQ(T(-11.0), func(T(-10.65))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); + EXPECT_FP_EQ(T(-1235.0), func(T(-1234.38))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.96))); + EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96))); + } +}; + +#define LIST_FLOOR_TESTS(T, func) \ + using LlvmLibcFloorTest = FloorTest; \ + TEST_F(LlvmLibcFloorTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcFloorTest, RoundedNubmers) { testRoundedNumbers(&func); } \ + TEST_F(LlvmLibcFloorTest, Fractions) { testFractions(&func); } diff --git a/libc/test/src/math/smoke/FmaTest.h b/libc/test/src/math/smoke/FmaTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FmaTest.h @@ -0,0 +1,57 @@ +//===-- Utility class to test different flavors of fma --------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_FMATEST_H +#define LLVM_LIBC_TEST_SRC_MATH_FMATEST_H + +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +template +class FmaTestTemplate : public __llvm_libc::testing::Test { +private: + using Func = T (*)(T, T, T); + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + const T nan = T(__llvm_libc::fputil::FPBits::build_quiet_nan(1)); + const T inf = T(__llvm_libc::fputil::FPBits::inf()); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); + const T zero = T(__llvm_libc::fputil::FPBits::zero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); + +public: + void test_special_numbers(Func func) { + EXPECT_FP_EQ(func(zero, zero, zero), zero); + EXPECT_FP_EQ(func(zero, neg_zero, neg_zero), neg_zero); + EXPECT_FP_EQ(func(inf, inf, zero), inf); + EXPECT_FP_EQ(func(neg_inf, inf, neg_inf), neg_inf); + EXPECT_FP_EQ(func(inf, zero, zero), nan); + EXPECT_FP_EQ(func(inf, neg_inf, inf), nan); + EXPECT_FP_EQ(func(nan, zero, inf), nan); + EXPECT_FP_EQ(func(inf, neg_inf, nan), nan); + + // Test underflow rounding up. + EXPECT_FP_EQ(func(T(0.5), T(FPBits(FPBits::MIN_SUBNORMAL)), + T(FPBits(FPBits::MIN_SUBNORMAL))), + T(FPBits(UIntType(2)))); + // Test underflow rounding down. + T v = T(FPBits(FPBits::MIN_NORMAL + UIntType(1))); + EXPECT_FP_EQ(func(T(1) / T(FPBits::MIN_NORMAL << 1), v, + T(FPBits(FPBits::MIN_NORMAL))), + v); + // Test overflow. + T z = T(FPBits(FPBits::MAX_NORMAL)); + EXPECT_FP_EQ(func(T(1.75), z, -z), T(0.75) * z); + // Exact cancellation. + EXPECT_FP_EQ(func(T(3.0), T(5.0), -T(15.0)), T(0.0)); + EXPECT_FP_EQ(func(T(-3.0), T(5.0), T(15.0)), T(0.0)); + } +}; + +#endif // LLVM_LIBC_TEST_SRC_MATH_FMATEST_H diff --git a/libc/test/src/math/smoke/FrexpTest.h b/libc/test/src/math/smoke/FrexpTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/FrexpTest.h @@ -0,0 +1,96 @@ +//===-- Utility class to test frexp[f|l] ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/BasicOperations.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class FrexpTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + + static constexpr UIntType HIDDEN_BIT = + UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; + +public: + typedef T (*FrexpFunc)(T, int *); + + void testSpecialNumbers(FrexpFunc func) { + int exponent; + ASSERT_FP_EQ(aNaN, func(aNaN, &exponent)); + ASSERT_FP_EQ(inf, func(inf, &exponent)); + ASSERT_FP_EQ(neg_inf, func(neg_inf, &exponent)); + + ASSERT_FP_EQ(0.0, func(0.0, &exponent)); + ASSERT_EQ(exponent, 0); + + ASSERT_FP_EQ(-0.0, func(-0.0, &exponent)); + ASSERT_EQ(exponent, 0); + } + + void testPowersOfTwo(FrexpFunc func) { + int exponent; + + EXPECT_FP_EQ(T(0.5), func(T(1.0), &exponent)); + EXPECT_EQ(exponent, 1); + EXPECT_FP_EQ(T(-0.5), func(T(-1.0), &exponent)); + EXPECT_EQ(exponent, 1); + + EXPECT_FP_EQ(T(0.5), func(T(2.0), &exponent)); + EXPECT_EQ(exponent, 2); + EXPECT_FP_EQ(T(-0.5), func(T(-2.0), &exponent)); + EXPECT_EQ(exponent, 2); + + EXPECT_FP_EQ(T(0.5), func(T(4.0), &exponent)); + EXPECT_EQ(exponent, 3); + EXPECT_FP_EQ(T(-0.5), func(T(-4.0), &exponent)); + EXPECT_EQ(exponent, 3); + + EXPECT_FP_EQ(T(0.5), func(T(8.0), &exponent)); + EXPECT_EQ(exponent, 4); + EXPECT_FP_EQ(T(-0.5), func(T(-8.0), &exponent)); + EXPECT_EQ(exponent, 4); + + EXPECT_FP_EQ(T(0.5), func(T(16.0), &exponent)); + EXPECT_EQ(exponent, 5); + EXPECT_FP_EQ(T(-0.5), func(T(-16.0), &exponent)); + EXPECT_EQ(exponent, 5); + + EXPECT_FP_EQ(T(0.5), func(T(32.0), &exponent)); + EXPECT_EQ(exponent, 6); + EXPECT_FP_EQ(T(-0.5), func(T(-32.0), &exponent)); + EXPECT_EQ(exponent, 6); + } + + void testSomeIntegers(FrexpFunc func) { + int exponent; + + EXPECT_FP_EQ(T(0.75), func(T(24.0), &exponent)); + EXPECT_EQ(exponent, 5); + EXPECT_FP_EQ(T(-0.75), func(T(-24.0), &exponent)); + EXPECT_EQ(exponent, 5); + + EXPECT_FP_EQ(T(0.625), func(T(40.0), &exponent)); + EXPECT_EQ(exponent, 6); + EXPECT_FP_EQ(T(-0.625), func(T(-40.0), &exponent)); + EXPECT_EQ(exponent, 6); + + EXPECT_FP_EQ(T(0.78125), func(T(800.0), &exponent)); + EXPECT_EQ(exponent, 10); + EXPECT_FP_EQ(T(-0.78125), func(T(-800.0), &exponent)); + EXPECT_EQ(exponent, 10); + } +}; + +#define LIST_FREXP_TESTS(T, func) \ + using LlvmLibcFrexpTest = FrexpTest; \ + TEST_F(LlvmLibcFrexpTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcFrexpTest, PowersOfTwo) { testPowersOfTwo(&func); } \ + TEST_F(LlvmLibcFrexpTest, SomeIntegers) { testSomeIntegers(&func); }\ diff --git a/libc/test/src/math/smoke/HypotTest.h b/libc/test/src/math/smoke/HypotTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/HypotTest.h @@ -0,0 +1,60 @@ +//===-- Utility class to test different flavors of hypot ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H + +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template +class HypotTestTemplate : public __llvm_libc::testing::Test { +private: + using Func = T (*)(T, T); + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + const T nan = T(FPBits::build_quiet_nan(1)); + const T inf = T(FPBits::inf()); + const T neg_inf = T(FPBits::neg_inf()); + const T zero = T(FPBits::zero()); + const T neg_zero = T(FPBits::neg_zero()); + const T max_normal = T(FPBits(FPBits::MAX_NORMAL)); + const T min_normal = T(FPBits(FPBits::MIN_NORMAL)); + const T max_subnormal = T(FPBits(FPBits::MAX_SUBNORMAL)); + const T min_subnormal = T(FPBits(FPBits::MIN_SUBNORMAL)); + +public: + void test_special_numbers(Func func) { + constexpr int N = 4; + // Pythagorean triples. + constexpr T PYT[N][3] = {{3, 4, 5}, {5, 12, 13}, {8, 15, 17}, {7, 24, 25}}; + + EXPECT_FP_EQ(func(inf, nan), inf); + EXPECT_FP_EQ(func(nan, neg_inf), inf); + EXPECT_FP_EQ(func(nan, nan), nan); + EXPECT_FP_EQ(func(nan, zero), nan); + EXPECT_FP_EQ(func(neg_zero, nan), nan); + + for (int i = 0; i < N; ++i) { + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], PYT[i][1])); + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], PYT[i][1])); + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], -PYT[i][1])); + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], -PYT[i][1])); + + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], PYT[i][0])); + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], PYT[i][0])); + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], -PYT[i][0])); + EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], -PYT[i][0])); + } + } +}; + +#endif // LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H diff --git a/libc/test/src/math/smoke/ILogbTest.h b/libc/test/src/math/smoke/ILogbTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ILogbTest.h @@ -0,0 +1,115 @@ +//===-- Utility class to test different flavors of ilogb --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H + +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "test/UnitTest/Test.h" +#include + +#include + +class LlvmLibcILogbTest : public __llvm_libc::testing::Test { +public: + template struct ILogbFunc { + typedef int (*Func)(T); + }; + + template + void test_special_numbers(typename ILogbFunc::Func func) { + EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits::zero()))); + EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits::neg_zero()))); + + EXPECT_EQ(FP_ILOGBNAN, + func(T(__llvm_libc::fputil::FPBits::build_quiet_nan(1)))); + + EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits::inf()))); + EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits::neg_inf()))); + } + + template + void test_powers_of_two(typename ILogbFunc::Func func) { + EXPECT_EQ(0, func(T(1.0))); + EXPECT_EQ(0, func(T(-1.0))); + + EXPECT_EQ(1, func(T(2.0))); + EXPECT_EQ(1, func(T(-2.0))); + + EXPECT_EQ(2, func(T(4.0))); + EXPECT_EQ(2, func(T(-4.0))); + + EXPECT_EQ(3, func(T(8.0))); + EXPECT_EQ(3, func(-8.0)); + + EXPECT_EQ(4, func(16.0)); + EXPECT_EQ(4, func(-16.0)); + + EXPECT_EQ(5, func(32.0)); + EXPECT_EQ(5, func(-32.0)); + } + + template + void test_some_integers(typename ILogbFunc::Func func) { + EXPECT_EQ(1, func(T(3.0))); + EXPECT_EQ(1, func(T(-3.0))); + + EXPECT_EQ(2, func(T(7.0))); + EXPECT_EQ(2, func(T(-7.0))); + + EXPECT_EQ(3, func(T(10.0))); + EXPECT_EQ(3, func(T(-10.0))); + + EXPECT_EQ(4, func(T(31.0))); + EXPECT_EQ(4, func(-31.0)); + + EXPECT_EQ(5, func(55.0)); + EXPECT_EQ(5, func(-55.0)); + } + + template + void test_subnormal_range(typename ILogbFunc::Func func) { + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + constexpr UIntType COUNT = 10'001; + constexpr UIntType STEP = + (UIntType(FPBits::MAX_SUBNORMAL) - UIntType(FPBits::MIN_SUBNORMAL)) / + COUNT; + for (UIntType v = FPBits::MIN_SUBNORMAL; v <= FPBits::MAX_SUBNORMAL; + v += STEP) { + T x = T(FPBits(v)); + if (isnan(x) || isinf(x) || x == 0.0) + continue; + + int exponent; + __llvm_libc::fputil::frexp(x, exponent); + ASSERT_EQ(exponent, func(x) + 1); + } + } + + template + void test_normal_range(typename ILogbFunc::Func func) { + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + constexpr UIntType COUNT = 10'001; + constexpr UIntType STEP = + (UIntType(FPBits::MAX_NORMAL) - UIntType(FPBits::MIN_NORMAL)) / COUNT; + for (UIntType v = FPBits::MIN_NORMAL; v <= FPBits::MAX_NORMAL; v += STEP) { + T x = T(FPBits(v)); + if (isnan(x) || isinf(x) || x == 0.0) + continue; + + int exponent; + __llvm_libc::fputil::frexp(x, exponent); + ASSERT_EQ(exponent, func(x) + 1); + } + } +}; + +#endif // LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H diff --git a/libc/test/src/math/smoke/LdExpTest.h b/libc/test/src/math/smoke/LdExpTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/LdExpTest.h @@ -0,0 +1,166 @@ +//===-- Utility class to test different flavors of ldexp --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H + +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/NormalFloat.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include +#include +#include + +template +class LdExpTestTemplate : public __llvm_libc::testing::Test { + using FPBits = __llvm_libc::fputil::FPBits; + using NormalFloat = __llvm_libc::fputil::NormalFloat; + using UIntType = typename FPBits::UIntType; + static constexpr UIntType MANTISSA_WIDTH = + __llvm_libc::fputil::MantissaWidth::VALUE; + // A normalized mantissa to be used with tests. + static constexpr UIntType MANTISSA = NormalFloat::ONE + 0x1234; + + const T zero = T(__llvm_libc::fputil::FPBits::zero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); + const T inf = T(__llvm_libc::fputil::FPBits::inf()); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); + const T nan = T(__llvm_libc::fputil::FPBits::build_quiet_nan(1)); + +public: + typedef T (*LdExpFunc)(T, int); + + void testSpecialNumbers(LdExpFunc func) { + int exp_array[5] = {-INT_MAX - 1, -10, 0, 10, INT_MAX}; + for (int exp : exp_array) { + ASSERT_FP_EQ(zero, func(zero, exp)); + ASSERT_FP_EQ(neg_zero, func(neg_zero, exp)); + ASSERT_FP_EQ(inf, func(inf, exp)); + ASSERT_FP_EQ(neg_inf, func(neg_inf, exp)); + ASSERT_FP_EQ(nan, func(nan, exp)); + } + } + + void testPowersOfTwo(LdExpFunc func) { + int32_t exp_array[5] = {1, 2, 3, 4, 5}; + int32_t val_array[6] = {1, 2, 4, 8, 16, 32}; + for (int32_t exp : exp_array) { + for (int32_t val : val_array) { + ASSERT_FP_EQ(T(val << exp), func(T(val), exp)); + ASSERT_FP_EQ(T(-1 * (val << exp)), func(T(-val), exp)); + } + } + } + + void testOverflow(LdExpFunc func) { + NormalFloat x(FPBits::MAX_EXPONENT - 10, NormalFloat::ONE + 0xF00BA, 0); + for (int32_t exp = 10; exp < 100; ++exp) { + ASSERT_FP_EQ(inf, func(T(x), exp)); + ASSERT_FP_EQ(neg_inf, func(-T(x), exp)); + } + } + + void testUnderflowToZeroOnNormal(LdExpFunc func) { + // In this test, we pass a normal nubmer to func and expect zero + // to be returned due to underflow. + int32_t base_exponent = FPBits::EXPONENT_BIAS + int32_t(MANTISSA_WIDTH); + int32_t exp_array[] = {base_exponent + 5, base_exponent + 4, + base_exponent + 3, base_exponent + 2, + base_exponent + 1}; + T x = NormalFloat(0, MANTISSA, 0); + for (int32_t exp : exp_array) { + ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : neg_zero); + } + } + + void testUnderflowToZeroOnSubnormal(LdExpFunc func) { + // In this test, we pass a normal nubmer to func and expect zero + // to be returned due to underflow. + int32_t base_exponent = FPBits::EXPONENT_BIAS + int32_t(MANTISSA_WIDTH); + int32_t exp_array[] = {base_exponent + 5, base_exponent + 4, + base_exponent + 3, base_exponent + 2, + base_exponent + 1}; + T x = NormalFloat(-FPBits::EXPONENT_BIAS, MANTISSA, 0); + for (int32_t exp : exp_array) { + ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : neg_zero); + } + } + + void testNormalOperation(LdExpFunc func) { + T val_array[] = { + // Normal numbers + NormalFloat(100, MANTISSA, 0), NormalFloat(-100, MANTISSA, 0), + NormalFloat(100, MANTISSA, 1), NormalFloat(-100, MANTISSA, 1), + // Subnormal numbers + NormalFloat(-FPBits::EXPONENT_BIAS, MANTISSA, 0), + NormalFloat(-FPBits::EXPONENT_BIAS, MANTISSA, 1)}; + for (int32_t exp = 0; exp <= static_cast(MANTISSA_WIDTH); ++exp) { + for (T x : val_array) { + // We compare the result of ldexp with the result + // of the native multiplication/division instruction. + + // We need to use a NormalFloat here (instead of 1 << exp), because + // there are 32 bit systems that don't support 128bit long ints but + // support long doubles. This test can do 1 << 64, which would fail + // in these systems. + NormalFloat two_to_exp = NormalFloat(static_cast(1.L)); + two_to_exp = two_to_exp.mul2(exp); + + ASSERT_FP_EQ(func(x, exp), x * two_to_exp); + ASSERT_FP_EQ(func(x, -exp), x / two_to_exp); + } + } + + // Normal which trigger mantissa overflow. + T x = NormalFloat(-FPBits::EXPONENT_BIAS + 1, + UIntType(2) * NormalFloat::ONE - UIntType(1), 0); + ASSERT_FP_EQ(func(x, -1), x / 2); + ASSERT_FP_EQ(func(-x, -1), -x / 2); + + // Start with a normal number high exponent but pass a very low number for + // exp. The result should be a subnormal number. + x = NormalFloat(FPBits::EXPONENT_BIAS, NormalFloat::ONE, 0); + int exp = -FPBits::MAX_EXPONENT - 5; + T result = func(x, exp); + FPBits result_bits(result); + ASSERT_FALSE(result_bits.is_zero()); + // Verify that the result is indeed subnormal. + ASSERT_EQ(result_bits.get_unbiased_exponent(), uint16_t(0)); + // But if the exp is so less that normalization leads to zero, then + // the result should be zero. + result = func(x, -FPBits::MAX_EXPONENT - int(MANTISSA_WIDTH) - 5); + ASSERT_TRUE(FPBits(result).is_zero()); + + // Start with a subnormal number but pass a very high number for exponent. + // The result should not be infinity. + x = NormalFloat(-FPBits::EXPONENT_BIAS + 1, NormalFloat::ONE >> 10, 0); + exp = FPBits::MAX_EXPONENT + 5; + ASSERT_FALSE(FPBits(func(x, exp)).is_inf()); + // But if the exp is large enough to oversome than the normalization shift, + // then it should result in infinity. + exp = FPBits::MAX_EXPONENT + 15; + ASSERT_FP_EQ(func(x, exp), inf); + } +}; + +#define LIST_LDEXP_TESTS(T, func) \ + using LlvmLibcLdExpTest = LdExpTestTemplate; \ + TEST_F(LlvmLibcLdExpTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcLdExpTest, PowersOfTwo) { testPowersOfTwo(&func); } \ + TEST_F(LlvmLibcLdExpTest, OverFlow) { testOverflow(&func); } \ + TEST_F(LlvmLibcLdExpTest, UnderflowToZeroOnNormal) { \ + testUnderflowToZeroOnNormal(&func); \ + } \ + TEST_F(LlvmLibcLdExpTest, UnderflowToZeroOnSubnormal) { \ + testUnderflowToZeroOnSubnormal(&func); \ + } \ + TEST_F(LlvmLibcLdExpTest, NormalOperation) { testNormalOperation(&func); } + +#endif // LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H diff --git a/libc/test/src/math/smoke/LogbTest.h b/libc/test/src/math/smoke/LogbTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/LogbTest.h @@ -0,0 +1,91 @@ +//===-- Utility class to test logb[f|l] -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class LogbTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + + static constexpr UIntType HIDDEN_BIT = + UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; + +public: + typedef T (*LogbFunc)(T); + + void testSpecialNumbers(LogbFunc func) { + ASSERT_FP_EQ(aNaN, func(aNaN)); + ASSERT_FP_EQ(inf, func(inf)); + ASSERT_FP_EQ(inf, func(neg_inf)); + ASSERT_FP_EQ(neg_inf, func(0.0)); + ASSERT_FP_EQ(neg_inf, func(-0.0)); + } + + void testPowersOfTwo(LogbFunc func) { + EXPECT_FP_EQ(T(0.0), func(T(1.0))); + EXPECT_FP_EQ(T(0.0), func(T(-1.0))); + + EXPECT_FP_EQ(T(1.0), func(T(2.0))); + EXPECT_FP_EQ(T(1.0), func(T(-2.0))); + + EXPECT_FP_EQ(T(2.0), func(T(4.0))); + EXPECT_FP_EQ(T(2.0), func(T(-4.0))); + + EXPECT_FP_EQ(T(3.0), func(T(8.0))); + EXPECT_FP_EQ(T(3.0), func(T(-8.0))); + + EXPECT_FP_EQ(T(4.0), func(T(16.0))); + EXPECT_FP_EQ(T(4.0), func(T(-16.0))); + + EXPECT_FP_EQ(T(5.0), func(T(32.0))); + EXPECT_FP_EQ(T(5.0), func(T(-32.0))); + } + + void testSomeIntegers(LogbFunc func) { + EXPECT_FP_EQ(T(1.0), func(T(3.0))); + EXPECT_FP_EQ(T(1.0), func(T(-3.0))); + + EXPECT_FP_EQ(T(2.0), func(T(7.0))); + EXPECT_FP_EQ(T(2.0), func(T(-7.0))); + + EXPECT_FP_EQ(T(3.0), func(T(10.0))); + EXPECT_FP_EQ(T(3.0), func(T(-10.0))); + + EXPECT_FP_EQ(T(4.0), func(T(31.0))); + EXPECT_FP_EQ(T(4.0), func(T(-31.0))); + + EXPECT_FP_EQ(T(5.0), func(T(55.0))); + EXPECT_FP_EQ(T(5.0), func(T(-55.0))); + } + + void testRange(LogbFunc func) { + using UIntType = typename FPBits::UIntType; + constexpr UIntType COUNT = 100'000; + constexpr UIntType STEP = UIntType(-1) / COUNT; + for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) { + T x = static_cast(FPBits(v)); + if (isnan(x) || isinf(x) || x == 0.0l) + continue; + + int exponent; + __llvm_libc::fputil::frexp(x, exponent); + ASSERT_FP_EQ(T(exponent), func(x) + T(1.0)); + } + } +}; + +#define LIST_LOGB_TESTS(T, func) \ + using LlvmLibcLogbTest = LogbTest; \ + TEST_F(LlvmLibcLogbTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcLogbTest, PowersOfTwo) { testPowersOfTwo(&func); } \ + TEST_F(LlvmLibcLogbTest, SomeIntegers) { testSomeIntegers(&func); } \ + TEST_F(LlvmLibcLogbTest, InRange) { testRange(&func); } diff --git a/libc/test/src/math/smoke/ModfTest.h b/libc/test/src/math/smoke/ModfTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ModfTest.h @@ -0,0 +1,105 @@ +//===-- Utility class to test floor[f|l] ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class ModfTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*ModfFunc)(T, T *); + + void testSpecialNumbers(ModfFunc func) { + T integral; + + EXPECT_FP_EQ(zero, func(zero, &integral)); + EXPECT_FP_EQ(integral, zero); + EXPECT_FP_EQ(neg_zero, func(neg_zero, &integral)); + EXPECT_FP_EQ(integral, neg_zero); + + EXPECT_FP_EQ(zero, func(inf, &integral)); + EXPECT_FP_EQ(inf, integral); + EXPECT_FP_EQ(neg_zero, func(neg_inf, &integral)); + EXPECT_FP_EQ(neg_inf, integral); + + EXPECT_FP_EQ(aNaN, func(aNaN, &integral)); + } + + void testIntegers(ModfFunc func) { + T integral; + + EXPECT_FP_EQ(T(0.0), func(T(1.0), &integral)); + EXPECT_FP_EQ(T(1.0), integral); + + EXPECT_FP_EQ(T(-0.0), func(T(-1.0), &integral)); + EXPECT_FP_EQ(T(-1.0), integral); + + EXPECT_FP_EQ(T(0.0), func(T(10.0), &integral)); + EXPECT_FP_EQ(T(10.0), integral); + + EXPECT_FP_EQ(T(-0.0), func(T(-10.0), &integral)); + EXPECT_FP_EQ(T(-10.0), integral); + + EXPECT_FP_EQ(T(0.0), func(T(12345.0), &integral)); + EXPECT_FP_EQ(T(12345.0), integral); + + EXPECT_FP_EQ(T(-0.0), func(T(-12345.0), &integral)); + EXPECT_FP_EQ(T(-12345.0), integral); + } + + void testFractions(ModfFunc func) { + T integral; + + EXPECT_FP_EQ(T(0.5), func(T(1.5), &integral)); + EXPECT_FP_EQ(integral, T(1.0)); + + EXPECT_FP_EQ(T(-0.5), func(T(-1.5), &integral)); + EXPECT_FP_EQ(integral, T(-1.0)); + + EXPECT_FP_EQ(T(0.75), func(T(10.75), &integral)); + EXPECT_FP_EQ(integral, T(10.0)); + + EXPECT_FP_EQ(T(-0.75), func(T(-10.75), &integral)); + EXPECT_FP_EQ(integral, T(-10.0)); + + EXPECT_FP_EQ(T(0.125), func(T(100.125), &integral)); + EXPECT_FP_EQ(integral, T(100.0)); + + EXPECT_FP_EQ(T(-0.125), func(T(-100.125), &integral)); + EXPECT_FP_EQ(integral, T(-100.0)); + } + + void testRange(ModfFunc func) { + constexpr UIntType COUNT = 100'000; + constexpr UIntType STEP = UIntType(-1) / COUNT; + for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) { + T x = T(FPBits(v)); + if (isnan(x) || isinf(x) || x == T(0.0)) + continue; + + T integral; + T frac = func(x, &integral); + ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0l); + ASSERT_TRUE(__llvm_libc::fputil::trunc(x) == integral); + ASSERT_TRUE(integral + frac == x); + } + } +}; + +#define LIST_MODF_TESTS(T, func) \ + using LlvmLibcModfTest = ModfTest; \ + TEST_F(LlvmLibcModfTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcModfTest, RoundedNubmers) { testIntegers(&func); } \ + TEST_F(LlvmLibcModfTest, Fractions) { testFractions(&func); } \ + TEST_F(LlvmLibcModfTest, Range) { testRange(&func); } diff --git a/libc/test/src/math/smoke/NextAfterTest.h b/libc/test/src/math/smoke/NextAfterTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/NextAfterTest.h @@ -0,0 +1,198 @@ +//===-- Utility class to test different flavors of nextafter ----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H + +#include "src/__support/CPP/bit.h" +#include "src/__support/CPP/type_traits.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +template +class NextAfterTestTemplate : public __llvm_libc::testing::Test { + using FPBits = __llvm_libc::fputil::FPBits; + using MantissaWidth = __llvm_libc::fputil::MantissaWidth; + using UIntType = typename FPBits::UIntType; + + static constexpr int BIT_WIDTH_OF_TYPE = + __llvm_libc::fputil::FloatProperties::BIT_WIDTH; + + const T zero = T(FPBits::zero()); + const T neg_zero = T(FPBits::neg_zero()); + const T inf = T(FPBits::inf()); + const T neg_inf = T(FPBits::neg_inf()); + const T nan = T(FPBits::build_quiet_nan(1)); + const UIntType min_subnormal = FPBits::MIN_SUBNORMAL; + const UIntType max_subnormal = FPBits::MAX_SUBNORMAL; + const UIntType min_normal = FPBits::MIN_NORMAL; + const UIntType max_normal = FPBits::MAX_NORMAL; + +public: + typedef T (*NextAfterFunc)(T, T); + + void testNaN(NextAfterFunc func) { + ASSERT_FP_EQ(func(nan, 0), nan); + ASSERT_FP_EQ(func(0, nan), nan); + } + + void testBoundaries(NextAfterFunc func) { + ASSERT_FP_EQ(func(zero, neg_zero), neg_zero); + ASSERT_FP_EQ(func(neg_zero, zero), zero); + + // 'from' is zero|neg_zero. + T x = zero; + T result = func(x, T(1)); + UIntType expected_bits = 1; + T expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + result = func(x, T(-1)); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + x = neg_zero; + result = func(x, 1); + expected_bits = 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + result = func(x, -1); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + // 'from' is max subnormal value. + x = __llvm_libc::cpp::bit_cast(max_subnormal); + result = func(x, 1); + expected = __llvm_libc::cpp::bit_cast(min_normal); + ASSERT_FP_EQ(result, expected); + + result = func(x, 0); + expected_bits = max_subnormal - 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + x = -x; + + result = func(x, -1); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + result = func(x, 0); + expected_bits = + (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal - 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + // 'from' is min subnormal value. + x = __llvm_libc::cpp::bit_cast(min_subnormal); + result = func(x, 1); + expected_bits = min_subnormal + 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + ASSERT_FP_EQ(func(x, 0), 0); + + x = -x; + result = func(x, -1); + expected_bits = + (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_subnormal + 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + ASSERT_FP_EQ(func(x, 0), T(-0.0)); + + // 'from' is min normal. + x = __llvm_libc::cpp::bit_cast(min_normal); + result = func(x, 0); + expected_bits = max_subnormal; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + result = func(x, inf); + expected_bits = min_normal + 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + x = -x; + result = func(x, 0); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + result = func(x, -inf); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal + 1; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + + // 'from' is max normal and 'to' is infinity. + x = __llvm_libc::cpp::bit_cast(max_normal); + result = func(x, inf); + ASSERT_FP_EQ(result, inf); + + result = func(-x, -inf); + ASSERT_FP_EQ(result, -inf); + + // 'from' is infinity. + x = inf; + result = func(x, 0); + expected_bits = max_normal; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + ASSERT_FP_EQ(func(x, inf), inf); + + x = neg_inf; + result = func(x, 0); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_normal; + expected = __llvm_libc::cpp::bit_cast(expected_bits); + ASSERT_FP_EQ(result, expected); + ASSERT_FP_EQ(func(x, neg_inf), neg_inf); + + // 'from' is a power of 2. + x = T(32.0); + result = func(x, 0); + FPBits x_bits = FPBits(x); + FPBits result_bits = FPBits(result); + ASSERT_EQ(result_bits.get_unbiased_exponent(), + uint16_t(x_bits.get_unbiased_exponent() - 1)); + ASSERT_EQ(result_bits.get_mantissa(), + (UIntType(1) << MantissaWidth::VALUE) - 1); + + result = func(x, T(33.0)); + result_bits = FPBits(result); + ASSERT_EQ(result_bits.get_unbiased_exponent(), + x_bits.get_unbiased_exponent()); + ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1)); + + x = -x; + + result = func(x, 0); + result_bits = FPBits(result); + ASSERT_EQ(result_bits.get_unbiased_exponent(), + uint16_t(x_bits.get_unbiased_exponent() - 1)); + ASSERT_EQ(result_bits.get_mantissa(), + (UIntType(1) << MantissaWidth::VALUE) - 1); + + result = func(x, T(-33.0)); + result_bits = FPBits(result); + ASSERT_EQ(result_bits.get_unbiased_exponent(), + x_bits.get_unbiased_exponent()); + ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1)); + } +}; + +#define LIST_NEXTAFTER_TESTS(T, func) \ + using LlvmLibcNextAfterTest = NextAfterTestTemplate; \ + TEST_F(LlvmLibcNextAfterTest, TestNaN) { testNaN(&func); } \ + TEST_F(LlvmLibcNextAfterTest, TestBoundaries) { testBoundaries(&func); } + +#endif // LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H diff --git a/libc/test/src/math/smoke/RIntTest.h b/libc/test/src/math/smoke/RIntTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/RIntTest.h @@ -0,0 +1,56 @@ +//===-- Utility class to test different flavors of rint ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H + +#include "src/__support/FPUtil/FEnvImpl.h" +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include +#include +#include + +static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO, + FE_TONEAREST}; + +template +class RIntTestTemplate : public __llvm_libc::testing::Test { +public: + typedef T (*RIntFunc)(T); + +private: + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + + const T zero = T(FPBits::zero()); + const T neg_zero = T(FPBits::neg_zero()); + const T inf = T(FPBits::inf()); + const T neg_inf = T(FPBits::neg_inf()); + const T nan = T(FPBits::build_quiet_nan(1)); + +public: + void testSpecialNumbers(RIntFunc func) { + for (int mode : ROUNDING_MODES) { + __llvm_libc::fputil::set_round(mode); + ASSERT_FP_EQ(inf, func(inf)); + ASSERT_FP_EQ(neg_inf, func(neg_inf)); + ASSERT_FP_EQ(nan, func(nan)); + ASSERT_FP_EQ(zero, func(zero)); + ASSERT_FP_EQ(neg_zero, func(neg_zero)); + } + } +}; + +#define LIST_RINT_TESTS(F, func) \ + using LlvmLibcRIntTest = RIntTestTemplate; \ + TEST_F(LlvmLibcRIntTest, specialNumbers) { testSpecialNumbers(&func); } + +#endif // LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H diff --git a/libc/test/src/math/smoke/RemQuoTest.h b/libc/test/src/math/smoke/RemQuoTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/RemQuoTest.h @@ -0,0 +1,102 @@ +//===-- Utility class to test different flavors of remquo -------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H + +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +template +class RemQuoTestTemplate : public __llvm_libc::testing::Test { + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + + const T zero = T(__llvm_libc::fputil::FPBits::zero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); + const T inf = T(__llvm_libc::fputil::FPBits::inf()); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); + const T nan = T(__llvm_libc::fputil::FPBits::build_quiet_nan(1)); + +public: + typedef T (*RemQuoFunc)(T, T, int *); + + void testSpecialNumbers(RemQuoFunc func) { + int quotient; + T x, y; + + y = T(1.0); + x = inf; + EXPECT_FP_EQ(nan, func(x, y, "ient)); + x = neg_inf; + EXPECT_FP_EQ(nan, func(x, y, "ient)); + + x = T(1.0); + y = zero; + EXPECT_FP_EQ(nan, func(x, y, "ient)); + y = neg_zero; + EXPECT_FP_EQ(nan, func(x, y, "ient)); + + y = nan; + x = T(1.0); + EXPECT_FP_EQ(nan, func(x, y, "ient)); + + y = T(1.0); + x = nan; + EXPECT_FP_EQ(nan, func(x, y, "ient)); + + x = nan; + y = nan; + EXPECT_FP_EQ(nan, func(x, y, "ient)); + + x = zero; + y = T(1.0); + EXPECT_FP_EQ(func(x, y, "ient), zero); + + x = neg_zero; + y = T(1.0); + EXPECT_FP_EQ(func(x, y, "ient), neg_zero); + + x = T(1.125); + y = inf; + EXPECT_FP_EQ(func(x, y, "ient), x); + EXPECT_EQ(quotient, 0); + } + + void testEqualNumeratorAndDenominator(RemQuoFunc func) { + T x = T(1.125), y = T(1.125); + int q; + + // When the remainder is zero, the standard requires it to + // have the same sign as x. + + EXPECT_FP_EQ(func(x, y, &q), zero); + EXPECT_EQ(q, 1); + + EXPECT_FP_EQ(func(x, -y, &q), zero); + EXPECT_EQ(q, -1); + + EXPECT_FP_EQ(func(-x, y, &q), neg_zero); + EXPECT_EQ(q, -1); + + EXPECT_FP_EQ(func(-x, -y, &q), neg_zero); + EXPECT_EQ(q, 1); + } +}; + +#define LIST_REMQUO_TESTS(T, func) \ + using LlvmLibcRemQuoTest = RemQuoTestTemplate; \ + TEST_F(LlvmLibcRemQuoTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcRemQuoTest, EqualNumeratorAndDenominator) { \ + testEqualNumeratorAndDenominator(&func); \ + } + +#endif // LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H diff --git a/libc/test/src/math/smoke/RoundTest.h b/libc/test/src/math/smoke/RoundTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/RoundTest.h @@ -0,0 +1,68 @@ +//===-- Utility class to test round[f|l] ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class RoundTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*RoundFunc)(T); + + void testSpecialNumbers(RoundFunc func) { + EXPECT_FP_EQ(zero, func(zero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); + + EXPECT_FP_EQ(inf, func(inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); + + EXPECT_FP_EQ(aNaN, func(aNaN)); + } + + void testRoundedNumbers(RoundFunc func) { + EXPECT_FP_EQ(T(1.0), func(T(1.0))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.0))); + EXPECT_FP_EQ(T(10.0), func(T(10.0))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.0))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.0))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0))); + } + + void testFractions(RoundFunc func) { + EXPECT_FP_EQ(T(1.0), func(T(0.5))); + EXPECT_FP_EQ(T(-1.0), func(T(-0.5))); + EXPECT_FP_EQ(T(0.0), func(T(0.115))); + EXPECT_FP_EQ(T(-0.0), func(T(-0.115))); + EXPECT_FP_EQ(T(1.0), func(T(0.715))); + EXPECT_FP_EQ(T(-1.0), func(T(-0.715))); + EXPECT_FP_EQ(T(1.0), func(T(1.3))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.3))); + EXPECT_FP_EQ(T(2.0), func(T(1.5))); + EXPECT_FP_EQ(T(-2.0), func(T(-1.5))); + EXPECT_FP_EQ(T(2.0), func(T(1.75))); + EXPECT_FP_EQ(T(-2.0), func(T(-1.75))); + EXPECT_FP_EQ(T(10.0), func(T(10.32))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); + EXPECT_FP_EQ(T(11.0), func(T(10.65))); + EXPECT_FP_EQ(T(-11.0), func(T(-10.65))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); + EXPECT_FP_EQ(T(1235.0), func(T(1234.96))); + EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96))); + } +}; + +#define LIST_ROUND_TESTS(T, func) \ + using LlvmLibcRoundTest = RoundTest; \ + TEST_F(LlvmLibcRoundTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcRoundTest, RoundedNubmers) { testRoundedNumbers(&func); } \ + TEST_F(LlvmLibcRoundTest, Fractions) { testFractions(&func); } diff --git a/libc/test/src/math/smoke/RoundToIntegerTest.h b/libc/test/src/math/smoke/RoundToIntegerTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/RoundToIntegerTest.h @@ -0,0 +1,168 @@ +//===-- Utility class to test different flavors of [l|ll]round --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H + +#include "src/__support/FPUtil/FEnvImpl.h" +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include +#include + +static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO, + FE_TONEAREST}; + +template +class RoundToIntegerTestTemplate : public __llvm_libc::testing::Test { +public: + typedef I (*RoundToIntegerFunc)(F); + +private: + using FPBits = __llvm_libc::fputil::FPBits; + using UIntType = typename FPBits::UIntType; + + const F zero = F(__llvm_libc::fputil::FPBits::zero()); + const F neg_zero = F(__llvm_libc::fputil::FPBits::neg_zero()); + const F inf = F(__llvm_libc::fputil::FPBits::inf()); + const F neg_inf = F(__llvm_libc::fputil::FPBits::neg_inf()); + const F nan = F(__llvm_libc::fputil::FPBits::build_quiet_nan(1)); + static constexpr I INTEGER_MIN = I(1) << (sizeof(I) * 8 - 1); + static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1); + + void test_one_input(RoundToIntegerFunc func, F input, I expected, + bool expectError) { + libc_errno = 0; + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + + ASSERT_EQ(func(input), expected); + + if (expectError) { + ASSERT_FP_EXCEPTION(FE_INVALID); + ASSERT_MATH_ERRNO(EDOM); + } else { + ASSERT_FP_EXCEPTION(0); + ASSERT_MATH_ERRNO(0); + } + } + +public: + void SetUp() override { + if (math_errhandling & MATH_ERREXCEPT) { + // We will disable all exceptions so that the test will not + // crash with SIGFPE. We can still use fetestexcept to check + // if the appropriate flag was raised. + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + } + } + + void do_infinity_and_na_n_test(RoundToIntegerFunc func) { + test_one_input(func, inf, INTEGER_MAX, true); + test_one_input(func, neg_inf, INTEGER_MIN, true); + // This is currently never enabled, the + // LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR CMake option in + // libc/CMakeLists.txt is not forwarded to C++. +#if LIBC_COPT_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR + // Result is not well-defined, we always returns INTEGER_MAX + test_one_input(func, nan, INTEGER_MAX, true); +#endif // LIBC_COPT_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR + } + + void testInfinityAndNaN(RoundToIntegerFunc func) { + if (TestModes) { + for (int mode : ROUNDING_MODES) { + __llvm_libc::fputil::set_round(mode); + do_infinity_and_na_n_test(func); + } + } else { + do_infinity_and_na_n_test(func); + } + } + + void do_round_numbers_test(RoundToIntegerFunc func) { + test_one_input(func, zero, I(0), false); + test_one_input(func, neg_zero, I(0), false); + test_one_input(func, F(1.0), I(1), false); + test_one_input(func, F(-1.0), I(-1), false); + test_one_input(func, F(10.0), I(10), false); + test_one_input(func, F(-10.0), I(-10), false); + test_one_input(func, F(1234.0), I(1234), false); + test_one_input(func, F(-1234.0), I(-1234), false); + } + + void testRoundNumbers(RoundToIntegerFunc func) { + if (TestModes) { + for (int mode : ROUNDING_MODES) { + __llvm_libc::fputil::set_round(mode); + do_round_numbers_test(func); + } + } else { + do_round_numbers_test(func); + } + } + + void testSubnormalRange(RoundToIntegerFunc func) { + constexpr UIntType COUNT = 1'000'001; + constexpr UIntType STEP = + (UIntType(FPBits::MAX_SUBNORMAL) - UIntType(FPBits::MIN_SUBNORMAL)) / + COUNT; + for (UIntType i = FPBits::MIN_SUBNORMAL; i <= FPBits::MAX_SUBNORMAL; + i += STEP) { + F x = F(FPBits(i)); + if (x == F(0.0)) + continue; + // All subnormal numbers should round to zero. + if (TestModes) { + if (x > 0) { + __llvm_libc::fputil::set_round(FE_UPWARD); + test_one_input(func, x, I(1), false); + __llvm_libc::fputil::set_round(FE_DOWNWARD); + test_one_input(func, x, I(0), false); + __llvm_libc::fputil::set_round(FE_TOWARDZERO); + test_one_input(func, x, I(0), false); + __llvm_libc::fputil::set_round(FE_TONEAREST); + test_one_input(func, x, I(0), false); + } else { + __llvm_libc::fputil::set_round(FE_UPWARD); + test_one_input(func, x, I(0), false); + __llvm_libc::fputil::set_round(FE_DOWNWARD); + test_one_input(func, x, I(-1), false); + __llvm_libc::fputil::set_round(FE_TOWARDZERO); + test_one_input(func, x, I(0), false); + __llvm_libc::fputil::set_round(FE_TONEAREST); + test_one_input(func, x, I(0), false); + } + } else { + test_one_input(func, x, 0L, false); + } + } + } +}; + +#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, TestModes) \ + using LlvmLibcRoundToIntegerTest = \ + RoundToIntegerTestTemplate; \ + TEST_F(LlvmLibcRoundToIntegerTest, InfinityAndNaN) { \ + testInfinityAndNaN(&func); \ + } \ + TEST_F(LlvmLibcRoundToIntegerTest, RoundNumbers) { \ + testRoundNumbers(&func); \ + } \ + TEST_F(LlvmLibcRoundToIntegerTest, SubnormalRange) { \ + testSubnormalRange(&func); \ + } + +#define LIST_ROUND_TO_INTEGER_TESTS(F, I, func) \ + LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false) + +#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \ + LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, true) + +#endif // LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H diff --git a/libc/test/src/math/smoke/ScalbnTest.h b/libc/test/src/math/smoke/ScalbnTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ScalbnTest.h @@ -0,0 +1,28 @@ +//===-- Utility class to test different flavors of scalbn -------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_SCALBN_H +#define LLVM_LIBC_TEST_SRC_MATH_SCALBN_H + +#include "LdExpTest.h" +#include "test/UnitTest/Test.h" + +#define LIST_SCALBN_TESTS(T, func) \ + using LlvmLibcScalbnTest = LdExpTestTemplate; \ + TEST_F(LlvmLibcScalbnTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcScalbnTest, PowersOfTwo) { testPowersOfTwo(&func); } \ + TEST_F(LlvmLibcScalbnTest, OverFlow) { testOverflow(&func); } \ + TEST_F(LlvmLibcScalbnTest, UnderflowToZeroOnNormal) { \ + testUnderflowToZeroOnNormal(&func); \ + } \ + TEST_F(LlvmLibcScalbnTest, UnderflowToZeroOnSubnormal) { \ + testUnderflowToZeroOnSubnormal(&func); \ + } \ + TEST_F(LlvmLibcScalbnTest, NormalOperation) { testNormalOperation(&func); } + +#endif // LLVM_LIBC_TEST_SRC_MATH_SCALBN_H diff --git a/libc/test/src/math/smoke/SqrtTest.h b/libc/test/src/math/smoke/SqrtTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/SqrtTest.h @@ -0,0 +1,40 @@ +//===-- Utility class to test sqrt[f|l] -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/CPP/bit.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class SqrtTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + + static constexpr UIntType HIDDEN_BIT = + UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; + +public: + typedef T (*SqrtFunc)(T); + + void test_special_numbers(SqrtFunc func) { + ASSERT_FP_EQ(aNaN, func(aNaN)); + ASSERT_FP_EQ(inf, func(inf)); + ASSERT_FP_EQ(aNaN, func(neg_inf)); + ASSERT_FP_EQ(0.0, func(0.0)); + ASSERT_FP_EQ(-0.0, func(-0.0)); + ASSERT_FP_EQ(aNaN, func(T(-1.0))); + ASSERT_FP_EQ(T(1.0), func(T(1.0))); + ASSERT_FP_EQ(T(2.0), func(T(4.0))); + ASSERT_FP_EQ(T(3.0), func(T(9.0))); + } +}; + +#define LIST_SQRT_TESTS(T, func) \ + using LlvmLibcSqrtTest = SqrtTest; \ + TEST_F(LlvmLibcSqrtTest, SpecialNumbers) { test_special_numbers(&func); } diff --git a/libc/test/src/math/smoke/TruncTest.h b/libc/test/src/math/smoke/TruncTest.h new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/TruncTest.h @@ -0,0 +1,68 @@ +//===-- Utility class to test trunc[f|l] ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include + +template class TruncTest : public __llvm_libc::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef T (*TruncFunc)(T); + + void testSpecialNumbers(TruncFunc func) { + EXPECT_FP_EQ(zero, func(zero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); + + EXPECT_FP_EQ(inf, func(inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); + + EXPECT_FP_EQ(aNaN, func(aNaN)); + } + + void testRoundedNumbers(TruncFunc func) { + EXPECT_FP_EQ(T(1.0), func(T(1.0))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.0))); + EXPECT_FP_EQ(T(10.0), func(T(10.0))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.0))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.0))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0))); + } + + void testFractions(TruncFunc func) { + EXPECT_FP_EQ(T(0.0), func(T(0.5))); + EXPECT_FP_EQ(T(-0.0), func(T(-0.5))); + EXPECT_FP_EQ(T(0.0), func(T(0.115))); + EXPECT_FP_EQ(T(-0.0), func(T(-0.115))); + EXPECT_FP_EQ(T(0.0), func(T(0.715))); + EXPECT_FP_EQ(T(-0.0), func(T(-0.715))); + EXPECT_FP_EQ(T(1.0), func(T(1.3))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.3))); + EXPECT_FP_EQ(T(1.0), func(T(1.5))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.5))); + EXPECT_FP_EQ(T(1.0), func(T(1.75))); + EXPECT_FP_EQ(T(-1.0), func(T(-1.75))); + EXPECT_FP_EQ(T(10.0), func(T(10.32))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); + EXPECT_FP_EQ(T(10.0), func(T(10.65))); + EXPECT_FP_EQ(T(-10.0), func(T(-10.65))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); + EXPECT_FP_EQ(T(1234.0), func(T(1234.96))); + EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96))); + } +}; + +#define LIST_TRUNC_TESTS(T, func) \ + using LlvmLibcTruncTest = TruncTest; \ + TEST_F(LlvmLibcTruncTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcTruncTest, RoundedNubmers) { testRoundedNumbers(&func); } \ + TEST_F(LlvmLibcTruncTest, Fractions) { testFractions(&func); } diff --git a/libc/test/src/math/smoke/acosf_test.cpp b/libc/test/src/math/smoke/acosf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/acosf_test.cpp @@ -0,0 +1,43 @@ +//===-- Unittests for acosf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/acosf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcAcosfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acosf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acosf(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acosf(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::acosf(1.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acosf(2.0f)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acosf(-2.0f)); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/acoshf_test.cpp b/libc/test/src/math/smoke/acoshf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/acoshf_test.cpp @@ -0,0 +1,40 @@ +//===-- Unittests for acoshf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/acoshf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits_t = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcAcoshfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acoshf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acoshf(0.0f)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::acoshf(1.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::acoshf(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::acoshf(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/asinf_test.cpp b/libc/test/src/math/smoke/asinf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/asinf_test.cpp @@ -0,0 +1,46 @@ +//===-- Unittests for asinf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/asinf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcAsinfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::asinf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::asinf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, __llvm_libc::asinf(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::asinf(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::asinf(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::asinf(2.0f)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::asinf(-2.0f)); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/asinhf_test.cpp b/libc/test/src/math/smoke/asinhf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/asinhf_test.cpp @@ -0,0 +1,40 @@ +//===-- Unittests for asinhf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/asinhf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits_t = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcAsinhfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::asinhf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::asinhf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, __llvm_libc::asinhf(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::asinhf(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, __llvm_libc::asinhf(neg_inf)); + EXPECT_MATH_ERRNO(0); +} diff --git a/libc/test/src/math/smoke/atanf_test.cpp b/libc/test/src/math/smoke/atanf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/atanf_test.cpp @@ -0,0 +1,40 @@ +//===-- Unittests for atanf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/atanf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcAtanfTest, SpecialNumbers) { + libc_errno = 0; + + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::atanf(aNaN)); + EXPECT_FP_EXCEPTION(0); + EXPECT_MATH_ERRNO(0); + + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::atanf(0.0f)); + EXPECT_FP_EXCEPTION(0); + EXPECT_MATH_ERRNO(0); + + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, __llvm_libc::atanf(-0.0f)); + EXPECT_FP_EXCEPTION(0); + EXPECT_MATH_ERRNO(0); +} diff --git a/libc/test/src/math/smoke/atanhf_test.cpp b/libc/test/src/math/smoke/atanhf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/atanhf_test.cpp @@ -0,0 +1,72 @@ +//===-- Unittests for atanhf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/atanhf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcAtanhfTest, SpecialNumbers) { + libc_errno = 0; + + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::atanhf(aNaN)); + EXPECT_FP_EXCEPTION(0); + EXPECT_MATH_ERRNO(0); + + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::atanhf(0.0f)); + EXPECT_FP_EXCEPTION(0); + EXPECT_MATH_ERRNO(0); + + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, __llvm_libc::atanhf(-0.0f)); + EXPECT_FP_EXCEPTION(0); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_WITH_EXCEPTION(inf, __llvm_libc::atanhf(1.0f), FE_DIVBYZERO); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::atanhf(-1.0f), + FE_DIVBYZERO); + EXPECT_MATH_ERRNO(ERANGE); + + auto bt = FPBits(1.0f); + bt.bits += 1; + + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::atanhf(bt.get_val()), + FE_INVALID); + EXPECT_MATH_ERRNO(EDOM); + + bt.set_sign(true); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::atanhf(bt.get_val()), + FE_INVALID); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::atanhf(2.0f), FE_INVALID); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::atanhf(-2.0f), FE_INVALID); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::atanhf(inf), FE_INVALID); + EXPECT_MATH_ERRNO(EDOM); + + bt.set_sign(true); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::atanhf(neg_inf), FE_INVALID); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/ceil_test.cpp b/libc/test/src/math/smoke/ceil_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ceil_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for ceil ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CeilTest.h" + +#include "src/math/ceil.h" + +LIST_CEIL_TESTS(double, __llvm_libc::ceil) diff --git a/libc/test/src/math/smoke/ceilf_test.cpp b/libc/test/src/math/smoke/ceilf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ceilf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for ceilf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CeilTest.h" + +#include "src/math/ceilf.h" + +LIST_CEIL_TESTS(float, __llvm_libc::ceilf) diff --git a/libc/test/src/math/smoke/ceill_test.cpp b/libc/test/src/math/smoke/ceill_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ceill_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for ceill -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CeilTest.h" + +#include "src/math/ceill.h" + +LIST_CEIL_TESTS(long double, __llvm_libc::ceill) diff --git a/libc/test/src/math/smoke/copysign_test.cpp b/libc/test/src/math/smoke/copysign_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/copysign_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for copysign --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CopySignTest.h" + +#include "src/math/copysign.h" + +LIST_COPYSIGN_TESTS(double, __llvm_libc::copysign) diff --git a/libc/test/src/math/smoke/copysignf_test.cpp b/libc/test/src/math/smoke/copysignf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/copysignf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for copysignf -------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CopySignTest.h" + +#include "src/math/copysignf.h" + +LIST_COPYSIGN_TESTS(float, __llvm_libc::copysignf) diff --git a/libc/test/src/math/smoke/copysignl_test.cpp b/libc/test/src/math/smoke/copysignl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/copysignl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for copysignl -------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CopySignTest.h" + +#include "src/math/copysignl.h" + +LIST_COPYSIGN_TESTS(long double, __llvm_libc::copysignl) diff --git a/libc/test/src/math/smoke/cosf_test.cpp b/libc/test/src/math/smoke/cosf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/cosf_test.cpp @@ -0,0 +1,40 @@ +//===-- Unittests for cosf ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/cosf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcCosfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::cosf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::cosf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::cosf(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::cosf(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::cosf(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/coshf_test.cpp b/libc/test/src/math/smoke/coshf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/coshf_test.cpp @@ -0,0 +1,56 @@ +//===-- Unittests for coshf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/CPP/array.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/coshf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcCoshfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::coshf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::coshf(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::coshf(neg_inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::coshf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::coshf(-0.0f)); + EXPECT_MATH_ERRNO(0); +} + +TEST(LlvmLibcCoshfTest, Overflow) { + libc_errno = 0; + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::coshf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::coshf(float(FPBits(0x42cffff8U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::coshf(float(FPBits(0x42d00008U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); +} diff --git a/libc/test/src/math/smoke/erff_test.cpp b/libc/test/src/math/smoke/erff_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/erff_test.cpp @@ -0,0 +1,28 @@ +//===-- Unittests for erff ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/math/erff.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcErffTest, SpecialNumbers) { + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::erff(aNaN)); + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::erff(inf)); + EXPECT_FP_EQ_ALL_ROUNDING(-1.0f, __llvm_libc::erff(neg_inf)); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::erff(zero)); + EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, __llvm_libc::erff(neg_zero)); +} diff --git a/libc/test/src/math/smoke/exp10_test.cpp b/libc/test/src/math/smoke/exp10_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/exp10_test.cpp @@ -0,0 +1,36 @@ +//===-- Unittests for 10^x ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/exp10.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcExp10Test, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::exp10(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::exp10(inf)); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::exp10(neg_inf)); + EXPECT_FP_EQ_WITH_EXCEPTION(zero, __llvm_libc::exp10(-0x1.0p20), + FE_UNDERFLOW); + EXPECT_FP_EQ_WITH_EXCEPTION(inf, __llvm_libc::exp10(0x1.0p20), FE_OVERFLOW); + EXPECT_FP_EQ_ALL_ROUNDING(1.0, __llvm_libc::exp10(0.0)); + EXPECT_FP_EQ_ALL_ROUNDING(1.0, __llvm_libc::exp10(-0.0)); + + EXPECT_FP_EQ_ALL_ROUNDING(10.0, __llvm_libc::exp10(1.0)); + EXPECT_FP_EQ_ALL_ROUNDING(100.0, __llvm_libc::exp10(2.0)); + EXPECT_FP_EQ_ALL_ROUNDING(1000.0, __llvm_libc::exp10(3.0)); +} diff --git a/libc/test/src/math/smoke/exp10f_test.cpp b/libc/test/src/math/smoke/exp10f_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/exp10f_test.cpp @@ -0,0 +1,56 @@ +//===-- Unittests for exp10f ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/exp10f.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcExp10fTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::exp10f(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::exp10f(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::exp10f(neg_inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::exp10f(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::exp10f(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(10.0f, __llvm_libc::exp10f(1.0f)); + EXPECT_FP_EQ_ALL_ROUNDING(100.0f, __llvm_libc::exp10f(2.0f)); + EXPECT_FP_EQ_ALL_ROUNDING(1000.0f, __llvm_libc::exp10f(3.0f)); +} + +TEST(LlvmLibcExp10fTest, Overflow) { + libc_errno = 0; + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp10f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp10f(float(FPBits(0x43000000U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp10f(float(FPBits(0x43000001U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); +} diff --git a/libc/test/src/math/smoke/exp2_test.cpp b/libc/test/src/math/smoke/exp2_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/exp2_test.cpp @@ -0,0 +1,35 @@ +//===-- Unittests for 2^x -------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/exp2.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcExp2Test, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::exp2(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::exp2(inf)); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::exp2(neg_inf)); + EXPECT_FP_EQ_WITH_EXCEPTION(zero, __llvm_libc::exp2(-0x1.0p20), FE_UNDERFLOW); + EXPECT_FP_EQ_WITH_EXCEPTION(inf, __llvm_libc::exp2(0x1.0p20), FE_OVERFLOW); + EXPECT_FP_EQ_ALL_ROUNDING(1.0, __llvm_libc::exp2(0.0)); + EXPECT_FP_EQ_ALL_ROUNDING(1.0, __llvm_libc::exp2(-0.0)); + EXPECT_FP_EQ_ALL_ROUNDING(2.0, __llvm_libc::exp2(1.0)); + EXPECT_FP_EQ_ALL_ROUNDING(0.5, __llvm_libc::exp2(-1.0)); + EXPECT_FP_EQ_ALL_ROUNDING(4.0, __llvm_libc::exp2(2.0)); + EXPECT_FP_EQ_ALL_ROUNDING(0.25, __llvm_libc::exp2(-2.0)); +} diff --git a/libc/test/src/math/smoke/exp2f_test.cpp b/libc/test/src/math/smoke/exp2f_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/exp2f_test.cpp @@ -0,0 +1,58 @@ +//===-- Unittests for exp2f -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA +#include "src/errno/libc_errno.h" +#include "src/math/exp2f.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcExp2fTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::exp2f(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::exp2f(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::exp2f(neg_inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::exp2f(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::exp2f(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(2.0f, __llvm_libc::exp2f(1.0f)); + EXPECT_FP_EQ_ALL_ROUNDING(0.5f, __llvm_libc::exp2f(-1.0f)); + EXPECT_FP_EQ_ALL_ROUNDING(4.0f, __llvm_libc::exp2f(2.0f)); + EXPECT_FP_EQ_ALL_ROUNDING(0.25f, __llvm_libc::exp2f(-2.0f)); +} + +TEST(LlvmLibcExp2fTest, Overflow) { + libc_errno = 0; + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp2f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp2f(float(FPBits(0x43000000U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp2f(float(FPBits(0x43000001U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); +} diff --git a/libc/test/src/math/smoke/exp_test.cpp b/libc/test/src/math/smoke/exp_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/exp_test.cpp @@ -0,0 +1,31 @@ +//===-- Unittests for exp -------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/exp.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcExpTest, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::exp(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::exp(inf)); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::exp(neg_inf)); + EXPECT_FP_EQ_WITH_EXCEPTION(zero, __llvm_libc::exp(-0x1.0p20), FE_UNDERFLOW); + EXPECT_FP_EQ_WITH_EXCEPTION(inf, __llvm_libc::exp(0x1.0p20), FE_OVERFLOW); + EXPECT_FP_EQ_ALL_ROUNDING(1.0, __llvm_libc::exp(0.0)); + EXPECT_FP_EQ_ALL_ROUNDING(1.0, __llvm_libc::exp(-0.0)); +} diff --git a/libc/test/src/math/smoke/expf_test.cpp b/libc/test/src/math/smoke/expf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/expf_test.cpp @@ -0,0 +1,52 @@ +//===-- Unittests for expf ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/expf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcExpfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::expf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::expf(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::expf(neg_inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::expf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(1.0f, __llvm_libc::expf(-0.0f)); + EXPECT_MATH_ERRNO(0); +} + +TEST(LlvmLibcExpfTest, Overflow) { + libc_errno = 0; + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expf(float(FPBits(0x42cffff8U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expf(float(FPBits(0x42d00008U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); +} diff --git a/libc/test/src/math/smoke/expm1f_test.cpp b/libc/test/src/math/smoke/expm1f_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/expm1f_test.cpp @@ -0,0 +1,52 @@ +//===-- Unittests for expm1f-----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/expm1f.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcExpm1fTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ_ALL_ROUNDING(aNaN, __llvm_libc::expm1f(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(inf, __llvm_libc::expm1f(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(-1.0f, __llvm_libc::expm1f(neg_inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(0.0f, __llvm_libc::expm1f(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, __llvm_libc::expm1f(-0.0f)); + EXPECT_MATH_ERRNO(0); +} + +TEST(LlvmLibcExpm1fTest, Overflow) { + libc_errno = 0; + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expm1f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expm1f(float(FPBits(0x42cffff8U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expm1f(float(FPBits(0x42d00008U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); +} diff --git a/libc/test/src/math/smoke/fabs_test.cpp b/libc/test/src/math/smoke/fabs_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fabs_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fabs ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FAbsTest.h" + +#include "src/math/fabs.h" + +LIST_FABS_TESTS(double, __llvm_libc::fabs) diff --git a/libc/test/src/math/smoke/fabsf_test.cpp b/libc/test/src/math/smoke/fabsf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fabsf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fabsf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FAbsTest.h" + +#include "src/math/fabsf.h" + +LIST_FABS_TESTS(float, __llvm_libc::fabsf) diff --git a/libc/test/src/math/smoke/fabsl_test.cpp b/libc/test/src/math/smoke/fabsl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fabsl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fabsl -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FAbsTest.h" + +#include "src/math/fabsl.h" + +LIST_FABS_TESTS(long double, __llvm_libc::fabsl) diff --git a/libc/test/src/math/smoke/fdim_test.cpp b/libc/test/src/math/smoke/fdim_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fdim_test.cpp @@ -0,0 +1,31 @@ +//===-- Unittests for fdim ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FDimTest.h" + +#include "src/__support/FPUtil/FPBits.h" +#include "src/math/fdim.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +using LlvmLibcFDimTest = FDimTestTemplate; + +TEST_F(LlvmLibcFDimTest, NaNArg_fdim) { test_na_n_arg(&__llvm_libc::fdim); } + +TEST_F(LlvmLibcFDimTest, InfArg_fdim) { test_inf_arg(&__llvm_libc::fdim); } + +TEST_F(LlvmLibcFDimTest, NegInfArg_fdim) { + test_neg_inf_arg(&__llvm_libc::fdim); +} + +TEST_F(LlvmLibcFDimTest, BothZero_fdim) { test_both_zero(&__llvm_libc::fdim); } + +TEST_F(LlvmLibcFDimTest, InDoubleRange_fdim) { + test_in_range(&__llvm_libc::fdim); +} diff --git a/libc/test/src/math/smoke/fdimf_test.cpp b/libc/test/src/math/smoke/fdimf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fdimf_test.cpp @@ -0,0 +1,33 @@ +//===-- Unittests for fdimf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FDimTest.h" + +#include "src/__support/FPUtil/FPBits.h" +#include "src/math/fdimf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +using LlvmLibcFDimTest = FDimTestTemplate; + +TEST_F(LlvmLibcFDimTest, NaNArg_fdimf) { test_na_n_arg(&__llvm_libc::fdimf); } + +TEST_F(LlvmLibcFDimTest, InfArg_fdimf) { test_inf_arg(&__llvm_libc::fdimf); } + +TEST_F(LlvmLibcFDimTest, NegInfArg_fdimf) { + test_neg_inf_arg(&__llvm_libc::fdimf); +} + +TEST_F(LlvmLibcFDimTest, BothZero_fdimf) { + test_both_zero(&__llvm_libc::fdimf); +} + +TEST_F(LlvmLibcFDimTest, InFloatRange_fdimf) { + test_in_range(&__llvm_libc::fdimf); +} diff --git a/libc/test/src/math/smoke/fdiml_test.cpp b/libc/test/src/math/smoke/fdiml_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fdiml_test.cpp @@ -0,0 +1,33 @@ +//===-- Unittests for fdiml -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FDimTest.h" + +#include "src/__support/FPUtil/FPBits.h" +#include "src/math/fdiml.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +using LlvmLibcFDimTest = FDimTestTemplate; + +TEST_F(LlvmLibcFDimTest, NaNArg_fdiml) { test_na_n_arg(&__llvm_libc::fdiml); } + +TEST_F(LlvmLibcFDimTest, InfArg_fdiml) { test_inf_arg(&__llvm_libc::fdiml); } + +TEST_F(LlvmLibcFDimTest, NegInfArg_fdiml) { + test_neg_inf_arg(&__llvm_libc::fdiml); +} + +TEST_F(LlvmLibcFDimTest, BothZero_fdiml) { + test_both_zero(&__llvm_libc::fdiml); +} + +TEST_F(LlvmLibcFDimTest, InLongDoubleRange_fdiml) { + test_in_range(&__llvm_libc::fdiml); +} diff --git a/libc/test/src/math/smoke/floor_test.cpp b/libc/test/src/math/smoke/floor_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/floor_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for floor -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FloorTest.h" + +#include "src/math/floor.h" + +LIST_FLOOR_TESTS(double, __llvm_libc::floor) diff --git a/libc/test/src/math/smoke/floorf_test.cpp b/libc/test/src/math/smoke/floorf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/floorf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for floorf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FloorTest.h" + +#include "src/math/floorf.h" + +LIST_FLOOR_TESTS(float, __llvm_libc::floorf) diff --git a/libc/test/src/math/smoke/floorl_test.cpp b/libc/test/src/math/smoke/floorl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/floorl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for floorl ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FloorTest.h" + +#include "src/math/floorl.h" + +LIST_FLOOR_TESTS(long double, __llvm_libc::floorl) diff --git a/libc/test/src/math/smoke/fma_test.cpp b/libc/test/src/math/smoke/fma_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fma_test.cpp @@ -0,0 +1,17 @@ +//===-- Unittests for fma ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FmaTest.h" + +#include "src/math/fma.h" + +using LlvmLibcFmaTest = FmaTestTemplate; + +TEST_F(LlvmLibcFmaTest, SpecialNumbers) { + test_special_numbers(&__llvm_libc::fma); +} diff --git a/libc/test/src/math/smoke/fmaf_test.cpp b/libc/test/src/math/smoke/fmaf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fmaf_test.cpp @@ -0,0 +1,17 @@ +//===-- Unittests for fmaf ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FmaTest.h" + +#include "src/math/fmaf.h" + +using LlvmLibcFmafTest = FmaTestTemplate; + +TEST_F(LlvmLibcFmafTest, SpecialNumbers) { + test_special_numbers(&__llvm_libc::fmaf); +} diff --git a/libc/test/src/math/smoke/fmax_test.cpp b/libc/test/src/math/smoke/fmax_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fmax_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmax -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#include "FMaxTest.h" + +#include "src/math/fmax.h" + +LIST_FMAX_TESTS(double, __llvm_libc::fmax) diff --git a/libc/test/src/math/smoke/fmaxf_test.cpp b/libc/test/src/math/smoke/fmaxf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fmaxf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmaxf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FMaxTest.h" + +#include "src/math/fmaxf.h" + +LIST_FMAX_TESTS(float, __llvm_libc::fmaxf) diff --git a/libc/test/src/math/smoke/fmaxl_test.cpp b/libc/test/src/math/smoke/fmaxl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fmaxl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmaxl -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FMaxTest.h" + +#include "src/math/fmaxl.h" + +LIST_FMAX_TESTS(long double, __llvm_libc::fmaxl) diff --git a/libc/test/src/math/smoke/fmin_test.cpp b/libc/test/src/math/smoke/fmin_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fmin_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmin -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#include "FMinTest.h" + +#include "src/math/fmin.h" + +LIST_FMIN_TESTS(double, __llvm_libc::fmin) diff --git a/libc/test/src/math/smoke/fminf_test.cpp b/libc/test/src/math/smoke/fminf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fminf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fminf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FMinTest.h" + +#include "src/math/fminf.h" + +LIST_FMIN_TESTS(float, __llvm_libc::fminf) diff --git a/libc/test/src/math/smoke/fminl_test.cpp b/libc/test/src/math/smoke/fminl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fminl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fminl -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FMinTest.h" + +#include "src/math/fminl.h" + +LIST_FMIN_TESTS(long double, __llvm_libc::fminl) diff --git a/libc/test/src/math/smoke/fmod_test.cpp b/libc/test/src/math/smoke/fmod_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fmod_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmod ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FModTest.h" + +#include "src/math/fmod.h" + +LIST_FMOD_TESTS(double, __llvm_libc::fmod) diff --git a/libc/test/src/math/smoke/fmodf_test.cpp b/libc/test/src/math/smoke/fmodf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/fmodf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmodf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FModTest.h" + +#include "src/math/fmodf.h" + +LIST_FMOD_TESTS(float, __llvm_libc::fmodf) diff --git a/libc/test/src/math/smoke/frexp_test.cpp b/libc/test/src/math/smoke/frexp_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/frexp_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for frexp -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FrexpTest.h" + +#include "src/math/frexp.h" + +LIST_FREXP_TESTS(double, __llvm_libc::frexp) diff --git a/libc/test/src/math/smoke/frexpf_test.cpp b/libc/test/src/math/smoke/frexpf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/frexpf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for frexpf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FrexpTest.h" + +#include "src/math/frexpf.h" + +LIST_FREXP_TESTS(float, __llvm_libc::frexpf) diff --git a/libc/test/src/math/smoke/frexpl_test.cpp b/libc/test/src/math/smoke/frexpl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/frexpl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for frexpl ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FrexpTest.h" + +#include "src/math/frexpl.h" + +LIST_FREXP_TESTS(long double, __llvm_libc::frexpl) diff --git a/libc/test/src/math/smoke/generic_sqrt_test.cpp b/libc/test/src/math/smoke/generic_sqrt_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/generic_sqrt_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for generic implementation of sqrt ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SqrtTest.h" + +#include "src/__support/FPUtil/generic/sqrt.h" + +LIST_SQRT_TESTS(double, __llvm_libc::fputil::sqrt) diff --git a/libc/test/src/math/smoke/generic_sqrtf_test.cpp b/libc/test/src/math/smoke/generic_sqrtf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/generic_sqrtf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for generic implementation of sqrtf----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SqrtTest.h" + +#include "src/__support/FPUtil/generic/sqrt.h" + +LIST_SQRT_TESTS(float, __llvm_libc::fputil::sqrt) diff --git a/libc/test/src/math/smoke/generic_sqrtl_test.cpp b/libc/test/src/math/smoke/generic_sqrtl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/generic_sqrtl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for generic implementation of sqrtl----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SqrtTest.h" + +#include "src/__support/FPUtil/generic/sqrt.h" + +LIST_SQRT_TESTS(long double, __llvm_libc::fputil::sqrt) diff --git a/libc/test/src/math/smoke/hypot_test.cpp b/libc/test/src/math/smoke/hypot_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/hypot_test.cpp @@ -0,0 +1,17 @@ +//===-- Unittests for hypot -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "HypotTest.h" + +#include "src/math/hypot.h" + +using LlvmLibcHypotTest = HypotTestTemplate; + +TEST_F(LlvmLibcHypotTest, SpecialNumbers) { + test_special_numbers(&__llvm_libc::hypot); +} diff --git a/libc/test/src/math/smoke/hypotf_test.cpp b/libc/test/src/math/smoke/hypotf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/hypotf_test.cpp @@ -0,0 +1,17 @@ +//===-- Unittests for hypotf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "HypotTest.h" + +#include "src/math/hypotf.h" + +using LlvmLibcHypotfTest = HypotTestTemplate; + +TEST_F(LlvmLibcHypotfTest, SpecialNumbers) { + test_special_numbers(&__llvm_libc::hypotf); +} diff --git a/libc/test/src/math/smoke/ilogb_test.cpp b/libc/test/src/math/smoke/ilogb_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ilogb_test.cpp @@ -0,0 +1,36 @@ +//===-- Unittests for ilogb -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ILogbTest.h" + +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/math/ilogb.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogb) { + test_special_numbers(&__llvm_libc::ilogb); +} + +TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogb) { + test_powers_of_two(&__llvm_libc::ilogb); +} + +TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogb) { + test_some_integers(&__llvm_libc::ilogb); +} + +TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogb) { + test_subnormal_range(&__llvm_libc::ilogb); +} + +TEST_F(LlvmLibcILogbTest, NormalRange_ilogb) { + test_normal_range(&__llvm_libc::ilogb); +} diff --git a/libc/test/src/math/smoke/ilogbf_test.cpp b/libc/test/src/math/smoke/ilogbf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ilogbf_test.cpp @@ -0,0 +1,36 @@ +//===-- Unittests for ilogbf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ILogbTest.h" + +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/math/ilogbf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogbf) { + test_special_numbers(&__llvm_libc::ilogbf); +} + +TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogbf) { + test_powers_of_two(&__llvm_libc::ilogbf); +} + +TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogbf) { + test_some_integers(&__llvm_libc::ilogbf); +} + +TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogbf) { + test_subnormal_range(&__llvm_libc::ilogbf); +} + +TEST_F(LlvmLibcILogbTest, NormalRange_ilogbf) { + test_normal_range(&__llvm_libc::ilogbf); +} diff --git a/libc/test/src/math/smoke/ilogbl_test.cpp b/libc/test/src/math/smoke/ilogbl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ilogbl_test.cpp @@ -0,0 +1,36 @@ +//===-- Unittests for ilogbl ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ILogbTest.h" + +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/math/ilogbl.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogbl) { + test_special_numbers(&__llvm_libc::ilogbl); +} + +TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogbl) { + test_powers_of_two(&__llvm_libc::ilogbl); +} + +TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogbl) { + test_some_integers(&__llvm_libc::ilogbl); +} + +TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogbl) { + test_subnormal_range(&__llvm_libc::ilogbl); +} + +TEST_F(LlvmLibcILogbTest, NormalRange_ilogbl) { + test_normal_range(&__llvm_libc::ilogbl); +} diff --git a/libc/test/src/math/smoke/ldexp_test.cpp b/libc/test/src/math/smoke/ldexp_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ldexp_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for ldexp -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "LdExpTest.h" + +#include "src/math/ldexp.h" + +LIST_LDEXP_TESTS(double, __llvm_libc::ldexp) diff --git a/libc/test/src/math/smoke/ldexpf_test.cpp b/libc/test/src/math/smoke/ldexpf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ldexpf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for ldexpf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "LdExpTest.h" + +#include "src/math/ldexpf.h" + +LIST_LDEXP_TESTS(float, __llvm_libc::ldexpf) diff --git a/libc/test/src/math/smoke/ldexpl_test.cpp b/libc/test/src/math/smoke/ldexpl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/ldexpl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for ldexpl ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "LdExpTest.h" + +#include "src/math/ldexpl.h" + +LIST_LDEXP_TESTS(long double, __llvm_libc::ldexpl) diff --git a/libc/test/src/math/smoke/llrint_test.cpp b/libc/test/src/math/smoke/llrint_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/llrint_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for llrint ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/llrint.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(double, long long, __llvm_libc::llrint) diff --git a/libc/test/src/math/smoke/llrintf_test.cpp b/libc/test/src/math/smoke/llrintf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/llrintf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for llrintf ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/llrintf.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float, long long, __llvm_libc::llrintf) diff --git a/libc/test/src/math/smoke/llrintl_test.cpp b/libc/test/src/math/smoke/llrintl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/llrintl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for llrintl ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/llrintl.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(long double, long long, + __llvm_libc::llrintl) diff --git a/libc/test/src/math/smoke/llround_test.cpp b/libc/test/src/math/smoke/llround_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/llround_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for llround ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/llround.h" + +LIST_ROUND_TO_INTEGER_TESTS(double, long long, __llvm_libc::llround) diff --git a/libc/test/src/math/smoke/llroundf_test.cpp b/libc/test/src/math/smoke/llroundf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/llroundf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for llroundf --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/llroundf.h" + +LIST_ROUND_TO_INTEGER_TESTS(float, long long, __llvm_libc::llroundf) diff --git a/libc/test/src/math/smoke/llroundl_test.cpp b/libc/test/src/math/smoke/llroundl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/llroundl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for llroundl --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/llroundl.h" + +LIST_ROUND_TO_INTEGER_TESTS(long double, long long, __llvm_libc::llroundl) diff --git a/libc/test/src/math/smoke/log10_test.cpp b/libc/test/src/math/smoke/log10_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/log10_test.cpp @@ -0,0 +1,36 @@ +//===-- Unittests for log10 -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/log10.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcLog10Test, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::log10(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::log10(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log10(neg_inf), FE_INVALID); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log10(0.0), FE_DIVBYZERO); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log10(-0.0), FE_DIVBYZERO); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log10(-1.0), FE_INVALID); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::log10(1.0)); + + double x = 1.0; + for (int i = 0; i < 11; ++i, x *= 10.0) { + EXPECT_FP_EQ_ALL_ROUNDING(static_cast(i), __llvm_libc::log10(x)); + } +} diff --git a/libc/test/src/math/smoke/log10f_test.cpp b/libc/test/src/math/smoke/log10f_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/log10f_test.cpp @@ -0,0 +1,34 @@ +//===-- Unittests for log10f ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/math/log10f.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcLog10fTest, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::log10f(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::log10f(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log10f(neg_inf), FE_INVALID); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log10f(0.0f), FE_DIVBYZERO); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log10f(-0.0f), + FE_DIVBYZERO); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log10f(-1.0f), FE_INVALID); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::log10f(1.0f)); + + float x = 1.0f; + for (int i = 0; i < 11; ++i, x *= 10.0f) { + EXPECT_FP_EQ_ALL_ROUNDING(static_cast(i), __llvm_libc::log10f(x)); + } +} diff --git a/libc/test/src/math/smoke/log1p_test.cpp b/libc/test/src/math/smoke/log1p_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/log1p_test.cpp @@ -0,0 +1,31 @@ +//===-- Unittests for log1p -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/log1p.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcLog1pTest, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::log1p(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::log1p(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log1p(neg_inf), FE_INVALID); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log1p(-2.0), FE_INVALID); + EXPECT_FP_EQ(zero, __llvm_libc::log1p(0.0)); + EXPECT_FP_EQ(neg_zero, __llvm_libc::log1p(-0.0)); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log1p(-1.0), FE_DIVBYZERO); +} diff --git a/libc/test/src/math/smoke/log1pf_test.cpp b/libc/test/src/math/smoke/log1pf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/log1pf_test.cpp @@ -0,0 +1,29 @@ +//===-- Unittests for log1pf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/log1pf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibclog1pfTest, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::log1pf(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::log1pf(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log1pf(neg_inf), FE_INVALID); + EXPECT_FP_EQ(zero, __llvm_libc::log1pf(0.0f)); + EXPECT_FP_EQ(neg_zero, __llvm_libc::log1pf(-0.0f)); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log1pf(-1.0f), + FE_DIVBYZERO); +} diff --git a/libc/test/src/math/smoke/log2_test.cpp b/libc/test/src/math/smoke/log2_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/log2_test.cpp @@ -0,0 +1,31 @@ +//===-- Unittests for log2 ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/log2.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcLog2Test, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::log2(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::log2(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log2(neg_inf), FE_INVALID); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log2(0.0), FE_DIVBYZERO); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log2(-0.0), FE_DIVBYZERO); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log2(-1.0), FE_INVALID); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::log2(1.0)); +} diff --git a/libc/test/src/math/smoke/log2f_test.cpp b/libc/test/src/math/smoke/log2f_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/log2f_test.cpp @@ -0,0 +1,28 @@ +//===-- Unittests for log2f -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/log2f.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcLog2fTest, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::log2f(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::log2f(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log2f(neg_inf), FE_INVALID); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log2f(0.0f), FE_DIVBYZERO); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log2f(-0.0f), FE_DIVBYZERO); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log2f(-1.0f), FE_INVALID); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::log2f(1.0f)); +} diff --git a/libc/test/src/math/smoke/log_test.cpp b/libc/test/src/math/smoke/log_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/log_test.cpp @@ -0,0 +1,31 @@ +//===-- Unittests for log -------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/log.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using __llvm_libc::testing::tlog; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcLogTest, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::log(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::log(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log(neg_inf), FE_INVALID); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log(0.0), FE_DIVBYZERO); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::log(-0.0), FE_DIVBYZERO); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::log(-1.0), FE_INVALID); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::log(1.0)); +} diff --git a/libc/test/src/math/smoke/logb_test.cpp b/libc/test/src/math/smoke/logb_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/logb_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for logb ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "LogbTest.h" + +#include "src/math/logb.h" + +LIST_LOGB_TESTS(double, __llvm_libc::logb) diff --git a/libc/test/src/math/smoke/logbf_test.cpp b/libc/test/src/math/smoke/logbf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/logbf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for logbf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "LogbTest.h" + +#include "src/math/logbf.h" + +LIST_LOGB_TESTS(float, __llvm_libc::logbf) diff --git a/libc/test/src/math/smoke/logbl_test.cpp b/libc/test/src/math/smoke/logbl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/logbl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for logbl -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "LogbTest.h" + +#include "src/math/logbl.h" + +LIST_LOGB_TESTS(long double, __llvm_libc::logbl) diff --git a/libc/test/src/math/smoke/logf_test.cpp b/libc/test/src/math/smoke/logf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/logf_test.cpp @@ -0,0 +1,27 @@ +//===-- Unittests for logf-----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/math/logf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcLogfTest, SpecialNumbers) { + EXPECT_FP_EQ(aNaN, __llvm_libc::logf(aNaN)); + EXPECT_FP_EQ(inf, __llvm_libc::logf(inf)); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::logf(neg_inf), FE_INVALID); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::logf(0.0f), FE_DIVBYZERO); + EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, __llvm_libc::logf(-0.0f), FE_DIVBYZERO); + EXPECT_FP_IS_NAN_WITH_EXCEPTION(__llvm_libc::logf(-1.0f), FE_INVALID); + EXPECT_FP_EQ_ALL_ROUNDING(zero, __llvm_libc::logf(1.0f)); +} diff --git a/libc/test/src/math/smoke/lrint_test.cpp b/libc/test/src/math/smoke/lrint_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/lrint_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for lrint -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/lrint.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(double, long, __llvm_libc::lrint) diff --git a/libc/test/src/math/smoke/lrintf_test.cpp b/libc/test/src/math/smoke/lrintf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/lrintf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for lrintf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/lrintf.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float, long, __llvm_libc::lrintf) diff --git a/libc/test/src/math/smoke/lrintl_test.cpp b/libc/test/src/math/smoke/lrintl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/lrintl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for lrintl ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/lrintl.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(long double, long, __llvm_libc::lrintl) diff --git a/libc/test/src/math/smoke/lround_test.cpp b/libc/test/src/math/smoke/lround_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/lround_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for lround ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/lround.h" + +LIST_ROUND_TO_INTEGER_TESTS(double, long, __llvm_libc::lround) diff --git a/libc/test/src/math/smoke/lroundf_test.cpp b/libc/test/src/math/smoke/lroundf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/lroundf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for lroundf ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/lroundf.h" + +LIST_ROUND_TO_INTEGER_TESTS(float, long, __llvm_libc::lroundf) diff --git a/libc/test/src/math/smoke/lroundl_test.cpp b/libc/test/src/math/smoke/lroundl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/lroundl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for lroundl ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundToIntegerTest.h" + +#include "src/math/lroundl.h" + +LIST_ROUND_TO_INTEGER_TESTS(long double, long, __llvm_libc::lroundl) diff --git a/libc/test/src/math/smoke/modf_test.cpp b/libc/test/src/math/smoke/modf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/modf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for modf ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ModfTest.h" + +#include "src/math/modf.h" + +LIST_MODF_TESTS(double, __llvm_libc::modf) diff --git a/libc/test/src/math/smoke/modff_test.cpp b/libc/test/src/math/smoke/modff_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/modff_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for modff -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ModfTest.h" + +#include "src/math/modff.h" + +LIST_MODF_TESTS(float, __llvm_libc::modff) diff --git a/libc/test/src/math/smoke/modfl_test.cpp b/libc/test/src/math/smoke/modfl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/modfl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for modfl -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ModfTest.h" + +#include "src/math/modfl.h" + +LIST_MODF_TESTS(long double, __llvm_libc::modfl) diff --git a/libc/test/src/math/smoke/nextafter_test.cpp b/libc/test/src/math/smoke/nextafter_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/nextafter_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for nextafter -------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "NextAfterTest.h" + +#include "src/math/nextafter.h" + +LIST_NEXTAFTER_TESTS(double, __llvm_libc::nextafter) diff --git a/libc/test/src/math/smoke/nextafterf_test.cpp b/libc/test/src/math/smoke/nextafterf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/nextafterf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for nextafterf ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "NextAfterTest.h" + +#include "src/math/nextafterf.h" + +LIST_NEXTAFTER_TESTS(float, __llvm_libc::nextafterf) diff --git a/libc/test/src/math/smoke/nextafterl_test.cpp b/libc/test/src/math/smoke/nextafterl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/nextafterl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for nextafterl ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "NextAfterTest.h" + +#include "src/math/nextafterl.h" + +LIST_NEXTAFTER_TESTS(long double, __llvm_libc::nextafterl) diff --git a/libc/test/src/math/smoke/remquo_test.cpp b/libc/test/src/math/smoke/remquo_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/remquo_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for remquo ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RemQuoTest.h" + +#include "src/math/remquo.h" + +LIST_REMQUO_TESTS(double, __llvm_libc::remquo) diff --git a/libc/test/src/math/smoke/remquof_test.cpp b/libc/test/src/math/smoke/remquof_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/remquof_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for remquof ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RemQuoTest.h" + +#include "src/math/remquof.h" + +LIST_REMQUO_TESTS(float, __llvm_libc::remquof) diff --git a/libc/test/src/math/smoke/remquol_test.cpp b/libc/test/src/math/smoke/remquol_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/remquol_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for remquol ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RemQuoTest.h" + +#include "src/math/remquol.h" + +LIST_REMQUO_TESTS(long double, __llvm_libc::remquol) diff --git a/libc/test/src/math/smoke/rint_test.cpp b/libc/test/src/math/smoke/rint_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/rint_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for rint ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RIntTest.h" + +#include "src/math/rint.h" + +LIST_RINT_TESTS(double, __llvm_libc::rint) diff --git a/libc/test/src/math/smoke/rintf_test.cpp b/libc/test/src/math/smoke/rintf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/rintf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for rintf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RIntTest.h" + +#include "src/math/rintf.h" + +LIST_RINT_TESTS(float, __llvm_libc::rintf) diff --git a/libc/test/src/math/smoke/rintl_test.cpp b/libc/test/src/math/smoke/rintl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/rintl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for rintl -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RIntTest.h" + +#include "src/math/rintl.h" + +LIST_RINT_TESTS(long double, __llvm_libc::rintl) diff --git a/libc/test/src/math/smoke/round_test.cpp b/libc/test/src/math/smoke/round_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/round_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for round -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundTest.h" + +#include "src/math/round.h" + +LIST_ROUND_TESTS(double, __llvm_libc::round) diff --git a/libc/test/src/math/smoke/roundf_test.cpp b/libc/test/src/math/smoke/roundf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/roundf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for roundf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundTest.h" + +#include "src/math/roundf.h" + +LIST_ROUND_TESTS(float, __llvm_libc::roundf) diff --git a/libc/test/src/math/smoke/roundl_test.cpp b/libc/test/src/math/smoke/roundl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/roundl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for roundl ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RoundTest.h" + +#include "src/math/roundl.h" + +LIST_ROUND_TESTS(long double, __llvm_libc::roundl) diff --git a/libc/test/src/math/smoke/scalbn_test.cpp b/libc/test/src/math/smoke/scalbn_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/scalbn_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for scalbn ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ScalbnTest.h" + +#include "src/math/scalbn.h" + +LIST_SCALBN_TESTS(double, __llvm_libc::scalbn) diff --git a/libc/test/src/math/smoke/scalbnf_test.cpp b/libc/test/src/math/smoke/scalbnf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/scalbnf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for scalbnf ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ScalbnTest.h" + +#include "src/math/scalbnf.h" + +LIST_SCALBN_TESTS(float, __llvm_libc::scalbnf) diff --git a/libc/test/src/math/smoke/scalbnl_test.cpp b/libc/test/src/math/smoke/scalbnl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/scalbnl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for scalbnl ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ScalbnTest.h" + +#include "src/math/scalbnl.h" + +LIST_SCALBN_TESTS(long double, __llvm_libc::scalbnl) diff --git a/libc/test/src/math/smoke/sincosf_test.cpp b/libc/test/src/math/smoke/sincosf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/sincosf_test.cpp @@ -0,0 +1,51 @@ +//===-- Unittests for sincosf ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/sincosf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcSinCosfTest, SpecialNumbers) { + libc_errno = 0; + float sin, cos; + + __llvm_libc::sincosf(aNaN, &sin, &cos); + EXPECT_FP_EQ(aNaN, cos); + EXPECT_FP_EQ(aNaN, sin); + EXPECT_MATH_ERRNO(0); + + __llvm_libc::sincosf(0.0f, &sin, &cos); + EXPECT_FP_EQ(1.0f, cos); + EXPECT_FP_EQ(0.0f, sin); + EXPECT_MATH_ERRNO(0); + + __llvm_libc::sincosf(-0.0f, &sin, &cos); + EXPECT_FP_EQ(1.0f, cos); + EXPECT_FP_EQ(-0.0f, sin); + EXPECT_MATH_ERRNO(0); + + __llvm_libc::sincosf(inf, &sin, &cos); + EXPECT_FP_EQ(aNaN, cos); + EXPECT_FP_EQ(aNaN, sin); + EXPECT_MATH_ERRNO(EDOM); + + __llvm_libc::sincosf(neg_inf, &sin, &cos); + EXPECT_FP_EQ(aNaN, cos); + EXPECT_FP_EQ(aNaN, sin); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/sinf_test.cpp b/libc/test/src/math/smoke/sinf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/sinf_test.cpp @@ -0,0 +1,40 @@ +//===-- Unittests for sinf ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/sinf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcSinfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(0.0f, __llvm_libc::sinf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(-0.0f, __llvm_libc::sinf(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/sinhf_test.cpp b/libc/test/src/math/smoke/sinhf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/sinhf_test.cpp @@ -0,0 +1,67 @@ +//===-- Unittests for sinhf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/CPP/array.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/sinhf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcSinhfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ(aNaN, __llvm_libc::sinhf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(0.0f, __llvm_libc::sinhf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(-0.0f, __llvm_libc::sinhf(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(inf, __llvm_libc::sinhf(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(neg_inf, __llvm_libc::sinhf(neg_inf)); + EXPECT_MATH_ERRNO(0); +} + +// For small values, sinh(x) is x. +TEST(LlvmLibcSinhfTest, SmallValues) { + float x = float(FPBits(uint32_t(0x17800000))); + float result = __llvm_libc::sinhf(x); + EXPECT_FP_EQ(x, result); + + x = float(FPBits(uint32_t(0x00400000))); + result = __llvm_libc::sinhf(x); + EXPECT_FP_EQ(x, result); +} + +TEST(LlvmLibcSinhfTest, Overflow) { + libc_errno = 0; + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::sinhf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::sinhf(float(FPBits(0x42cffff8U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); + + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::sinhf(float(FPBits(0x42d00008U))), FE_OVERFLOW); + EXPECT_MATH_ERRNO(ERANGE); +} diff --git a/libc/test/src/math/smoke/sqrt_test.cpp b/libc/test/src/math/smoke/sqrt_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/sqrt_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for sqrt ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SqrtTest.h" + +#include "src/math/sqrt.h" + +LIST_SQRT_TESTS(double, __llvm_libc::sqrt) diff --git a/libc/test/src/math/smoke/sqrtf_test.cpp b/libc/test/src/math/smoke/sqrtf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/sqrtf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for sqrtf------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SqrtTest.h" + +#include "src/math/sqrtf.h" + +LIST_SQRT_TESTS(float, __llvm_libc::sqrtf) diff --git a/libc/test/src/math/smoke/sqrtl_test.cpp b/libc/test/src/math/smoke/sqrtl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/sqrtl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for sqrtl------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "SqrtTest.h" + +#include "src/math/sqrtl.h" + +LIST_SQRT_TESTS(long double, __llvm_libc::sqrtl) diff --git a/libc/test/src/math/smoke/tanf_test.cpp b/libc/test/src/math/smoke/tanf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/tanf_test.cpp @@ -0,0 +1,40 @@ +//===-- Unittests for tanf ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/tanf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcTanfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ(aNaN, __llvm_libc::tanf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(0.0f, __llvm_libc::tanf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(-0.0f, __llvm_libc::tanf(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(aNaN, __llvm_libc::tanf(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ(aNaN, __llvm_libc::tanf(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/smoke/tanhf_test.cpp b/libc/test/src/math/smoke/tanhf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/tanhf_test.cpp @@ -0,0 +1,40 @@ +//===-- Unittests for tanhf -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/FPBits.h" +#include "src/errno/libc_errno.h" +#include "src/math/tanhf.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +DECLARE_SPECIAL_CONSTANTS(float) + +TEST(LlvmLibcTanhfTest, SpecialNumbers) { + libc_errno = 0; + + EXPECT_FP_EQ(aNaN, __llvm_libc::tanhf(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(0.0f, __llvm_libc::tanhf(0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(-0.0f, __llvm_libc::tanhf(-0.0f)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(1.0f, __llvm_libc::tanhf(inf)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(-1.0f, __llvm_libc::tanhf(neg_inf)); + EXPECT_MATH_ERRNO(0); +} diff --git a/libc/test/src/math/smoke/trunc_test.cpp b/libc/test/src/math/smoke/trunc_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/trunc_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for trunc -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "TruncTest.h" + +#include "src/math/trunc.h" + +LIST_TRUNC_TESTS(double, __llvm_libc::trunc) diff --git a/libc/test/src/math/smoke/truncf_test.cpp b/libc/test/src/math/smoke/truncf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/truncf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for truncf ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "TruncTest.h" + +#include "src/math/truncf.h" + +LIST_TRUNC_TESTS(float, __llvm_libc::truncf) diff --git a/libc/test/src/math/smoke/truncl_test.cpp b/libc/test/src/math/smoke/truncl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/smoke/truncl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for truncl ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "TruncTest.h" + +#include "src/math/truncl.h" + +LIST_TRUNC_TESTS(long double, __llvm_libc::truncl)