diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -3,7 +3,6 @@ HDRS FEnvImpl.h DEPENDS - libc.include.errno libc.include.fenv libc.include.math libc.src.__support.macros.attributes @@ -52,7 +51,6 @@ libc.src.__support.CPP.type_traits libc.src.__support.common libc.include.math - libc.include.errno libc.src.errno.errno ) @@ -80,7 +78,6 @@ libc.src.__support.common libc.src.__support.macros.optimization libc.include.math - libc.include.errno libc.src.errno.errno ) diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h --- a/libc/src/__support/FPUtil/FEnvImpl.h +++ b/libc/src/__support/FPUtil/FEnvImpl.h @@ -11,8 +11,8 @@ #include "src/__support/macros/attributes.h" // LIBC_INLINE #include "src/__support/macros/properties/architectures.h" +#include "src/errno/libc_errno.h" -#include #include #include @@ -71,7 +71,7 @@ LIBC_INLINE void set_errno_if_required(int err) { if (math_errhandling & MATH_ERRNO) - errno = err; + libc_errno = err; } } // namespace __llvm_libc::fputil diff --git a/libc/src/__support/FPUtil/NearestIntegerOperations.h b/libc/src/__support/FPUtil/NearestIntegerOperations.h --- a/libc/src/__support/FPUtil/NearestIntegerOperations.h +++ b/libc/src/__support/FPUtil/NearestIntegerOperations.h @@ -15,7 +15,6 @@ #include "src/__support/CPP/type_traits.h" #include "src/__support/common.h" -#include #include namespace __llvm_libc { @@ -238,10 +237,8 @@ constexpr I INTEGER_MAX = -(INTEGER_MIN + 1); FPBits bits(x); auto set_domain_error_and_raise_invalid = []() { - if (math_errhandling & MATH_ERRNO) - errno = EDOM; - if (math_errhandling & MATH_ERREXCEPT) - raise_except(FE_INVALID); + set_errno_if_required(EDOM); + raise_except_if_required(FE_INVALID); }; if (bits.is_inf_or_nan()) { diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -774,6 +774,7 @@ HDRS ../log10.h DEPENDS + libc.src.__support.FPUtil.fenv_impl libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.multiply_add libc.src.__support.FPUtil.double_double diff --git a/libc/src/math/generic/acosf.cpp b/libc/src/math/generic/acosf.cpp --- a/libc/src/math/generic/acosf.cpp +++ b/libc/src/math/generic/acosf.cpp @@ -79,8 +79,7 @@ fputil::set_errno_if_required(EDOM); fputil::raise_except_if_required(FE_INVALID); } - return x + - FPBits::build_nan(1 << (fputil::MantissaWidth::VALUE - 1)); + return x + FPBits::build_quiet_nan(0); } // When 0.5 < |x| <= 1, we perform range reduction as follow: diff --git a/libc/src/math/generic/acoshf.cpp b/libc/src/math/generic/acoshf.cpp --- a/libc/src/math/generic/acoshf.cpp +++ b/libc/src/math/generic/acoshf.cpp @@ -25,7 +25,8 @@ if (LIBC_UNLIKELY(x < 1.0f)) { // x < 1. - fputil::set_except(FE_INVALID); + fputil::set_errno_if_required(EDOM); + fputil::raise_except_if_required(FE_INVALID); return FPBits_t::build_quiet_nan(0); } diff --git a/libc/src/math/generic/atanhf.cpp b/libc/src/math/generic/atanhf.cpp --- a/libc/src/math/generic/atanhf.cpp +++ b/libc/src/math/generic/atanhf.cpp @@ -24,15 +24,15 @@ if (xbits.is_nan()) { return x; } - // |x| == 0 + // |x| == 1.0 if (x_abs == 0x3F80'0000U) { - fputil::set_except(FE_DIVBYZERO); - return with_errno(FPBits::inf(sign).get_val(), ERANGE); + fputil::set_errno_if_required(ERANGE); + fputil::raise_except_if_required(FE_DIVBYZERO); + return FPBits::inf(sign).get_val(); } else { - fputil::set_except(FE_INVALID); - return with_errno( - FPBits::build_nan(1 << (fputil::MantissaWidth::VALUE - 1)), - EDOM); + fputil::set_errno_if_required(EDOM); + fputil::raise_except_if_required(FE_INVALID); + return FPBits::build_quiet_nan(0); } } diff --git a/libc/src/math/generic/cosf.cpp b/libc/src/math/generic/cosf.cpp --- a/libc/src/math/generic/cosf.cpp +++ b/libc/src/math/generic/cosf.cpp @@ -117,8 +117,7 @@ fputil::set_errno_if_required(EDOM); fputil::raise_except_if_required(FE_INVALID); } - return x + - FPBits::build_nan(1 << (fputil::MantissaWidth::VALUE - 1)); + return x + FPBits::build_quiet_nan(0); } // Combine the results with the sine of sum formula: diff --git a/libc/src/math/generic/log10.cpp b/libc/src/math/generic/log10.cpp --- a/libc/src/math/generic/log10.cpp +++ b/libc/src/math/generic/log10.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/math/log10.h" +#include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/double_double.h" #include "src/__support/FPUtil/dyadic_float.h" @@ -953,9 +954,13 @@ xbits.uintval() > FPBits_t::MAX_NORMAL)) { if (xbits.is_zero()) { // return -Inf and raise FE_DIVBYZERO. - return -1.0 / 0.0; + fputil::set_errno_if_required(ERANGE); + fputil::raise_except_if_required(FE_DIVBYZERO); + return static_cast(FPBits_t::neg_inf()); } if (xbits.get_sign() && !xbits.is_nan()) { + fputil::set_errno_if_required(EDOM); + fputil::raise_except_if_required(FE_INVALID); return FPBits_t::build_quiet_nan(0); } if (xbits.is_inf_or_nan()) { diff --git a/libc/src/math/generic/log10f.cpp b/libc/src/math/generic/log10f.cpp --- a/libc/src/math/generic/log10f.cpp +++ b/libc/src/math/generic/log10f.cpp @@ -152,12 +152,14 @@ if (LIBC_UNLIKELY(x_u < FPBits::MIN_NORMAL || x_u > FPBits::MAX_NORMAL)) { if (xbits.is_zero()) { // Return -inf and raise FE_DIVBYZERO - fputil::raise_except(FE_DIVBYZERO); + fputil::set_errno_if_required(ERANGE); + fputil::raise_except_if_required(FE_DIVBYZERO); return static_cast(FPBits::neg_inf()); } if (xbits.get_sign() && !xbits.is_nan()) { // Return NaN and raise FE_INVALID - fputil::raise_except(FE_INVALID); + fputil::set_errno_if_required(EDOM); + fputil::raise_except_if_required(FE_INVALID); return FPBits::build_quiet_nan(0); } if (xbits.is_inf_or_nan()) { diff --git a/libc/src/math/generic/log1pf.cpp b/libc/src/math/generic/log1pf.cpp --- a/libc/src/math/generic/log1pf.cpp +++ b/libc/src/math/generic/log1pf.cpp @@ -45,7 +45,8 @@ if (LIBC_UNLIKELY(x_u > FPBits::MAX_NORMAL)) { if (xbits.get_sign() && !xbits.is_nan()) { - fputil::raise_except(FE_INVALID); + fputil::set_errno_if_required(EDOM); + fputil::raise_except_if_required(FE_INVALID); return fputil::FPBits::build_quiet_nan(0); } return static_cast(x); @@ -103,7 +104,8 @@ case 0xbd1d20afU: // x = -0x1.3a415ep-5f return fputil::round_result_slightly_up(-0x1.407112p-5f); case 0xbf800000U: // x = -1.0 - fputil::raise_except(FE_DIVBYZERO); + fputil::set_errno_if_required(ERANGE); + fputil::raise_except_if_required(FE_DIVBYZERO); return static_cast(fputil::FPBits::neg_inf()); #ifndef LIBC_TARGET_CPU_HAS_FMA case 0x4cc1c80bU: // x = 0x1.839016p+26f diff --git a/libc/src/math/generic/log2f.cpp b/libc/src/math/generic/log2f.cpp --- a/libc/src/math/generic/log2f.cpp +++ b/libc/src/math/generic/log2f.cpp @@ -121,10 +121,12 @@ // Exceptional inputs. if (LIBC_UNLIKELY(x_u < FPBits::MIN_NORMAL || x_u > FPBits::MAX_NORMAL)) { if (xbits.is_zero()) { - fputil::raise_except(FE_DIVBYZERO); + fputil::set_errno_if_required(ERANGE); + fputil::raise_except_if_required(FE_DIVBYZERO); return static_cast(FPBits::neg_inf()); } if (xbits.get_sign() && !xbits.is_nan()) { + fputil::set_errno_if_required(EDOM); fputil::raise_except(FE_INVALID); return FPBits::build_quiet_nan(0); } diff --git a/libc/src/math/generic/logf.cpp b/libc/src/math/generic/logf.cpp --- a/libc/src/math/generic/logf.cpp +++ b/libc/src/math/generic/logf.cpp @@ -96,12 +96,14 @@ if (LIBC_UNLIKELY(x_u < FPBits::MIN_NORMAL || x_u > FPBits::MAX_NORMAL)) { if (xbits.is_zero()) { // Return -inf and raise FE_DIVBYZERO - fputil::raise_except(FE_DIVBYZERO); + fputil::set_errno_if_required(ERANGE); + fputil::raise_except_if_required(FE_DIVBYZERO); return static_cast(FPBits::neg_inf()); } if (xbits.get_sign() && !xbits.is_nan()) { // Return NaN and raise FE_INVALID - fputil::raise_except(FE_INVALID); + fputil::set_errno_if_required(EDOM); + fputil::raise_except_if_required(FE_INVALID); return FPBits::build_quiet_nan(0); } if (xbits.is_inf_or_nan()) { diff --git a/libc/src/math/generic/sinf.cpp b/libc/src/math/generic/sinf.cpp --- a/libc/src/math/generic/sinf.cpp +++ b/libc/src/math/generic/sinf.cpp @@ -138,8 +138,7 @@ fputil::set_errno_if_required(EDOM); fputil::raise_except_if_required(FE_INVALID); } - return x + - FPBits::build_nan(1 << (fputil::MantissaWidth::VALUE - 1)); + return x + FPBits::build_quiet_nan(0); } // Combine the results with the sine of sum formula: diff --git a/libc/src/math/generic/tanf.cpp b/libc/src/math/generic/tanf.cpp --- a/libc/src/math/generic/tanf.cpp +++ b/libc/src/math/generic/tanf.cpp @@ -114,8 +114,7 @@ fputil::set_errno_if_required(EDOM); fputil::raise_except_if_required(FE_INVALID); } - return x + - FPBits::build_nan(1 << (fputil::MantissaWidth::VALUE - 1)); + return x + FPBits::build_quiet_nan(0); } // Other large exceptional values if (auto r = TANF_EXCEPTS.lookup_odd(x_abs, x_sign); diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h --- a/libc/test/UnitTest/FPMatcher.h +++ b/libc/test/UnitTest/FPMatcher.h @@ -14,7 +14,6 @@ #include "test/UnitTest/Test.h" #include "utils/testutils/RoundingModeUtils.h" -#include #include namespace __llvm_libc { @@ -106,8 +105,8 @@ #define EXPECT_MATH_ERRNO(expected) \ do { \ if (math_errhandling & MATH_ERRNO) { \ - int actual = errno; \ - errno = 0; \ + int actual = libc_errno; \ + libc_errno = 0; \ EXPECT_EQ(actual, expected); \ } \ } while (0) @@ -115,8 +114,8 @@ #define ASSERT_MATH_ERRNO(expected) \ do { \ if (math_errhandling & MATH_ERRNO) { \ - int actual = errno; \ - errno = 0; \ + int actual = libc_errno; \ + libc_errno = 0; \ ASSERT_EQ(actual, expected); \ } \ } while (0) 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 @@ -10,7 +10,6 @@ HDRS sdcomp26094.h DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.cosf libc.src.__support.CPP.array @@ -39,7 +38,6 @@ HDRS sdcomp26094.h DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.sinf libc.src.__support.CPP.array @@ -68,7 +66,6 @@ HDRS sdcomp26094.h DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.sincosf libc.src.__support.CPP.array @@ -85,7 +82,6 @@ HDRS sdcomp26094.h DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.tanf libc.src.__support.CPP.array @@ -327,7 +323,6 @@ HDRS RoundToIntegerTest.h DEPENDS - libc.include.errno libc.include.math libc.src.errno.errno libc.src.fenv.feclearexcept @@ -347,7 +342,6 @@ HDRS RoundToIntegerTest.h DEPENDS - libc.include.errno libc.include.math libc.src.errno.errno libc.src.fenv.feclearexcept @@ -367,7 +361,6 @@ HDRS RoundToIntegerTest.h DEPENDS - libc.include.errno libc.include.math libc.src.errno.errno libc.src.fenv.feclearexcept @@ -387,7 +380,6 @@ HDRS RoundToIntegerTest.h DEPENDS - libc.include.errno libc.include.math libc.src.errno.errno libc.src.fenv.feclearexcept @@ -407,7 +399,6 @@ HDRS RoundToIntegerTest.h DEPENDS - libc.include.errno libc.include.math libc.src.errno.errno libc.src.fenv.feclearexcept @@ -427,7 +418,6 @@ HDRS RoundToIntegerTest.h DEPENDS - libc.include.errno libc.include.math libc.src.errno.errno libc.src.fenv.feclearexcept @@ -589,7 +579,6 @@ SRCS expf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.expf @@ -604,7 +593,6 @@ SRCS exp2f_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.exp2f @@ -619,7 +607,6 @@ SRCS exp10f_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.exp10f @@ -1268,7 +1255,6 @@ SRCS expm1f_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.expm1f @@ -1295,7 +1281,6 @@ SRCS logf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.logf @@ -1310,7 +1295,6 @@ SRCS log2f_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.log2f @@ -1325,7 +1309,6 @@ SRCS log10_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.log10 @@ -1342,7 +1325,6 @@ SRCS log10f_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.log10f @@ -1357,7 +1339,6 @@ SRCS log1pf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.include.math libc.src.math.log1pf @@ -1419,7 +1400,6 @@ HDRS sdcomp26094.h DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.coshf libc.src.__support.CPP.array @@ -1436,7 +1416,6 @@ HDRS sdcomp26094.h DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.sinhf libc.src.__support.CPP.array @@ -1463,7 +1442,6 @@ SRCS atanhf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.atanhf libc.src.__support.FPUtil.fp_bits @@ -1477,7 +1455,6 @@ SRCS asinhf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.asinhf libc.src.__support.FPUtil.fp_bits @@ -1491,7 +1468,6 @@ SRCS acoshf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.acoshf libc.src.__support.FPUtil.fp_bits @@ -1505,7 +1481,6 @@ SRCS asinf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.asinf libc.src.__support.FPUtil.fp_bits @@ -1519,7 +1494,6 @@ SRCS asin_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.asin ) @@ -1532,7 +1506,6 @@ SRCS acosf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.acosf libc.src.__support.FPUtil.fp_bits @@ -1546,7 +1519,6 @@ SRCS atanf_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.atanf libc.src.__support.FPUtil.fp_bits @@ -1574,7 +1546,6 @@ SRCS pow_test.cpp DEPENDS - libc.include.errno libc.src.errno.errno libc.src.math.pow ) diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h --- a/libc/test/src/math/RoundToIntegerTest.h +++ b/libc/test/src/math/RoundToIntegerTest.h @@ -42,7 +42,7 @@ void test_one_input(RoundToIntegerFunc func, F input, I expected, bool expectError) { - errno = 0; + libc_errno = 0; __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); ASSERT_EQ(func(input), expected); diff --git a/libc/test/src/math/acosf_test.cpp b/libc/test/src/math/acosf_test.cpp --- a/libc/test/src/math/acosf_test.cpp +++ b/libc/test/src/math/acosf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -23,7 +24,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcAcosfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::acosf(aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/acoshf_test.cpp b/libc/test/src/math/acoshf_test.cpp --- a/libc/test/src/math/acoshf_test.cpp +++ b/libc/test/src/math/acoshf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -23,13 +24,13 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcAcoshfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::acoshf(aNaN)); EXPECT_MATH_ERRNO(0); EXPECT_FP_EQ(aNaN, __llvm_libc::acoshf(0.0f)); - EXPECT_MATH_ERRNO(0); + EXPECT_MATH_ERRNO(EDOM); EXPECT_FP_EQ(0.0f, __llvm_libc::acoshf(1.0f)); EXPECT_MATH_ERRNO(0); @@ -38,7 +39,7 @@ EXPECT_MATH_ERRNO(0); EXPECT_FP_EQ(aNaN, __llvm_libc::acoshf(neg_inf)); - EXPECT_MATH_ERRNO(0); + EXPECT_MATH_ERRNO(EDOM); } TEST(LlvmLibcAcoshfTest, InFloatRange) { diff --git a/libc/test/src/math/asin_test.cpp b/libc/test/src/math/asin_test.cpp --- a/libc/test/src/math/asin_test.cpp +++ b/libc/test/src/math/asin_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "src/errno/libc_errno.h" #include "src/math/asin.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -22,7 +23,7 @@ DECLARE_SPECIAL_CONSTANTS(double) TEST(LlvmLibcAsinTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::asin(aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/asinf_test.cpp b/libc/test/src/math/asinf_test.cpp --- a/libc/test/src/math/asinf_test.cpp +++ b/libc/test/src/math/asinf_test.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #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" @@ -24,7 +25,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcAsinfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::asinf(aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/asinhf_test.cpp b/libc/test/src/math/asinhf_test.cpp --- a/libc/test/src/math/asinhf_test.cpp +++ b/libc/test/src/math/asinhf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -23,7 +24,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcAsinhfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::asinhf(aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/atanf_test.cpp b/libc/test/src/math/atanf_test.cpp --- a/libc/test/src/math/atanf_test.cpp +++ b/libc/test/src/math/atanf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -25,7 +26,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcAtanfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); EXPECT_FP_EQ(aNaN, __llvm_libc::atanf(aNaN)); EXPECT_FP_EXCEPTION(0); diff --git a/libc/test/src/math/atanhf_test.cpp b/libc/test/src/math/atanhf_test.cpp --- a/libc/test/src/math/atanhf_test.cpp +++ b/libc/test/src/math/atanhf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -23,7 +24,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcAtanhfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); EXPECT_FP_EQ(aNaN, __llvm_libc::atanhf(aNaN)); EXPECT_FP_EXCEPTION(0); diff --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp --- a/libc/test/src/math/cosf_test.cpp +++ b/libc/test/src/math/cosf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -25,7 +26,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcCosfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::cosf(aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/coshf_test.cpp b/libc/test/src/math/coshf_test.cpp --- a/libc/test/src/math/coshf_test.cpp +++ b/libc/test/src/math/coshf_test.cpp @@ -8,6 +8,7 @@ #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" @@ -24,7 +25,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcCoshfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::coshf(aNaN)); EXPECT_MATH_ERRNO(0); @@ -43,7 +44,7 @@ } TEST(LlvmLibcCoshfTest, Overflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( inf, __llvm_libc::coshf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); diff --git a/libc/test/src/math/exp10f_test.cpp b/libc/test/src/math/exp10f_test.cpp --- a/libc/test/src/math/exp10f_test.cpp +++ b/libc/test/src/math/exp10f_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -21,7 +22,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcExp10fTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::exp10f(aNaN)); EXPECT_MATH_ERRNO(0); @@ -40,7 +41,7 @@ } TEST(LlvmLibcExp10fTest, Overflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( inf, __llvm_libc::exp10f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); @@ -55,7 +56,7 @@ } TEST(LlvmLibcExp10fTest, Underflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( 0.0f, __llvm_libc::exp10f(float(FPBits(0xff7fffffU))), FE_UNDERFLOW); EXPECT_MATH_ERRNO(ERANGE); @@ -96,7 +97,7 @@ 0x41200000, // x = 10.0f }; for (int i = 0; i < N; ++i) { - errno = 0; + libc_errno = 0; float x = float(FPBits(INPUTS[i])); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x, __llvm_libc::exp10f(x), 0.5); @@ -112,7 +113,7 @@ float x = float(FPBits(v)); if (isnan(x) || isinf(x)) continue; - errno = 0; + libc_errno = 0; float result = __llvm_libc::exp10f(x); // If the computation resulted in an error or did not produce valid result diff --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp --- a/libc/test/src/math/exp2f_test.cpp +++ b/libc/test/src/math/exp2f_test.cpp @@ -8,6 +8,7 @@ #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" @@ -22,7 +23,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcExp2fTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::exp2f(aNaN)); EXPECT_MATH_ERRNO(0); @@ -41,7 +42,7 @@ } TEST(LlvmLibcExp2fTest, Overflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( inf, __llvm_libc::exp2f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); @@ -72,7 +73,7 @@ 0xc3150000U, /*-0x1.2ap+7f*/ }; for (int i = 0; i < N; ++i) { - errno = 0; + libc_errno = 0; float x = float(FPBits(INPUTS[i])); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 0.5); @@ -81,7 +82,7 @@ } TEST(LlvmLibcExp2fTest, Underflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( 0.0f, __llvm_libc::exp2f(float(FPBits(0xff7fffffU))), FE_UNDERFLOW); EXPECT_MATH_ERRNO(ERANGE); @@ -109,7 +110,7 @@ float x = float(FPBits(v)); if (isnan(x) || isinf(x)) continue; - errno = 0; + libc_errno = 0; float result = __llvm_libc::exp2f(x); // If the computation resulted in an error or did not produce valid result diff --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp --- a/libc/test/src/math/expf_test.cpp +++ b/libc/test/src/math/expf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -21,7 +22,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcExpfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::expf(aNaN)); EXPECT_MATH_ERRNO(0); @@ -40,7 +41,7 @@ } TEST(LlvmLibcExpfTest, Overflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( inf, __llvm_libc::expf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); @@ -55,7 +56,7 @@ } TEST(LlvmLibcExpfTest, Underflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( 0.0f, __llvm_libc::expf(float(FPBits(0xff7fffffU))), FE_UNDERFLOW); EXPECT_MATH_ERRNO(ERANGE); @@ -76,7 +77,7 @@ TEST(LlvmLibcExpfTest, Borderline) { float x; - errno = 0; + libc_errno = 0; x = float(FPBits(0x42affff8U)); ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 0.5); @@ -110,7 +111,7 @@ float x = float(FPBits(v)); if (isnan(x) || isinf(x)) continue; - errno = 0; + libc_errno = 0; float result = __llvm_libc::expf(x); // If the computation resulted in an error or did not produce valid result diff --git a/libc/test/src/math/expm1f_test.cpp b/libc/test/src/math/expm1f_test.cpp --- a/libc/test/src/math/expm1f_test.cpp +++ b/libc/test/src/math/expm1f_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -21,7 +22,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcExpm1fTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::expm1f(aNaN)); EXPECT_MATH_ERRNO(0); @@ -40,7 +41,7 @@ } TEST(LlvmLibcExpm1fTest, Overflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( inf, __llvm_libc::expm1f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); @@ -55,7 +56,7 @@ } TEST(LlvmLibcExpm1fTest, Underflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(-1.0f, __llvm_libc::expm1f(float(FPBits(0xff7fffffU)))); float x = float(FPBits(0xc2cffff8U)); @@ -70,7 +71,7 @@ TEST(LlvmLibcExpm1fTest, Borderline) { float x; - errno = 0; + libc_errno = 0; x = float(FPBits(0x42affff8U)); ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x, __llvm_libc::expm1f(x), 0.5); @@ -119,7 +120,7 @@ float x = float(FPBits(v)); if (isnan(x) || isinf(x)) continue; - errno = 0; + libc_errno = 0; float result = __llvm_libc::expm1f(x); // If the computation resulted in an error or did not produce valid result diff --git a/libc/test/src/math/log10_test.cpp b/libc/test/src/math/log10_test.cpp --- a/libc/test/src/math/log10_test.cpp +++ b/libc/test/src/math/log10_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -84,7 +85,7 @@ double x = FPBits(v).get_val(); if (isnan(x) || isinf(x) || x < 0.0) continue; - errno = 0; + libc_errno = 0; double result = __llvm_libc::log10(x); ++cc; if (isnan(result)) diff --git a/libc/test/src/math/log1pf_test.cpp b/libc/test/src/math/log1pf_test.cpp --- a/libc/test/src/math/log1pf_test.cpp +++ b/libc/test/src/math/log1pf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -75,7 +76,7 @@ float x = float(FPBits(v)); if (isnan(x) || isinf(x)) continue; - errno = 0; + libc_errno = 0; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x, __llvm_libc::log1pf(x), 0.5); } diff --git a/libc/test/src/math/log2f_test.cpp b/libc/test/src/math/log2f_test.cpp --- a/libc/test/src/math/log2f_test.cpp +++ b/libc/test/src/math/log2f_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -50,7 +51,7 @@ float x = float(FPBits(v)); if (isnan(x) || isinf(x)) continue; - errno = 0; + libc_errno = 0; float result = __llvm_libc::log2f(x); // If the computation resulted in an error or did not produce valid result // in the single-precision floating point range, then ignore comparing with diff --git a/libc/test/src/math/pow_test.cpp b/libc/test/src/math/pow_test.cpp --- a/libc/test/src/math/pow_test.cpp +++ b/libc/test/src/math/pow_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "src/errno/libc_errno.h" #include "src/math/pow.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -22,7 +23,7 @@ DECLARE_SPECIAL_CONSTANTS(double) TEST(LlvmLibcAsinTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::pow(aNaN, aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp --- a/libc/test/src/math/sincosf_test.cpp +++ b/libc/test/src/math/sincosf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -25,7 +26,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcSinCosfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; float sin, cos; __llvm_libc::sincosf(aNaN, &sin, &cos); diff --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp --- a/libc/test/src/math/sinf_test.cpp +++ b/libc/test/src/math/sinf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -25,7 +26,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcSinfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/sinhf_test.cpp b/libc/test/src/math/sinhf_test.cpp --- a/libc/test/src/math/sinhf_test.cpp +++ b/libc/test/src/math/sinhf_test.cpp @@ -8,6 +8,7 @@ #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" @@ -24,7 +25,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcSinhfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::sinhf(aNaN)); EXPECT_MATH_ERRNO(0); @@ -67,7 +68,7 @@ } TEST(LlvmLibcSinhfTest, Overflow) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ_WITH_EXCEPTION( inf, __llvm_libc::sinhf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); diff --git a/libc/test/src/math/tanf_test.cpp b/libc/test/src/math/tanf_test.cpp --- a/libc/test/src/math/tanf_test.cpp +++ b/libc/test/src/math/tanf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -25,7 +26,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcTanfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::tanf(aNaN)); EXPECT_MATH_ERRNO(0); diff --git a/libc/test/src/math/tanhf_test.cpp b/libc/test/src/math/tanhf_test.cpp --- a/libc/test/src/math/tanhf_test.cpp +++ b/libc/test/src/math/tanhf_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" @@ -23,7 +24,7 @@ DECLARE_SPECIAL_CONSTANTS(float) TEST(LlvmLibcTanhfTest, SpecialNumbers) { - errno = 0; + libc_errno = 0; EXPECT_FP_EQ(aNaN, __llvm_libc::tanhf(aNaN)); EXPECT_MATH_ERRNO(0);