[libc][math] Switch math functions to use libc_errno and fix some errno and floating...
authorTue Ly <lntue@google.com>
Mon, 6 Mar 2023 03:57:51 +0000 (22:57 -0500)
committerTue Ly <lntue@google.com>
Tue, 7 Mar 2023 05:51:16 +0000 (00:51 -0500)
Switch math functions to use libc_errno and fix some errno and
floating point exceptions

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145349

40 files changed:
libc/src/__support/FPUtil/CMakeLists.txt
libc/src/__support/FPUtil/FEnvImpl.h
libc/src/__support/FPUtil/NearestIntegerOperations.h
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/acosf.cpp
libc/src/math/generic/acoshf.cpp
libc/src/math/generic/atanhf.cpp
libc/src/math/generic/cosf.cpp
libc/src/math/generic/log10.cpp
libc/src/math/generic/log10f.cpp
libc/src/math/generic/log1pf.cpp
libc/src/math/generic/log2f.cpp
libc/src/math/generic/logf.cpp
libc/src/math/generic/sinf.cpp
libc/src/math/generic/tanf.cpp
libc/test/UnitTest/FPMatcher.h
libc/test/src/math/CMakeLists.txt
libc/test/src/math/RoundToIntegerTest.h
libc/test/src/math/acosf_test.cpp
libc/test/src/math/acoshf_test.cpp
libc/test/src/math/asin_test.cpp
libc/test/src/math/asinf_test.cpp
libc/test/src/math/asinhf_test.cpp
libc/test/src/math/atanf_test.cpp
libc/test/src/math/atanhf_test.cpp
libc/test/src/math/cosf_test.cpp
libc/test/src/math/coshf_test.cpp
libc/test/src/math/exp10f_test.cpp
libc/test/src/math/exp2f_test.cpp
libc/test/src/math/expf_test.cpp
libc/test/src/math/expm1f_test.cpp
libc/test/src/math/log10_test.cpp
libc/test/src/math/log1pf_test.cpp
libc/test/src/math/log2f_test.cpp
libc/test/src/math/pow_test.cpp
libc/test/src/math/sincosf_test.cpp
libc/test/src/math/sinf_test.cpp
libc/test/src/math/sinhf_test.cpp
libc/test/src/math/tanf_test.cpp
libc/test/src/math/tanhf_test.cpp

index 6ccb3ba..b737aad 100644 (file)
@@ -3,7 +3,6 @@ add_header_library(
   HDRS
     FEnvImpl.h
   DEPENDS
-    libc.include.errno
     libc.include.fenv
     libc.include.math
     libc.src.__support.macros.attributes
@@ -52,7 +51,6 @@ add_header_library(
     libc.src.__support.CPP.type_traits
     libc.src.__support.common
     libc.include.math
-    libc.include.errno
     libc.src.errno.errno
 )
 
@@ -80,7 +78,6 @@ add_header_library(
     libc.src.__support.common
     libc.src.__support.macros.optimization
     libc.include.math
-    libc.include.errno
     libc.src.errno.errno
 )
 
index 5041b3e..ec21555 100644 (file)
@@ -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 <errno.h>
 #include <fenv.h>
 #include <math.h>
 
@@ -71,7 +71,7 @@ LIBC_INLINE int raise_except_if_required(int excepts) {
 
 LIBC_INLINE void set_errno_if_required(int err) {
   if (math_errhandling & MATH_ERRNO)
-    errno = err;
+    libc_errno = err;
 }
 
 } // namespace __llvm_libc::fputil
index 968e7d4..8265ea1 100644 (file)
@@ -15,7 +15,6 @@
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/common.h"
 
-#include <errno.h>
 #include <math.h>
 
 namespace __llvm_libc {
@@ -238,10 +237,8 @@ LIBC_INLINE I rounded_float_to_signed_integer(F x) {
   constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
   FPBits<F> 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()) {
index 922e16f..09aefc6 100644 (file)
@@ -774,6 +774,7 @@ add_entrypoint_object(
   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
index d75e362..5835dfa 100644 (file)
@@ -79,8 +79,7 @@ LLVM_LIBC_FUNCTION(float, acosf, (float x)) {
       fputil::set_errno_if_required(EDOM);
       fputil::raise_except_if_required(FE_INVALID);
     }
-    return x +
-           FPBits::build_nan(1 << (fputil::MantissaWidth<float>::VALUE - 1));
+    return x + FPBits::build_quiet_nan(0);
   }
 
   // When 0.5 < |x| <= 1, we perform range reduction as follow:
index 12e0796..ac225fe 100644 (file)
@@ -25,7 +25,8 @@ LLVM_LIBC_FUNCTION(float, acoshf, (float x)) {
 
   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);
   }
 
index 0a07700..b0c92fa 100644 (file)
@@ -24,15 +24,15 @@ LLVM_LIBC_FUNCTION(float, atanhf, (float x)) {
     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<float>::VALUE - 1)),
-          EDOM);
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::build_quiet_nan(0);
     }
   }
 
