[libc-commits] [libc] [libc][math] implement `signbit` (PR #97791)

via libc-commits libc-commits at lists.llvm.org
Fri Jul 5 20:43:36 PDT 2024


https://github.com/akielaries updated https://github.com/llvm/llvm-project/pull/97791

>From 88aa30aaa0c94cbbbd729d641299d4711ac1b3d6 Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Thu, 4 Jul 2024 21:12:58 -0700
Subject: [PATCH 1/9] [libc][math] adding scaffolding for solving #96322

---
 .../llvm-libc-macros/generic-math-macros.h    | 20 +++++++++++
 libc/include/llvm-libc-macros/genmv           |  0
 libc/include/llvm-libc-macros/math-macros.h   |  5 ---
 .../test/include/generic-math-macros_test.cpp | 34 +++++++++++++++++++
 4 files changed, 54 insertions(+), 5 deletions(-)
 create mode 100644 libc/include/llvm-libc-macros/generic-math-macros.h
 create mode 100644 libc/include/llvm-libc-macros/genmv
 create mode 100644 libc/test/include/generic-math-macros_test.cpp

diff --git a/libc/include/llvm-libc-macros/generic-math-macros.h b/libc/include/llvm-libc-macros/generic-math-macros.h
new file mode 100644
index 0000000000000..8fec2cc6c02ea
--- /dev/null
+++ b/libc/include/llvm-libc-macros/generic-math-macros.h
@@ -0,0 +1,20 @@
+//===-- Definition of macros from math.h ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_GENERIC_MATH_MACROS_H
+#define LLVM_LIBC_MACROS_GENERIC_MATH_MACROS_H
+
+#define isfinite(x) __builtin_isfinite(x)
+#define isinf(x) __builtin_isinf(x)
+#define isnan(x) __builtin_isnan(x)
+#define signbit(x) \
+    ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
+    : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
+    : __builtin_signbitl(x))
+
+#endif // LLVM_LIBC_MACROS_GENERIC_MATH_MACROS_H
diff --git a/libc/include/llvm-libc-macros/genmv b/libc/include/llvm-libc-macros/genmv
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 47838969d59ae..bcda32a615b62 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -51,9 +51,4 @@
 #define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
 #endif
 
-// TODO: Move generic functional math macros to a separate header file.
-#define isfinite(x) __builtin_isfinite(x)
-#define isinf(x) __builtin_isinf(x)
-#define isnan(x) __builtin_isnan(x)
-
 #endif // LLVM_LIBC_MACROS_MATH_MACROS_H
diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
new file mode 100644
index 0000000000000..d988ec3110fba
--- /dev/null
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -0,0 +1,34 @@
+//===-- Unittests for stdbit ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "test/UnitTest/Test.h"
+
+/*
+ * The intent of this test is validate that the generic math macros operate as
+ * intended
+ */
+
+#include "stdbit_stub.h"
+
+#include "include/llvm-libc-macros/generic-math-macros.h"
+
+TEST(LlvmLibcIsfinite, TypeGenericMacroMathIsfinite) {
+
+}
+
+TEST(LlvmLibcIsinf, TypeGenericMacroMathIsinf) {
+
+}
+
+TEST(LlvmLibcIsnan, TypeGenericMacroMathIsnan) {
+
+}
+
+TEST(LlvmLibcSignbit, TypeGenericMacroMathSignbit) {
+
+}

>From f3c51abcb303baa3daa1f91055b9fe39eb8f75d9 Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Thu, 4 Jul 2024 21:13:21 -0700
Subject: [PATCH 2/9] [libc][math] adding scaffolding for solving #96322

---
 libc/include/llvm-libc-macros/genmv | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 libc/include/llvm-libc-macros/genmv

diff --git a/libc/include/llvm-libc-macros/genmv b/libc/include/llvm-libc-macros/genmv
deleted file mode 100644
index e69de29bb2d1d..0000000000000

>From 06eb1e293e5e74294aaef6498f9bb46e2d13267a Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Thu, 4 Jul 2024 23:00:20 -0700
Subject: [PATCH 3/9] [libc][math] adding additional scaffolding while
 compiling source

