Skip to content

Commit

Permalink
[libc][NFC] Switch all uses of errno in math and math tests to libc_e…
Browse files Browse the repository at this point in the history
…rrno.
  • Loading branch information
Siva Chandra Reddy committed Mar 13, 2023
1 parent ca0cd67 commit adff2b2
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 13 deletions.
5 changes: 3 additions & 2 deletions libc/src/math/generic/math_utils.h
Expand Up @@ -12,7 +12,8 @@
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/common.h"
#include <errno.h>
#include "src/errno/libc_errno.h"

#include <math.h>

#include <stdint.h>
Expand Down Expand Up @@ -52,7 +53,7 @@ template <> struct XFlowValues<double> {

template <typename T> LIBC_INLINE T with_errno(T x, int err) {
if (math_errhandling & MATH_ERRNO)
errno = err;
libc_errno = err;
return x;
}

Expand Down
2 changes: 2 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Expand Up @@ -1355,6 +1355,7 @@ add_fp_unittest(
FModTest.h
DEPENDS
libc.include.math
libc.src.errno.errno
libc.src.math.fmodf
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
Expand All @@ -1370,6 +1371,7 @@ add_fp_unittest(
FModTest.h
DEPENDS
libc.include.math
libc.src.errno.errno
libc.src.math.fmod
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/math/exp10f_test.cpp
Expand Up @@ -14,7 +14,6 @@
#include "utils/MPFRWrapper/MPFRUtils.h"
#include <math.h>

#include <errno.h>
#include <stdint.h>

namespace mpfr = __llvm_libc::testing::mpfr;
Expand Down Expand Up @@ -120,7 +119,7 @@ TEST(LlvmLibcExp10fTest, InFloatRange) {
// in the single-precision floating point range, then ignore comparing with
// MPFR result as MPFR can still produce valid results because of its
// wider precision.
if (isnan(result) || isinf(result) || errno != 0)
if (isnan(result) || isinf(result) || libc_errno != 0)
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
__llvm_libc::exp10f(x), 0.5);
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/math/exp2f_test.cpp
Expand Up @@ -15,7 +15,6 @@
#include "utils/MPFRWrapper/MPFRUtils.h"
#include <math.h>

#include <errno.h>
#include <stdint.h>

namespace mpfr = __llvm_libc::testing::mpfr;
Expand Down Expand Up @@ -117,7 +116,7 @@ TEST(LlvmLibcExp2fTest, InFloatRange) {
// in the single-precision floating point range, then ignore comparing with
// MPFR result as MPFR can still produce valid results because of its
// wider precision.
if (isnan(result) || isinf(result) || errno != 0)
if (isnan(result) || isinf(result) || libc_errno != 0)
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x,
__llvm_libc::exp2f(x), 0.5);
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/math/expf_test.cpp
Expand Up @@ -14,7 +14,6 @@
#include "utils/MPFRWrapper/MPFRUtils.h"
#include <math.h>

#include <errno.h>
#include <stdint.h>

namespace mpfr = __llvm_libc::testing::mpfr;
Expand Down Expand Up @@ -118,7 +117,7 @@ TEST(LlvmLibcExpfTest, InFloatRange) {
// in the single-precision floating point range, then ignore comparing with
// MPFR result as MPFR can still produce valid results because of its
// wider precision.
if (isnan(result) || isinf(result) || errno != 0)
if (isnan(result) || isinf(result) || libc_errno != 0)
continue;
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
__llvm_libc::expf(x), 0.5);
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/math/expm1f_test.cpp
Expand Up @@ -14,7 +14,6 @@
#include "utils/MPFRWrapper/MPFRUtils.h"
#include <math.h>

#include <errno.h>
#include <stdint.h>

namespace mpfr = __llvm_libc::testing::mpfr;
Expand Down Expand Up @@ -127,7 +126,7 @@ TEST(LlvmLibcExpm1fTest, InFloatRange) {
// in the single-precision floating point range, then ignore comparing with
// MPFR result as MPFR can still produce valid results because of its
// wider precision.
if (isnan(result) || isinf(result) || errno != 0)
if (isnan(result) || isinf(result) || libc_errno != 0)
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
__llvm_libc::expm1f(x), 0.5);
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/math/log2f_test.cpp
Expand Up @@ -14,7 +14,6 @@
#include "utils/MPFRWrapper/MPFRUtils.h"
#include <math.h>

#include <errno.h>
#include <stdint.h>

namespace mpfr = __llvm_libc::testing::mpfr;
Expand Down Expand Up @@ -57,7 +56,7 @@ TEST(LlvmLibcLog2fTest, InFloatRange) {
// in the single-precision floating point range, then ignore comparing with
// MPFR result as MPFR can still produce valid results because of its
// wider precision.
if (isnan(result) || isinf(result) || errno != 0)
if (isnan(result) || isinf(result) || libc_errno != 0)
continue;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,
__llvm_libc::log2f(x), 0.5);
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/math/logf_test.cpp
Expand Up @@ -13,7 +13,6 @@
#include "utils/MPFRWrapper/MPFRUtils.h"
#include <math.h>

#include <errno.h>
#include <stdint.h>

namespace mpfr = __llvm_libc::testing::mpfr;
Expand Down

0 comments on commit adff2b2

Please sign in to comment.