[libc-commits] [libc] eb56bc2 - [libc] Remove specific nan payload in math functions (#79165)

via libc-commits libc-commits at lists.llvm.org
Mon Jan 29 06:28:50 PST 2024


Author: Guillaume Chatelet
Date: 2024-01-29T15:28:46+01:00
New Revision: eb56bc2b105c792bafd36ef35c0e6eda9f0b822e

URL: https://github.com/llvm/llvm-project/commit/eb56bc2b105c792bafd36ef35c0e6eda9f0b822e
DIFF: https://github.com/llvm/llvm-project/commit/eb56bc2b105c792bafd36ef35c0e6eda9f0b822e.diff

LOG: [libc] Remove specific nan payload in math functions (#79165)

Added: 
    

Modified: 
    libc/src/math/generic/asinf.cpp
    libc/src/math/generic/sincosf.cpp
    libc/test/UnitTest/FPMatcher.h
    libc/test/src/__support/FPUtil/fpbits_test.cpp
    libc/test/src/stdio/sprintf_test.cpp
    libc/test/src/stdio/sscanf_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/math/generic/asinf.cpp b/libc/src/math/generic/asinf.cpp
index ee8e853063644ee..7655aabb72101fa 100644
--- a/libc/src/math/generic/asinf.cpp
+++ b/libc/src/math/generic/asinf.cpp
@@ -109,7 +109,7 @@ LLVM_LIBC_FUNCTION(float, asinf, (float x)) {
       fputil::set_errno_if_required(EDOM);
       fputil::raise_except_if_required(FE_INVALID);
     }
-    return x + FPBits::build_nan(Sign::POS, FPBits::FRACTION_MASK).get_val();
+    return FPBits::build_quiet_nan().get_val();
   }
 
   // Check for exceptional values

diff  --git a/libc/src/math/generic/sincosf.cpp b/libc/src/math/generic/sincosf.cpp
index f12b93a0e69653b..52f2323b435491f 100644
--- a/libc/src/math/generic/sincosf.cpp
+++ b/libc/src/math/generic/sincosf.cpp
@@ -148,9 +148,7 @@ LLVM_LIBC_FUNCTION(void, sincosf, (float x, float *sinp, float *cosp)) {
       fputil::set_errno_if_required(EDOM);
       fputil::raise_except_if_required(FE_INVALID);
     }
-    *sinp =
-        x +
-        FPBits::build_nan(fputil::Sign::POS, FPBits::FRACTION_MASK).get_val();
+    *sinp = FPBits::build_quiet_nan().get_val();
     *cosp = *sinp;
     return;
   }