---
 libc/test/include/CMakeLists.txt               | 12 ++++++++++++
 libc/test/include/generic-math-macros_test.cpp | 17 ++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 03c31855e352b..6cae50eb0e82c 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -68,6 +68,18 @@ if(LLVM_LIBC_FULL_BUILD AND libc.include.stdbit IN_LIST TARGET_PUBLIC_HEADERS)
       # of the underlying functions which the type generic macros may dispatch
       # to.
   )
+  add_libc_test(
+    generic_math_test
+    SUITE
+      libc_include_tests
+    # HRDS
+    SRCS
+      generic-math-macros_test.cpp
+    DEPENDS
+      libc.include.llvm-libc-macros.generic_math_macros
+      libc.include.llvm-libc-macros.stdbit_macros
+      libc.include.llvm_libc_common_h
+  )
 endif()
 
 add_libc_test(
diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
index d988ec3110fba..cd31aa64d0436 100644
--- a/libc/test/include/generic-math-macros_test.cpp
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -13,22 +13,25 @@
  * intended
  */
 
-#include "stdbit_stub.h"
+// #include "stdbit_stub.h"
 
 #include "include/llvm-libc-macros/generic-math-macros.h"
 
-TEST(LlvmLibcIsfinite, TypeGenericMacroMathIsfinite) {
-
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsfinite) {
+  EXPECT_EQ(isfinite(3.14), 0);
+  EXPECT_EQ(isfinite(3.14 / 0.0), 1);
 }
 
-TEST(LlvmLibcIsinf, TypeGenericMacroMathIsinf) {
+/*
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsinf) {
 
 }
 
-TEST(LlvmLibcIsnan, TypeGenericMacroMathIsnan) {
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsnan) {
 
 }
 
-TEST(LlvmLibcSignbit, TypeGenericMacroMathSignbit) {
 
-}
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathSignbit) {
+
+}*/

>From da15670fa70d08a9626c122bb31a1d0bd206941b Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Fri, 5 Jul 2024 11:08:54 -0700
Subject: [PATCH 4/9] [libc][math] adding generic math macros header and test
 to CMake build system. verifying 1 case for now

---
 libc/include/llvm-libc-macros/CMakeLists.txt  |  6 +++++
 libc/test/include/CMakeLists.txt              | 23 +++++++++----------
 .../test/include/generic-math-macros_test.cpp |  6 ++---
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index f6af11abd4dd7..666b6337ddf37 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -277,3 +277,9 @@ add_macro_header(
   HDR
     stdckdint-macros.h
 )
+
+add_macro_header(
+  generic_math_macros
+  HDR
+    generic-math-macros.h
+)
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 6cae50eb0e82c..52fa9b230f289 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -68,18 +68,6 @@ if(LLVM_LIBC_FULL_BUILD AND libc.include.stdbit IN_LIST TARGET_PUBLIC_HEADERS)
       # of the underlying functions which the type generic macros may dispatch
       # to.
   )
-  add_libc_test(
-    generic_math_test
-    SUITE
-      libc_include_tests
-    # HRDS
-    SRCS
-      generic-math-macros_test.cpp
-    DEPENDS
-      libc.include.llvm-libc-macros.generic_math_macros
-      libc.include.llvm-libc-macros.stdbit_macros
-      libc.include.llvm_libc_common_h
-  )
 endif()
 
 add_libc_test(
@@ -91,3 +79,14 @@ add_libc_test(
   DEPENDS
     libc.include.llvm-libc-macros.stdckdint_macros
 )
+
+add_libc_test(
+  generic_math_macros_test
+  SUITE
+    libc_include_tests
+  SRCS
+    generic-math-macros_test.cpp
+  DEPENDS
+    libc.include.llvm-libc-macros.generic_math_macros
+)
+
diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
index cd31aa64d0436..42712f22f335b 100644
--- a/libc/test/include/generic-math-macros_test.cpp
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -13,13 +13,13 @@
  * intended
  */
 
-// #include "stdbit_stub.h"
+#include "stdbit_stub.h"
 
 #include "include/llvm-libc-macros/generic-math-macros.h"
 
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsfinite) {
-  EXPECT_EQ(isfinite(3.14), 0);
-  EXPECT_EQ(isfinite(3.14 / 0.0), 1);
+  EXPECT_EQ(isfinite(3.14), 1);
+  EXPECT_EQ(isfinite(3.14 / 0.0), 0);
 }
 
 /*

>From 665d0df8b61a03c6c4c8d769edca173f93abf44b Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Fri, 5 Jul 2024 16:15:25 -0700
Subject: [PATCH 5/9] [libc][math] adding valuable test cases. working on
 cleanup

---
 .../test/include/generic-math-macros_test.cpp | 46 ++++++++++++++++---
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
index 42712f22f335b..9be7f2c3cc40e 100644
--- a/libc/test/include/generic-math-macros_test.cpp
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -12,26 +12,60 @@
  * The intent of this test is validate that the generic math macros operate as
  * intended
  */
+#include "include/llvm-libc-macros/generic-math-macros.h"
 
-#include "stdbit_stub.h"
 
-#include "include/llvm-libc-macros/generic-math-macros.h"
+// INF can be defined as a number with zeroed out mantissa and 1s in the 
+// exponent
+static uint32_t positive_infinity = 0x7F800000;
+static uint32_t negative_infinity = 0xFF800000;
+static const float pos_inf = *(float *) &positive_infinity;
+static const float neg_inf = *(float *) &negative_infinity;
+
+// NaN can be defined as a number with all 1s in the exponent
+static uint32_t positive_nan = 0x7F800001;
+static uint32_t negative_nan = 0xFF800001;
+static const float pos_nan = *(float *) &positive_nan;
+static const float neg_nan = *(float *) &negative_nan;
+
+/*
+ * As with IEEE 754-1985, the biased-exponent field is filled with all 1 bits 
+ * to indicate either infinity (trailing significand field = 0) or a NaN 
+ * (trailing significand field ≠ 0)
+ */
 
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsfinite) {
   EXPECT_EQ(isfinite(3.14), 1);
   EXPECT_EQ(isfinite(3.14 / 0.0), 0);
+  EXPECT_EQ(isfinite(pos_inf), 0);
+  EXPECT_EQ(isfinite(neg_inf), 0);
+  EXPECT_EQ(isfinite(pos_nan), 0);
+  EXPECT_EQ(isfinite(neg_nan), 0);
 }
 