index 89b7d63..ef94804 100644 (file)
@@ -117,8 +117,7 @@ LLVM_LIBC_FUNCTION(float, cosf, (float x)) {
       fputil::set_errno_if_required(EDOM);
       fputil::raise_except_if_required(FE_INVALID);
     }
-    return x +
-           FPBits::build_nan(1 << (fputil::MantissaWidth<float>::VALUE - 1));
+    return x + FPBits::build_quiet_nan(0);
   }
 
   // Combine the results with the sine of sum formula:
index 10d57a8..8eca773 100644 (file)
@@ -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 @@ LLVM_LIBC_FUNCTION(double, log10, (double x)) {
                     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<double>(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()) {
index ba2f016..bcf17c6 100644 (file)
@@ -152,12 +152,14 @@ LLVM_LIBC_FUNCTION(float, log10f, (float x)) {
   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<float>(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()) {
index 1a18e0c..bf6a91a 100644 (file)
@@ -45,7 +45,8 @@ LIBC_INLINE float log(double x) {
 
   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<float>::build_quiet_nan(0);
     }
     return static_cast<float>(x);
@@ -103,7 +104,8 @@ LLVM_LIBC_FUNCTION(float, log1pf, (float x)) {
     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<float>(fputil::FPBits<float>::neg_inf());
 #ifndef LIBC_TARGET_CPU_HAS_FMA
     case 0x4cc1c80bU: // x = 0x1.839016p+26f
index 47abcf8..ae3c67a 100644 (file)
@@ -121,10 +121,12 @@ LLVM_LIBC_FUNCTION(float, log2f, (float x)) {
   // 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<float>(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);
     }
index b579b5b..f2c1fa3 100644 (file)
@@ -96,12 +96,14 @@ LLVM_LIBC_FUNCTION(float, logf, (float x)) {
   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<float>(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()) {
index 86f47ac..1641c44 100644 (file)
@@ -138,8 +138,7 @@ LLVM_LIBC_FUNCTION(float, sinf, (float x)) {
       fputil::set_errno_if_required(EDOM);
       fputil::raise_except_if_required(FE_INVALID);
     }
-    return x +
-           FPBits::build_nan(1 << (fputil::MantissaWidth<float>::VALUE - 1));
+    return x + FPBits::build_quiet_nan(0);
   }
 
   // Combine the results with the sine of sum formula:
index e220820..217664f 100644 (file)
@@ -114,8 +114,7 @@ LLVM_LIBC_FUNCTION(float, tanf, (float x)) {
         fputil::set_errno_if_required(EDOM);
         fputil::raise_except_if_required(FE_INVALID);
       }
-      return x +
-             FPBits::build_nan(1 << (fputil::MantissaWidth<float>::VALUE - 1));
+      return x + FPBits::build_quiet_nan(0);
     }
     // Other large exceptional values
     if (auto r = TANF_EXCEPTS.lookup_odd(x_abs, x_sign);
index f804b65..89ccf1a 100644 (file)
@@ -14,7 +14,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/testutils/RoundingModeUtils.h"
 
-#include <errno.h>
 #include <math.h>
 
 namespace __llvm_libc {
@@ -106,8 +105,8 @@ FPMatcher<T, C> getMatcher(T expectedValue) {
 #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 @@ FPMatcher<T, C> getMatcher(T expectedValue) {
 #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)
index 54cabf8..0a929ff 100644 (file)
@@ -10,7 +10,6 @@ add_fp_unittest(
   HDRS
     sdcomp26094.h
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.cosf
     libc.src.__support.CPP.array
@@ -39,7 +38,6 @@ add_fp_unittest(
   HDRS
     sdcomp26094.h
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.sinf
     libc.src.__support.CPP.array
@@ -68,7 +66,6 @@ add_fp_unittest(
   HDRS
     sdcomp26094.h
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.sincosf
     libc.src.__support.CPP.array
@@ -85,7 +82,6 @@ add_fp_unittest(
   HDRS
     sdcomp26094.h
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.tanf
     libc.src.__support.CPP.array
@@ -327,7 +323,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.errno
     libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
@@ -347,7 +342,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.errno
     libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
@@ -367,7 +361,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.errno
     libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
@@ -387,7 +380,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.errno
     libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
@@ -407,7 +399,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.errno
     libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
@@ -427,7 +418,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.errno
     libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
@@ -589,7 +579,6 @@ add_fp_unittest(
   SRCS
     expf_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.expf
@@ -604,7 +593,6 @@ add_fp_unittest(
   SRCS
     exp2f_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.exp2f
@@ -619,7 +607,6 @@ add_fp_unittest(
   SRCS
     exp10f_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.exp10f
@@ -1268,7 +1255,6 @@ add_fp_unittest(
   SRCS
     expm1f_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.expm1f
@@ -1295,7 +1281,6 @@ add_fp_unittest(
   SRCS
     logf_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.logf
@@ -1310,7 +1295,6 @@ add_fp_unittest(
   SRCS
     log2f_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.log2f
@@ -1325,7 +1309,6 @@ add_fp_unittest(
  SRCS
    log10_test.cpp
  DEPENDS
-   libc.include.errno
    libc.src.errno.errno
    libc.include.math
    libc.src.math.log10
@@ -1342,7 +1325,6 @@ add_fp_unittest(
   SRCS
     log10f_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.log10f
@@ -1357,7 +1339,6 @@ add_fp_unittest(
   SRCS
     log1pf_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.include.math
     libc.src.math.log1pf
@@ -1419,7 +1400,6 @@ add_fp_unittest(
   HDRS
     sdcomp26094.h
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.coshf
     libc.src.__support.CPP.array
@@ -1436,7 +1416,6 @@ add_fp_unittest(
   HDRS
     sdcomp26094.h
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.sinhf
     libc.src.__support.CPP.array
@@ -1463,7 +1442,6 @@ add_fp_unittest(
   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 @@ add_fp_unittest(
   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 @@ add_fp_unittest(
   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 @@ add_fp_unittest(
   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 @@ add_fp_unittest(
   SRCS
     asin_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.asin
 )
@@ -1532,7 +1506,6 @@ add_fp_unittest(
   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 @@ add_fp_unittest(
   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 @@ add_fp_unittest(
   SRCS
     pow_test.cpp
   DEPENDS
-    libc.include.errno
     libc.src.errno.errno
     libc.src.math.pow
 )
index 823ec8d..a8be948 100644 (file)
@@ -42,7 +42,7 @@ private:
 
   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);
index ea79aff..0d2db12 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcAcosfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::acosf(aNaN));
   EXPECT_MATH_ERRNO(0);
index 4ac01b7..03f3a30 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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 @@ TEST(LlvmLibcAcoshfTest, SpecialNumbers) {
   EXPECT_MATH_ERRNO(0);
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::acoshf(neg_inf));
-  EXPECT_MATH_ERRNO(0);
+  EXPECT_MATH_ERRNO(EDOM);
 }
 
 TEST(LlvmLibcAcoshfTest, InFloatRange) {
index d1b8483..2ccbebf 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(double)
 
 TEST(LlvmLibcAsinTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::asin(aNaN));
   EXPECT_MATH_ERRNO(0);
index 890f21f..439d23c 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcAsinfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::asinf(aNaN));
   EXPECT_MATH_ERRNO(0);
index d2c6584..906f834 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcAsinhfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::asinhf(aNaN));
   EXPECT_MATH_ERRNO(0);
index 7601ffb..dbe1d48 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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);
index d4b8848..b11a9df 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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);
index dae3c93..721ca32 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcCosfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::cosf(aNaN));
   EXPECT_MATH_ERRNO(0);
index c151fba..88354a1 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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, SpecialNumbers) {
 }
 
 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);
index 1ea7b80..684aa01 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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, SpecialNumbers) {
 }
 
 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, Overflow) {
 }
 
 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 @@ TEST(LlvmLibcExp10fTest, TrickyInputs) {
       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 @@ TEST(LlvmLibcExp10fTest, InFloatRange) {
     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
index b38c4d4..22abd23 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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, SpecialNumbers) {
 }
 
 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 @@ TEST(LlvmLibcExp2fTest, TrickyInputs) {
       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, TrickyInputs) {
 }
 
 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 @@ TEST(LlvmLibcExp2fTest, InFloatRange) {
     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
index bcd1dcd..a38bcbd 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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, SpecialNumbers) {
 }
 
 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, Overflow) {
 }
 
 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, Underflow) {
 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 @@ TEST(LlvmLibcExpfTest, InFloatRange) {
     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
index 74df79f..8ea85f7 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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, SpecialNumbers) {
 }
 
 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, Overflow) {
 }
 
 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, Underflow) {
 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 @@ TEST(LlvmLibcExpm1fTest, InFloatRange) {
     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
index edefa4c..15e5ee6 100644 (file)
@@ -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 @@ TEST(LlvmLibcLog10Test, InDoubleRange) {
       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))
index 973c719..e5137e6 100644 (file)
@@ -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 @@ TEST(LlvmLibclog1pfTest, InFloatRange) {
     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);
   }
index 08619ef..bef2ffd 100644 (file)
@@ -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 @@ TEST(LlvmLibcLog2fTest, InFloatRange) {
     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
index 2be8b87..eff578a 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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);
index 1fd8919..8f580c9 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcSinCosfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
   float sin, cos;
 
   __llvm_libc::sincosf(aNaN, &sin, &cos);
index 3559515..a4a2eda 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcSinfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(aNaN));
   EXPECT_MATH_ERRNO(0);
index 6bec642..c0a0775 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 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, SmallValues) {
 }
 
 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);
index cfe1762..a513a03 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcTanfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::tanf(aNaN));
   EXPECT_MATH_ERRNO(0);
index dc8af63..6e7a1b4 100644 (file)
@@ -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 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(LlvmLibcTanhfTest, SpecialNumbers) {
-  errno = 0;
+  libc_errno = 0;
 
   EXPECT_FP_EQ(aNaN, __llvm_libc::tanhf(aNaN));
   EXPECT_MATH_ERRNO(0);