diff  --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index 69da5387d382b56..7c81475ecec3aea 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -69,7 +69,7 @@ template <typename T> struct FPTest : public Test {
   static constexpr T zero = FPBits::zero(Sign::POS).get_val();
   static constexpr T neg_zero = FPBits::zero(Sign::NEG).get_val();
   static constexpr T aNaN = FPBits::build_quiet_nan().get_val();
-  static constexpr T sNaN = FPBits::build_nan(Sign::POS, 1).get_val();
+  static constexpr T sNaN = FPBits::build_nan().get_val();
   static constexpr T inf = FPBits::inf(Sign::POS).get_val();
   static constexpr T neg_inf = FPBits::inf(Sign::NEG).get_val();
   static constexpr T min_normal = FPBits::min_normal().get_val();
@@ -98,7 +98,7 @@ template <typename T> struct FPTest : public Test {
   const T zero = FPBits::zero(Sign::POS).get_val();                            \
   const T neg_zero = FPBits::zero(Sign::NEG).get_val();                        \
   const T aNaN = FPBits::build_quiet_nan().get_val();                          \
-  const T sNaN = FPBits::build_nan(Sign::POS, 1).get_val();                    \
+  const T sNaN = FPBits::build_nan().get_val();                                \
   const T inf = FPBits::inf(Sign::POS).get_val();                              \
   const T neg_inf = FPBits::inf(Sign::NEG).get_val();                          \
   const T min_normal = FPBits::min_normal().get_val();                         \

diff  --git a/libc/test/src/__support/FPUtil/fpbits_test.cpp b/libc/test/src/__support/FPUtil/fpbits_test.cpp
index aadcd3fe92b9e54..a4324a071536f84 100644
--- a/libc/test/src/__support/FPUtil/fpbits_test.cpp
+++ b/libc/test/src/__support/FPUtil/fpbits_test.cpp
@@ -236,8 +236,7 @@ TEST(LlvmLibcFPBitsTest, FloatType) {
                "(+Infinity)");
   EXPECT_STREQ(LIBC_NAMESPACE::str(FloatBits::inf(Sign::NEG)).c_str(),
                "(-Infinity)");
-  EXPECT_STREQ(LIBC_NAMESPACE::str(FloatBits::build_nan(Sign::POS, 1)).c_str(),
-               "(NaN)");
+  EXPECT_STREQ(LIBC_NAMESPACE::str(FloatBits::build_nan()).c_str(), "(NaN)");
 
   FloatBits zero(0.0f);
   EXPECT_TRUE(zero.is_pos());
@@ -363,9 +362,8 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {
                "(+Infinity)");
   EXPECT_STREQ(LIBC_NAMESPACE::str(LongDoubleBits::inf(Sign::NEG)).c_str(),
                "(-Infinity)");
-  EXPECT_STREQ(
-      LIBC_NAMESPACE::str(LongDoubleBits::build_nan(Sign::POS, 1)).c_str(),
-      "(NaN)");
+  EXPECT_STREQ(LIBC_NAMESPACE::str(LongDoubleBits::build_nan()).c_str(),
+               "(NaN)");
 
   LongDoubleBits zero(0.0l);
   EXPECT_TRUE(zero.is_pos());
@@ -444,9 +442,8 @@ TEST(LlvmLibcFPBitsTest, LongDoubleType) {
                "(+Infinity)");
   EXPECT_STREQ(LIBC_NAMESPACE::str(LongDoubleBits::inf(Sign::NEG)).c_str(),
                "(-Infinity)");
-  EXPECT_STREQ(
-      LIBC_NAMESPACE::str(LongDoubleBits::build_nan(Sign::POS, 1)).c_str(),
-      "(NaN)");
+  EXPECT_STREQ(LIBC_NAMESPACE::str(LongDoubleBits::build_nan()).c_str(),
+               "(NaN)");
 
   LongDoubleBits zero(0.0l);
   EXPECT_TRUE(zero.is_pos());
@@ -519,9 +516,7 @@ TEST(LlvmLibcFPBitsTest, Float128Type) {
                "(+Infinity)");
   EXPECT_STREQ(LIBC_NAMESPACE::str(Float128Bits::inf(Sign::NEG)).c_str(),
                "(-Infinity)");
-  EXPECT_STREQ(
-      LIBC_NAMESPACE::str(Float128Bits::build_nan(Sign::POS, 1)).c_str(),
-      "(NaN)");
+  EXPECT_STREQ(LIBC_NAMESPACE::str(Float128Bits::build_nan()).c_str(), "(NaN)");
 
   Float128Bits zero = Float128Bits::zero(Sign::POS);
   EXPECT_TRUE(zero.is_pos());

diff  --git a/libc/test/src/stdio/sprintf_test.cpp b/libc/test/src/stdio/sprintf_test.cpp
index 07501ac751fa309..70cacf01a2f991c 100644
--- a/libc/test/src/stdio/sprintf_test.cpp
+++ b/libc/test/src/stdio/sprintf_test.cpp
@@ -586,9 +586,8 @@ TEST(LlvmLibcSPrintfTest, OctConv) {
 TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
   ForceRoundingMode r(RoundingMode::Nearest);
   double inf = LIBC_NAMESPACE::fputil::FPBits<double>::inf().get_val();
-  double nan = LIBC_NAMESPACE::fputil::FPBits<double>::build_nan(
-                   LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                   .get_val();
+  double nan =
+      LIBC_NAMESPACE::fputil::FPBits<double>::build_quiet_nan().get_val();
   written = LIBC_NAMESPACE::sprintf(buff, "%a", 1.0);
   ASSERT_STREQ_LEN(written, buff, "0x1p+0");
 
@@ -952,14 +951,12 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
 TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
   ForceRoundingMode r(RoundingMode::Nearest);
   double inf = LIBC_NAMESPACE::fputil::FPBits<double>::inf().get_val();
-  double nan = LIBC_NAMESPACE::fputil::FPBits<double>::build_nan(
-                   LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                   .get_val();
+  double nan =
+      LIBC_NAMESPACE::fputil::FPBits<double>::build_quiet_nan().get_val();
   long double ld_inf =
       LIBC_NAMESPACE::fputil::FPBits<long double>::inf().get_val();
-  long double ld_nan = LIBC_NAMESPACE::fputil::FPBits<long double>::build_nan(
-                           LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                           .get_val();
+  long double ld_nan =
+      LIBC_NAMESPACE::fputil::FPBits<long double>::build_quiet_nan().get_val();
 
   char big_buff[10000]; // Used for long doubles and other extremely wide
                         // numbers.
@@ -1808,9 +1805,8 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalLongDoubleConv) {
 TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
   ForceRoundingMode r(RoundingMode::Nearest);
   double inf = LIBC_NAMESPACE::fputil::FPBits<double>::inf().get_val();
-  double nan = LIBC_NAMESPACE::fputil::FPBits<double>::build_nan(
-                   LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                   .get_val();
+  double nan =
+      LIBC_NAMESPACE::fputil::FPBits<double>::build_quiet_nan().get_val();
 
   written = LIBC_NAMESPACE::sprintf(buff, "%e", 1.0);
   ASSERT_STREQ_LEN(written, buff, "1.000000e+00");
@@ -2417,9 +2413,8 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentLongDoubleConv) {
 TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
   ForceRoundingMode r(RoundingMode::Nearest);
   double inf = LIBC_NAMESPACE::fputil::FPBits<double>::inf().get_val();
-  double nan = LIBC_NAMESPACE::fputil::FPBits<double>::build_nan(
-                   LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                   .get_val();
+  double nan =
+      LIBC_NAMESPACE::fputil::FPBits<double>::build_quiet_nan().get_val();
 
   written = LIBC_NAMESPACE::sprintf(buff, "%g", 1.0);
   ASSERT_STREQ_LEN(written, buff, "1");

diff  --git a/libc/test/src/stdio/sscanf_test.cpp b/libc/test/src/stdio/sscanf_test.cpp
index db67c25029133c1..abfdb338323dcbb 100644
--- a/libc/test/src/stdio/sscanf_test.cpp
+++ b/libc/test/src/stdio/sscanf_test.cpp
@@ -231,9 +231,8 @@ TEST(LlvmLibcSScanfTest, FloatConvSimple) {
   float result = 0;
 
   float inf = LIBC_NAMESPACE::fputil::FPBits<float>::inf().get_val();
-  float nan = LIBC_NAMESPACE::fputil::FPBits<float>::build_nan(
-                  LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                  .get_val();
+  float nan =
+      LIBC_NAMESPACE::fputil::FPBits<float>::build_quiet_nan().get_val();
 
   ret_val = LIBC_NAMESPACE::sscanf("123", "%f", &result);
   EXPECT_EQ(ret_val, 1);
@@ -297,9 +296,8 @@ TEST(LlvmLibcSScanfTest, FloatConvLengthModifier) {
   long double ld_result = 0;
 
   double d_inf = LIBC_NAMESPACE::fputil::FPBits<double>::inf().get_val();
-  long double ld_nan = LIBC_NAMESPACE::fputil::FPBits<long double>::build_nan(
-                           LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                           .get_val();
+  long double ld_nan =
+      LIBC_NAMESPACE::fputil::FPBits<long double>::build_quiet_nan().get_val();
 
   ret_val = LIBC_NAMESPACE::sscanf("123", "%lf", &d_result);
   EXPECT_EQ(ret_val, 1);
@@ -395,9 +393,8 @@ TEST(LlvmLibcSScanfTest, FloatConvComplexParsing) {
   float result = 0;
 
   float inf = LIBC_NAMESPACE::fputil::FPBits<float>::inf().get_val();
-  float nan = LIBC_NAMESPACE::fputil::FPBits<float>::build_nan(
-                  LIBC_NAMESPACE::fputil::Sign::POS, 1)
-                  .get_val();
+  float nan =
+      LIBC_NAMESPACE::fputil::FPBits<float>::build_quiet_nan().get_val();
 
   ret_val = LIBC_NAMESPACE::sscanf("0x1.0e3", "%f", &result);
   EXPECT_EQ(ret_val, 1);


        


More information about the libc-commits mailing list