-/*
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsinf) {
-
+  EXPECT_EQ(isinf(3.14), 0);
+  EXPECT_EQ(isinf(pos_inf), 1);
+  EXPECT_EQ(isinf(neg_inf), 1);
+  EXPECT_EQ(isnan(0.0 * pos_inf), 1);   // multiply 0 by infinity
+  EXPECT_EQ(isinf(3.14 / 0.0), 1);      // division by 0
+  EXPECT_EQ(isnan(3.14 / pos_inf), 0);  // division by infinity
 }
 
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsnan) {
-
+  EXPECT_EQ(isnan(3.14), 0);
+  EXPECT_EQ(isnan(pos_nan), 1);
+  EXPECT_EQ(isnan(neg_nan), 1);
+  EXPECT_EQ(isnan(0.0 * pos_inf), 1);     // multiply 0 by infinity
+  EXPECT_EQ(isnan(3.14 / 0.0), 0);        // division by 0
+  EXPECT_EQ(isnan(3.14 / pos_inf), 0);    // division by infinity
+  EXPECT_EQ(isnan(pos_inf / neg_inf), 1); // pos infinity / neg infinity
 }
 
-
+/*
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathSignbit) {
+  // float
+
+  // double
 
 }*/

>From aa9bdff2be9929e75cd06e6a083064975f26af0e Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Fri, 5 Jul 2024 17:07:16 -0700
Subject: [PATCH 6/9] [libc][math] editing test cases

---
 .../test/include/generic-math-macros_test.cpp | 33 ++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
index 9be7f2c3cc40e..1c41bfccc573e 100644
--- a/libc/test/include/generic-math-macros_test.cpp
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -14,7 +14,6 @@
  */
 #include "include/llvm-libc-macros/generic-math-macros.h"
 
-
 // INF can be defined as a number with zeroed out mantissa and 1s in the 
 // exponent
 static uint32_t positive_infinity = 0x7F800000;
