[libc] Remove redundant header files included from internal paths.

This commit is contained in:
Siva Chandra Reddy 2021-03-03 21:29:46 -08:00
parent e94125f054
commit 35e2e448ce
6 changed files with 97 additions and 103 deletions

View File

@ -10,7 +10,6 @@
#define LLVM_LIBC_SRC_MATH_MATH_UTILS_H #define LLVM_LIBC_SRC_MATH_MATH_UTILS_H
#include "src/__support/common.h" #include "src/__support/common.h"
#include "src/errno/llvmlibc_errno.h"
#include "utils/CPP/TypeTraits.h" #include "utils/CPP/TypeTraits.h"
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
@ -56,7 +55,7 @@ template <> struct XFlowValues<double> {
template <typename T> static inline T with_errno(T x, int err) { template <typename T> static inline T with_errno(T x, int err) {
if (math_errhandling & MATH_ERRNO) if (math_errhandling & MATH_ERRNO)
llvmlibc_errno = err; errno = err; // NOLINT
return x; return x;
} }

View File

@ -6,8 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "include/errno.h"
#include "src/errno/llvmlibc_errno.h"
#include "src/math/cosf.h" #include "src/math/cosf.h"
#include "test/src/math/sdcomp26094.h" #include "test/src/math/sdcomp26094.h"
#include "utils/CPP/Array.h" #include "utils/CPP/Array.h"
@ -19,6 +17,7 @@
#include "utils/UnitTest/Test.h" #include "utils/UnitTest/Test.h"
#include <math.h> #include <math.h>
#include <errno.h>
#include <stdint.h> #include <stdint.h>
using __llvm_libc::fputil::isNegativeQuietNaN; using __llvm_libc::fputil::isNegativeQuietNaN;
@ -33,40 +32,40 @@ using __llvm_libc::testing::sdcomp26094Values;
namespace mpfr = __llvm_libc::testing::mpfr; namespace mpfr = __llvm_libc::testing::mpfr;
TEST(LlvmLibcCosfTest, SpecialNumbers) { TEST(LlvmLibcCosfTest, SpecialNumbers) {
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE( EXPECT_TRUE(
isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::aQuietNaN)))); isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::aQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::cosf(valueFromBits(BitPatterns::aNegativeQuietNaN)))); __llvm_libc::cosf(valueFromBits(BitPatterns::aNegativeQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isQuietNaN( EXPECT_TRUE(isQuietNaN(
__llvm_libc::cosf(valueFromBits(BitPatterns::aSignallingNaN)))); __llvm_libc::cosf(valueFromBits(BitPatterns::aSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::cosf(valueFromBits(BitPatterns::aNegativeSignallingNaN)))); __llvm_libc::cosf(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::one, EXPECT_EQ(BitPatterns::one,
valueAsBits(__llvm_libc::cosf(valueFromBits(BitPatterns::zero)))); valueAsBits(__llvm_libc::cosf(valueFromBits(BitPatterns::zero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::cosf( EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::cosf(
valueFromBits(BitPatterns::negZero)))); valueFromBits(BitPatterns::negZero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE(isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::inf)))); EXPECT_TRUE(isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::inf))));
EXPECT_EQ(llvmlibc_errno, EDOM); EXPECT_EQ(errno, EDOM);
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE( EXPECT_TRUE(
isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::negInf)))); isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::negInf))));
EXPECT_EQ(llvmlibc_errno, EDOM); EXPECT_EQ(errno, EDOM);
} }
TEST(LlvmLibcCosfTest, InFloatRange) { TEST(LlvmLibcCosfTest, InFloatRange) {

View File

@ -6,8 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "include/errno.h"
#include "src/errno/llvmlibc_errno.h"
#include "src/math/exp2f.h" #include "src/math/exp2f.h"
#include "utils/FPUtil/BitPatterns.h" #include "utils/FPUtil/BitPatterns.h"
#include "utils/FPUtil/ClassificationFunctions.h" #include "utils/FPUtil/ClassificationFunctions.h"
@ -17,6 +15,7 @@
#include "utils/UnitTest/Test.h" #include "utils/UnitTest/Test.h"
#include <math.h> #include <math.h>
#include <errno.h>
#include <stdint.h> #include <stdint.h>
using __llvm_libc::fputil::isNegativeQuietNaN; using __llvm_libc::fputil::isNegativeQuietNaN;
@ -29,56 +28,56 @@ using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
namespace mpfr = __llvm_libc::testing::mpfr; namespace mpfr = __llvm_libc::testing::mpfr;
TEST(LlvmLibcexp2fTest, SpecialNumbers) { TEST(LlvmLibcexp2fTest, SpecialNumbers) {
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE( EXPECT_TRUE(
isQuietNaN(__llvm_libc::exp2f(valueFromBits(BitPatterns::aQuietNaN)))); isQuietNaN(__llvm_libc::exp2f(valueFromBits(BitPatterns::aQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::exp2f(valueFromBits(BitPatterns::aNegativeQuietNaN)))); __llvm_libc::exp2f(valueFromBits(BitPatterns::aNegativeQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isQuietNaN( EXPECT_TRUE(isQuietNaN(
__llvm_libc::exp2f(valueFromBits(BitPatterns::aSignallingNaN)))); __llvm_libc::exp2f(valueFromBits(BitPatterns::aSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::exp2f(valueFromBits(BitPatterns::aNegativeSignallingNaN)))); __llvm_libc::exp2f(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::exp2f(valueFromBits(BitPatterns::inf)))); valueAsBits(__llvm_libc::exp2f(valueFromBits(BitPatterns::inf))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::zero, valueAsBits(__llvm_libc::exp2f( EXPECT_EQ(BitPatterns::zero, valueAsBits(__llvm_libc::exp2f(
valueFromBits(BitPatterns::negInf)))); valueFromBits(BitPatterns::negInf))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::one, EXPECT_EQ(BitPatterns::one,
valueAsBits(__llvm_libc::exp2f(valueFromBits(BitPatterns::zero)))); valueAsBits(__llvm_libc::exp2f(valueFromBits(BitPatterns::zero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::exp2f( EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::exp2f(
valueFromBits(BitPatterns::negZero)))); valueFromBits(BitPatterns::negZero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
} }
TEST(LlvmLibcExpfTest, Overflow) { TEST(LlvmLibcExpfTest, Overflow) {
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::exp2f(valueFromBits(0x7f7fffffU)))); valueAsBits(__llvm_libc::exp2f(valueFromBits(0x7f7fffffU))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::exp2f(valueFromBits(0x43000000U)))); valueAsBits(__llvm_libc::exp2f(valueFromBits(0x43000000U))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::exp2f(valueFromBits(0x43000001U)))); valueAsBits(__llvm_libc::exp2f(valueFromBits(0x43000001U))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
} }
// Test with inputs which are the borders of underflow/overflow but still // Test with inputs which are the borders of underflow/overflow but still
@ -86,47 +85,47 @@ TEST(LlvmLibcExpfTest, Overflow) {
TEST(LlvmLibcExpfTest, Borderline) { TEST(LlvmLibcExpfTest, Borderline) {
float x; float x;
llvmlibc_errno = 0; errno = 0;
x = valueFromBits(0x42fa0001U); x = valueFromBits(0x42fa0001U);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0x42ffffffU); x = valueFromBits(0x42ffffffU);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0xc2fa0001U); x = valueFromBits(0xc2fa0001U);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0xc2fc0000U); x = valueFromBits(0xc2fc0000U);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0xc2fc0001U); x = valueFromBits(0xc2fc0001U);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0xc3150000U); x = valueFromBits(0xc3150000U);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
} }
TEST(LlvmLibcExpfTest, Underflow) { TEST(LlvmLibcExpfTest, Underflow) {
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::zero, EXPECT_EQ(BitPatterns::zero,
valueAsBits(__llvm_libc::exp2f(valueFromBits(0xff7fffffU)))); valueAsBits(__llvm_libc::exp2f(valueFromBits(0xff7fffffU))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
float x = valueFromBits(0xc3158000U); float x = valueFromBits(0xc3158000U);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
x = valueFromBits(0xc3165432U); x = valueFromBits(0xc3165432U);
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
} }
TEST(LlvmLibcexp2fTest, InFloatRange) { TEST(LlvmLibcexp2fTest, InFloatRange) {
@ -136,14 +135,14 @@ TEST(LlvmLibcexp2fTest, InFloatRange) {
float x = valueFromBits(v); float x = valueFromBits(v);
if (isnan(x) || isinf(x)) if (isnan(x) || isinf(x))
continue; continue;
llvmlibc_errno = 0; errno = 0;
float result = __llvm_libc::exp2f(x); float result = __llvm_libc::exp2f(x);
// If the computation resulted in an error or did not produce valid result // If the computation resulted in an error or did not produce valid result
// in the single-precision floating point range, then ignore comparing with // in the single-precision floating point range, then ignore comparing with
// MPFR result as MPFR can still produce valid results because of its // MPFR result as MPFR can still produce valid results because of its
// wider precision. // wider precision.
if (isnan(result) || isinf(result) || llvmlibc_errno != 0) if (isnan(result) || isinf(result) || errno != 0)
continue; continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0); ASSERT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
} }

View File

@ -6,8 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "include/errno.h"
#include "src/errno/llvmlibc_errno.h"
#include "src/math/expf.h" #include "src/math/expf.h"
#include "utils/FPUtil/BitPatterns.h" #include "utils/FPUtil/BitPatterns.h"
#include "utils/FPUtil/ClassificationFunctions.h" #include "utils/FPUtil/ClassificationFunctions.h"
@ -17,6 +15,7 @@
#include "utils/UnitTest/Test.h" #include "utils/UnitTest/Test.h"
#include <math.h> #include <math.h>
#include <errno.h>
#include <stdint.h> #include <stdint.h>
using __llvm_libc::fputil::isNegativeQuietNaN; using __llvm_libc::fputil::isNegativeQuietNaN;
@ -29,73 +28,73 @@ using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
namespace mpfr = __llvm_libc::testing::mpfr; namespace mpfr = __llvm_libc::testing::mpfr;
TEST(LlvmLibcExpfTest, SpecialNumbers) { TEST(LlvmLibcExpfTest, SpecialNumbers) {
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE( EXPECT_TRUE(
isQuietNaN(__llvm_libc::expf(valueFromBits(BitPatterns::aQuietNaN)))); isQuietNaN(__llvm_libc::expf(valueFromBits(BitPatterns::aQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::expf(valueFromBits(BitPatterns::aNegativeQuietNaN)))); __llvm_libc::expf(valueFromBits(BitPatterns::aNegativeQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isQuietNaN( EXPECT_TRUE(isQuietNaN(
__llvm_libc::expf(valueFromBits(BitPatterns::aSignallingNaN)))); __llvm_libc::expf(valueFromBits(BitPatterns::aSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::expf(valueFromBits(BitPatterns::aNegativeSignallingNaN)))); __llvm_libc::expf(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::inf)))); valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::inf))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::zero, EXPECT_EQ(BitPatterns::zero,
valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::negInf)))); valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::negInf))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::one, EXPECT_EQ(BitPatterns::one,
valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::zero)))); valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::zero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::expf( EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::expf(
valueFromBits(BitPatterns::negZero)))); valueFromBits(BitPatterns::negZero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
} }
TEST(LlvmLibcExpfTest, Overflow) { TEST(LlvmLibcExpfTest, Overflow) {
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::expf(valueFromBits(0x7f7fffffU)))); valueAsBits(__llvm_libc::expf(valueFromBits(0x7f7fffffU))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::expf(valueFromBits(0x42cffff8U)))); valueAsBits(__llvm_libc::expf(valueFromBits(0x42cffff8U))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::inf, EXPECT_EQ(BitPatterns::inf,
valueAsBits(__llvm_libc::expf(valueFromBits(0x42d00008U)))); valueAsBits(__llvm_libc::expf(valueFromBits(0x42d00008U))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
} }
TEST(LlvmLibcExpfTest, Underflow) { TEST(LlvmLibcExpfTest, Underflow) {
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::zero, EXPECT_EQ(BitPatterns::zero,
valueAsBits(__llvm_libc::expf(valueFromBits(0xff7fffffU)))); valueAsBits(__llvm_libc::expf(valueFromBits(0xff7fffffU))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::zero, EXPECT_EQ(BitPatterns::zero,
valueAsBits(__llvm_libc::expf(valueFromBits(0xc2cffff8U)))); valueAsBits(__llvm_libc::expf(valueFromBits(0xc2cffff8U))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
llvmlibc_errno = 0; errno = 0;
EXPECT_EQ(BitPatterns::zero, EXPECT_EQ(BitPatterns::zero,
valueAsBits(__llvm_libc::expf(valueFromBits(0xc2d00008U)))); valueAsBits(__llvm_libc::expf(valueFromBits(0xc2d00008U))));
EXPECT_EQ(llvmlibc_errno, ERANGE); EXPECT_EQ(errno, ERANGE);
} }
// Test with inputs which are the borders of underflow/overflow but still // Test with inputs which are the borders of underflow/overflow but still
@ -103,22 +102,22 @@ TEST(LlvmLibcExpfTest, Underflow) {
TEST(LlvmLibcExpfTest, Borderline) { TEST(LlvmLibcExpfTest, Borderline) {
float x; float x;
llvmlibc_errno = 0; errno = 0;
x = valueFromBits(0x42affff8U); x = valueFromBits(0x42affff8U);
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0); ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0x42b00008U); x = valueFromBits(0x42b00008U);
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0); ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0xc2affff8U); x = valueFromBits(0xc2affff8U);
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0); ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
x = valueFromBits(0xc2b00008U); x = valueFromBits(0xc2b00008U);
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0); ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
} }
TEST(LlvmLibcExpfTest, InFloatRange) { TEST(LlvmLibcExpfTest, InFloatRange) {
@ -128,14 +127,14 @@ TEST(LlvmLibcExpfTest, InFloatRange) {
float x = valueFromBits(v); float x = valueFromBits(v);
if (isnan(x) || isinf(x)) if (isnan(x) || isinf(x))
continue; continue;
llvmlibc_errno = 0; errno = 0;
float result = __llvm_libc::expf(x); float result = __llvm_libc::expf(x);
// If the computation resulted in an error or did not produce valid result // If the computation resulted in an error or did not produce valid result
// in the single-precision floating point range, then ignore comparing with // in the single-precision floating point range, then ignore comparing with
// MPFR result as MPFR can still produce valid results because of its // MPFR result as MPFR can still produce valid results because of its
// wider precision. // wider precision.
if (isnan(result) || isinf(result) || llvmlibc_errno != 0) if (isnan(result) || isinf(result) || errno != 0)
continue; continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0); ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
} }