@@ -28,6 +27,13 @@ static uint32_t negative_nan = 0xFF800001;
 static const float pos_nan = *(float *) &positive_nan;
 static const float neg_nan = *(float *) &negative_nan;
 
+#define PI 3.14159265358979323846
+#define CASE_DIV_BY_ZERO            PI / 0.0
+#define CASE_DIV_BY_POS_INF         PI / pos_inf
+#define CASE_DIV_BY_NEG_INF         PI / neg_inf
+#define CASE_MULT_ZERO_BY_POS_INF   0 * pos_inf
+#define CASE_MULT_ZERO_BY_NEG_INF   0 * neg_inf
+
 /*
  * As with IEEE 754-1985, the biased-exponent field is filled with all 1 bits 
  * to indicate either infinity (trailing significand field = 0) or a NaN 
@@ -35,31 +41,34 @@ static const float neg_nan = *(float *) &negative_nan;
  */
 
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsfinite) {
-  EXPECT_EQ(isfinite(3.14), 1);
-  EXPECT_EQ(isfinite(3.14 / 0.0), 0);
   EXPECT_EQ(isfinite(pos_inf), 0);
   EXPECT_EQ(isfinite(neg_inf), 0);
   EXPECT_EQ(isfinite(pos_nan), 0);
   EXPECT_EQ(isfinite(neg_nan), 0);
+  EXPECT_EQ(isfinite(CASE_DIV_BY_ZERO), 0);
+  EXPECT_EQ(isfinite(PI), 1);
 }
 
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsinf) {
-  EXPECT_EQ(isinf(3.14), 0);
+  EXPECT_EQ(isinf(PI), 0);
+  EXPECT_EQ(isinf(CASE_DIV_BY_POS_INF), 0);
+  EXPECT_EQ(isinf(CASE_DIV_BY_NEG_INF), 0);
+  EXPECT_EQ(isinf(CASE_MULT_ZERO_BY_POS_INF), 0);
+  EXPECT_EQ(isinf(CASE_MULT_ZERO_BY_NEG_INF), 0);
   EXPECT_EQ(isinf(pos_inf), 1);
   EXPECT_EQ(isinf(neg_inf), 1);
-  EXPECT_EQ(isnan(0.0 * pos_inf), 1);   // multiply 0 by infinity
-  EXPECT_EQ(isinf(3.14 / 0.0), 1);      // division by 0
-  EXPECT_EQ(isnan(3.14 / pos_inf), 0);  // division by infinity
+  EXPECT_EQ(isinf(CASE_DIV_BY_ZERO), 1);
 }
 
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsnan) {
-  EXPECT_EQ(isnan(3.14), 0);
+  EXPECT_EQ(isnan(PI), 0);
+  EXPECT_EQ(isnan(CASE_DIV_BY_POS_INF), 0);
+  EXPECT_EQ(isnan(CASE_DIV_BY_NEG_INF), 0);
   EXPECT_EQ(isnan(pos_nan), 1);
   EXPECT_EQ(isnan(neg_nan), 1);
-  EXPECT_EQ(isnan(0.0 * pos_inf), 1);     // multiply 0 by infinity
-  EXPECT_EQ(isnan(3.14 / 0.0), 0);        // division by 0
-  EXPECT_EQ(isnan(3.14 / pos_inf), 0);    // division by infinity
-  EXPECT_EQ(isnan(pos_inf / neg_inf), 1); // pos infinity / neg infinity
+  EXPECT_EQ(isnan(CASE_MULT_ZERO_BY_POS_INF), 1);
+  EXPECT_EQ(isnan(CASE_MULT_ZERO_BY_NEG_INF), 1);
+  EXPECT_EQ(isnan(pos_inf / neg_inf), 1);
 }
 
 /*

>From c955ec1743c72c545680c828199199f042d7dbbb Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Fri, 5 Jul 2024 17:44:17 -0700
Subject: [PATCH 7/9] [libc][math] adding cases for `signbit` for `float`,
 `double`, and `long double` types

---
 libc/test/include/CMakeLists.txt               |  1 -
 libc/test/include/generic-math-macros_test.cpp | 17 ++++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 52fa9b230f289..7a805fc3a2e66 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -89,4 +89,3 @@ add_libc_test(
   DEPENDS
     libc.include.llvm-libc-macros.generic_math_macros
 )
-
diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
index 1c41bfccc573e..d7b37c7ba4e8b 100644
--- a/libc/test/include/generic-math-macros_test.cpp
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -62,6 +62,7 @@ TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsinf) {
 
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsnan) {
   EXPECT_EQ(isnan(PI), 0);
+  EXPECT_EQ(isnan(CASE_DIV_BY_ZERO), 0);
   EXPECT_EQ(isnan(CASE_DIV_BY_POS_INF), 0);
   EXPECT_EQ(isnan(CASE_DIV_BY_NEG_INF), 0);
   EXPECT_EQ(isnan(pos_nan), 1);
@@ -71,10 +72,16 @@ TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsnan) {
   EXPECT_EQ(isnan(pos_inf / neg_inf), 1);
 }
 
-/*
 TEST(LlvmLibcGenericMath, TypeGenericMacroMathSignbit) {
-  // float
-
-  // double
+  EXPECT_EQ(signbit(static_cast<float>(PI)), 0);
+  EXPECT_EQ(signbit(static_cast<double>(PI)), 0);
+  EXPECT_EQ(signbit(static_cast<long double>(PI)), 0);
+  EXPECT_EQ(signbit(pos_inf), 0);
+  EXPECT_EQ(signbit(pos_nan), 0);
 
-}*/
+  EXPECT_EQ(signbit(static_cast<float>(-PI)), 1);
+  EXPECT_EQ(signbit(static_cast<double>(-PI)), 1);
+  EXPECT_EQ(signbit(static_cast<long double>(-PI)), 1);
+  EXPECT_EQ(signbit(neg_inf), 1);
+  EXPECT_EQ(signbit(neg_nan), 1);
+}

>From 724633d588354b4bc868ab9852467d623c137872 Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Fri, 5 Jul 2024 17:52:05 -0700
Subject: [PATCH 8/9] [libc][math] fixing typo

---
 libc/test/include/generic-math-macros_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
index d7b37c7ba4e8b..6adbc029c9f92 100644
--- a/libc/test/include/generic-math-macros_test.cpp
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for stdbit ----------------------------------------------===//
+//===-- Unittests for generic-math-macros ---------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

>From 118feda796b579659ce65c0ed8569bbe50c009cf Mon Sep 17 00:00:00 2001
From: akielaries <akiel at akiel.org>
Date: Fri, 5 Jul 2024 20:43:13 -0700
Subject: [PATCH 9/9] [libc][math] clarity around inf and nan definitions in
 `generic-math-macros_test.cpp`

---
 libc/test/include/generic-math-macros_test.cpp | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
index 6adbc029c9f92..651bc8e507e01 100644
--- a/libc/test/include/generic-math-macros_test.cpp
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -16,16 +16,16 @@
 
 // INF can be defined as a number with zeroed out mantissa and 1s in the 
 // exponent
-static uint32_t positive_infinity = 0x7F800000;
-static uint32_t negative_infinity = 0xFF800000;
-static const float pos_inf = *(float *) &positive_infinity;
-static const float neg_inf = *(float *) &negative_infinity;
+static uint32_t pos_inf_bits = 0x7F800000;
+static uint32_t neg_inf_bits = 0xFF800000;
+static const float pos_inf = *(float *) &pos_inf_bits;
+static const float neg_inf = *(float *) &neg_inf_bits;
 
 // NaN can be defined as a number with all 1s in the exponent
-static uint32_t positive_nan = 0x7F800001;
-static uint32_t negative_nan = 0xFF800001;
-static const float pos_nan = *(float *) &positive_nan;
-static const float neg_nan = *(float *) &negative_nan;
+static uint32_t pos_nan_bits = 0x7F800001;
+static uint32_t neg_nan_bits = 0xFF800001;
+static const float pos_nan = *(float *) &pos_nan_bits;
+static const float neg_nan = *(float *) &neg_nan_bits;
 
 #define PI 3.14159265358979323846
 #define CASE_DIV_BY_ZERO            PI / 0.0



More information about the libc-commits mailing list