View File

@ -6,8 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "include/errno.h"
#include "src/errno/llvmlibc_errno.h"
#include "src/math/sincosf.h" #include "src/math/sincosf.h"
#include "test/src/math/sdcomp26094.h" #include "test/src/math/sdcomp26094.h"
#include "utils/CPP/Array.h" #include "utils/CPP/Array.h"
@ -19,6 +17,7 @@
#include "utils/UnitTest/Test.h" #include "utils/UnitTest/Test.h"
#include <math.h> #include <math.h>
#include <errno.h>
#include <stdint.h> #include <stdint.h>
using __llvm_libc::fputil::isNegativeQuietNaN; using __llvm_libc::fputil::isNegativeQuietNaN;
@ -33,52 +32,52 @@ using __llvm_libc::testing::sdcomp26094Values;
namespace mpfr = __llvm_libc::testing::mpfr; namespace mpfr = __llvm_libc::testing::mpfr;
TEST(LlvmLibcSinCosfTest, SpecialNumbers) { TEST(LlvmLibcSinCosfTest, SpecialNumbers) {
llvmlibc_errno = 0; errno = 0;
float sin, cos; float sin, cos;
__llvm_libc::sincosf(valueFromBits(BitPatterns::aQuietNaN), &sin, &cos); __llvm_libc::sincosf(valueFromBits(BitPatterns::aQuietNaN), &sin, &cos);
EXPECT_TRUE(isQuietNaN(cos)); EXPECT_TRUE(isQuietNaN(cos));
EXPECT_TRUE(isQuietNaN(sin)); EXPECT_TRUE(isQuietNaN(sin));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
__llvm_libc::sincosf(valueFromBits(BitPatterns::aNegativeQuietNaN), &sin, __llvm_libc::sincosf(valueFromBits(BitPatterns::aNegativeQuietNaN), &sin,
&cos); &cos);
EXPECT_TRUE(isNegativeQuietNaN(cos)); EXPECT_TRUE(isNegativeQuietNaN(cos));
EXPECT_TRUE(isNegativeQuietNaN(sin)); EXPECT_TRUE(isNegativeQuietNaN(sin));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
__llvm_libc::sincosf(valueFromBits(BitPatterns::aSignallingNaN), &sin, &cos); __llvm_libc::sincosf(valueFromBits(BitPatterns::aSignallingNaN), &sin, &cos);
EXPECT_TRUE(isQuietNaN(cos)); EXPECT_TRUE(isQuietNaN(cos));
EXPECT_TRUE(isQuietNaN(sin)); EXPECT_TRUE(isQuietNaN(sin));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
__llvm_libc::sincosf(valueFromBits(BitPatterns::aNegativeSignallingNaN), &sin, __llvm_libc::sincosf(valueFromBits(BitPatterns::aNegativeSignallingNaN), &sin,
&cos); &cos);
EXPECT_TRUE(isNegativeQuietNaN(cos)); EXPECT_TRUE(isNegativeQuietNaN(cos));
EXPECT_TRUE(isNegativeQuietNaN(sin)); EXPECT_TRUE(isNegativeQuietNaN(sin));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
__llvm_libc::sincosf(valueFromBits(BitPatterns::zero), &sin, &cos); __llvm_libc::sincosf(valueFromBits(BitPatterns::zero), &sin, &cos);
EXPECT_EQ(BitPatterns::one, valueAsBits(cos)); EXPECT_EQ(BitPatterns::one, valueAsBits(cos));
EXPECT_EQ(BitPatterns::zero, valueAsBits(sin)); EXPECT_EQ(BitPatterns::zero, valueAsBits(sin));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
__llvm_libc::sincosf(valueFromBits(BitPatterns::negZero), &sin, &cos); __llvm_libc::sincosf(valueFromBits(BitPatterns::negZero), &sin, &cos);
EXPECT_EQ(BitPatterns::one, valueAsBits(cos)); EXPECT_EQ(BitPatterns::one, valueAsBits(cos));
EXPECT_EQ(BitPatterns::negZero, valueAsBits(sin)); EXPECT_EQ(BitPatterns::negZero, valueAsBits(sin));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
llvmlibc_errno = 0; errno = 0;
__llvm_libc::sincosf(valueFromBits(BitPatterns::inf), &sin, &cos); __llvm_libc::sincosf(valueFromBits(BitPatterns::inf), &sin, &cos);
EXPECT_TRUE(isQuietNaN(cos)); EXPECT_TRUE(isQuietNaN(cos));
EXPECT_TRUE(isQuietNaN(sin)); EXPECT_TRUE(isQuietNaN(sin));
EXPECT_EQ(llvmlibc_errno, EDOM); EXPECT_EQ(errno, EDOM);
llvmlibc_errno = 0; errno = 0;
__llvm_libc::sincosf(valueFromBits(BitPatterns::negInf), &sin, &cos); __llvm_libc::sincosf(valueFromBits(BitPatterns::negInf), &sin, &cos);
EXPECT_TRUE(isQuietNaN(cos)); EXPECT_TRUE(isQuietNaN(cos));
EXPECT_TRUE(isQuietNaN(sin)); EXPECT_TRUE(isQuietNaN(sin));
EXPECT_EQ(llvmlibc_errno, EDOM); EXPECT_EQ(errno, EDOM);
} }
TEST(LlvmLibcSinCosfTest, InFloatRange) { TEST(LlvmLibcSinCosfTest, InFloatRange) {

View File

@ -6,8 +6,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "include/errno.h"
#include "src/errno/llvmlibc_errno.h"
#include "src/math/sinf.h" #include "src/math/sinf.h"
#include "test/src/math/sdcomp26094.h" #include "test/src/math/sdcomp26094.h"
#include "utils/CPP/Array.h" #include "utils/CPP/Array.h"
@ -19,6 +17,7 @@
#include "utils/UnitTest/Test.h" #include "utils/UnitTest/Test.h"
#include <math.h> #include <math.h>
#include <errno.h>
#include <stdint.h> #include <stdint.h>
using __llvm_libc::fputil::isNegativeQuietNaN; using __llvm_libc::fputil::isNegativeQuietNaN;
@ -33,40 +32,40 @@ using __llvm_libc::testing::sdcomp26094Values;
namespace mpfr = __llvm_libc::testing::mpfr; namespace mpfr = __llvm_libc::testing::mpfr;
TEST(LlvmLibcSinfTest, SpecialNumbers) { TEST(LlvmLibcSinfTest, SpecialNumbers) {
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE( EXPECT_TRUE(
isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::aQuietNaN)))); isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::aQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::sinf(valueFromBits(BitPatterns::aNegativeQuietNaN)))); __llvm_libc::sinf(valueFromBits(BitPatterns::aNegativeQuietNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isQuietNaN( EXPECT_TRUE(isQuietNaN(
__llvm_libc::sinf(valueFromBits(BitPatterns::aSignallingNaN)))); __llvm_libc::sinf(valueFromBits(BitPatterns::aSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_TRUE(isNegativeQuietNaN( EXPECT_TRUE(isNegativeQuietNaN(
__llvm_libc::sinf(valueFromBits(BitPatterns::aNegativeSignallingNaN)))); __llvm_libc::sinf(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::zero, EXPECT_EQ(BitPatterns::zero,
valueAsBits(__llvm_libc::sinf(valueFromBits(BitPatterns::zero)))); valueAsBits(__llvm_libc::sinf(valueFromBits(BitPatterns::zero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(BitPatterns::negZero, valueAsBits(__llvm_libc::sinf( EXPECT_EQ(BitPatterns::negZero, valueAsBits(__llvm_libc::sinf(
valueFromBits(BitPatterns::negZero)))); valueFromBits(BitPatterns::negZero))));
EXPECT_EQ(llvmlibc_errno, 0); EXPECT_EQ(errno, 0);
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE(isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::inf)))); EXPECT_TRUE(isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::inf))));
EXPECT_EQ(llvmlibc_errno, EDOM); EXPECT_EQ(errno, EDOM);
llvmlibc_errno = 0; errno = 0;
EXPECT_TRUE( EXPECT_TRUE(
isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::negInf)))); isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::negInf))));
EXPECT_EQ(llvmlibc_errno, EDOM); EXPECT_EQ(errno, EDOM);
} }
TEST(LlvmLibcSinfTest, InFloatRange) { TEST(LlvmLibcSinfTest, InFloatRange) {