[libc-commits] [libc] [libc][math] Implement iscanonical[f|l] as a libc math function (PR #110565)

Shourya Goel via libc-commits libc-commits at lists.llvm.org
Mon Sep 30 13:27:16 PDT 2024


https://github.com/Sh0g0-1758 created https://github.com/llvm/llvm-project/pull/110565

This PR implements the iscanonical function as part of the libc math library. 

The addition of this function is crucial for completing the implementation of remaining math macros, as referenced in #109201

>From 4515515a08fe7663958825e0095b78be357794ed Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:36:21 +0530
Subject: [PATCH 1/4] init

---
 libc/config/linux/aarch64/entrypoints.txt |  3 +++
 libc/config/linux/riscv/entrypoints.txt   |  3 +++
 libc/config/linux/x86_64/entrypoints.txt  |  3 +++
 libc/src/math/CMakeLists.txt              |  4 +++
 libc/src/math/generic/CMakeLists.txt      | 31 +++++++++++++++++++++++
 libc/src/math/generic/iscanonical.cpp     | 22 ++++++++++++++++
 libc/src/math/generic/iscanonicalf.cpp    | 22 ++++++++++++++++
 libc/src/math/generic/iscanonicall.cpp    | 22 ++++++++++++++++
 libc/src/math/iscanonical.h               | 20 +++++++++++++++
 libc/src/math/iscanonicalf.h              | 20 +++++++++++++++
 libc/src/math/iscanonicall.h              | 20 +++++++++++++++
 11 files changed, 170 insertions(+)
 create mode 100644 libc/src/math/generic/iscanonical.cpp
 create mode 100644 libc/src/math/generic/iscanonicalf.cpp
 create mode 100644 libc/src/math/generic/iscanonicall.cpp
 create mode 100644 libc/src/math/iscanonical.h
 create mode 100644 libc/src/math/iscanonicalf.h
 create mode 100644 libc/src/math/iscanonicall.h

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 64fbe1a250c0ba..313f429541a574 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -378,6 +378,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.canonicalize
     libc.src.math.canonicalizef
     libc.src.math.canonicalizel
+    libc.src.math.iscanonical
+    libc.src.math.iscanonicalf
+    libc.src.math.iscanonicall
     libc.src.math.cbrt
     libc.src.math.cbrtf
     libc.src.math.ceil
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index ff3d821c664c5b..7d06774661bd7b 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -377,6 +377,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.canonicalize
     libc.src.math.canonicalizef
     libc.src.math.canonicalizel
+    libc.src.math.iscanonical
+    libc.src.math.iscanonicalf
+    libc.src.math.iscanonicall
     libc.src.math.cbrt
     libc.src.math.cbrtf
     libc.src.math.ceil
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index dd658af3bfb674..3d2a94fe2b1f0c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -377,6 +377,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.canonicalize
     libc.src.math.canonicalizef
     libc.src.math.canonicalizel
+    libc.src.math.iscanonical
+    libc.src.math.iscanonicalf
+    libc.src.math.iscanonicall
     libc.src.math.cbrt
     libc.src.math.cbrtf
     libc.src.math.ceil
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3cba34fc249322..a2c63b4ea70587 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -66,6 +66,10 @@ add_math_entrypoint_object(canonicalizel)
 add_math_entrypoint_object(canonicalizef16)
 add_math_entrypoint_object(canonicalizef128)
 
+add_math_entrypoint_object(iscanonical)
+add_math_entrypoint_object(iscanonicalf)
+add_math_entrypoint_object(iscanonicall)
+
 add_math_entrypoint_object(cbrt)
 add_math_entrypoint_object(cbrtf)
 
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index d0676d03420c68..c1f8856348af28 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -60,6 +60,37 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.basic_operations
 )
 
+add_entrypoint_object(
+  iscanonical
+  SRCS
+    iscanonical.cpp
+  HDRS
+    ../iscanonical.h
+  COMPILE_OPTIONS
+    -O3
+)
+
+add_entrypoint_object(
+  iscanonicalf
+  SRCS
+    iscanonicalf.cpp
+  HDRS
+    ../iscanonicalf.h
+  COMPILE_OPTIONS
+    -O3
+)
+
+add_entrypoint_object(
+  iscanonicall
+  SRCS
+    iscanonicall.cpp
+  HDRS
+    ../iscanonicall.h
+  COMPILE_OPTIONS
+    -O3
+)
+
+
 add_entrypoint_object(
   ceil
   SRCS
diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
new file mode 100644
index 00000000000000..c815778090a44d
--- /dev/null
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of iscanonical function ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/iscanonical.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
+    double temp;
+    if (fputil::canonicalize(temp, x) == 0) return 1;
+    return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
new file mode 100644
index 00000000000000..3e81af2d0ce3e8
--- /dev/null
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of iscanonicalf function ---------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/iscanonicalf.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
+    float temp;
+    if (fputil::canonicalize(temp, x) == 0) return 1;
+    return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
new file mode 100644
index 00000000000000..10bd0e101dae8a
--- /dev/null
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of iscanonicall function ---------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/iscanonicall.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
+    long double temp;
+    if (fputil::canonicalize(temp, x) == 0) return 1;
+    return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/iscanonical.h b/libc/src/math/iscanonical.h
new file mode 100644
index 00000000000000..20f83161d45a89
--- /dev/null
+++ b/libc/src/math/iscanonical.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for iscanonical -------------------*- C++ -*-===//
+//
+// 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_SRC_MATH_ISCANONICAL_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICAL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonical(double x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICAL_H
\ No newline at end of file
diff --git a/libc/src/math/iscanonicalf.h b/libc/src/math/iscanonicalf.h
new file mode 100644
index 00000000000000..4f599e12b1d884
--- /dev/null
+++ b/libc/src/math/iscanonicalf.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for iscanonicalf ------------------*- C++ -*-===//
+//
+// 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_SRC_MATH_ISCANONICALF_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICALF_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonicalf(float x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF_H
\ No newline at end of file
diff --git a/libc/src/math/iscanonicall.h b/libc/src/math/iscanonicall.h
new file mode 100644
index 00000000000000..cb028f0dcbe428
--- /dev/null
+++ b/libc/src/math/iscanonicall.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for iscanonicall ------------------*- C++ -*-===//
+//
+// 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_SRC_MATH_ISCANONICALL_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICALL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonicall(long double x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALL_H
\ No newline at end of file

>From 6f706d15018a80061184b727cdeec68e899137e5 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:36:30 +0530
Subject: [PATCH 2/4] fmt

---
 libc/src/math/generic/iscanonical.cpp  | 7 ++++---
 libc/src/math/generic/iscanonicalf.cpp | 7 ++++---
 libc/src/math/generic/iscanonicall.cpp | 7 ++++---
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
index c815778090a44d..ce2a84ca8d830c 100644
--- a/libc/src/math/generic/iscanonical.cpp
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -14,9 +14,10 @@
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
-    double temp;
-    if (fputil::canonicalize(temp, x) == 0) return 1;
-    return 0;
+  double temp;
+  if (fputil::canonicalize(temp, x) == 0)
+    return 1;
+  return 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
index 3e81af2d0ce3e8..3a84cea06ac0a1 100644
--- a/libc/src/math/generic/iscanonicalf.cpp
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -14,9 +14,10 @@
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
-    float temp;
-    if (fputil::canonicalize(temp, x) == 0) return 1;
-    return 0;
+  float temp;
+  if (fputil::canonicalize(temp, x) == 0)
+    return 1;
+  return 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
index 10bd0e101dae8a..07e9df45ada5d0 100644
--- a/libc/src/math/generic/iscanonicall.cpp
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -14,9 +14,10 @@
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
-    long double temp;
-    if (fputil::canonicalize(temp, x) == 0) return 1;
-    return 0;
+  long double temp;
+  if (fputil::canonicalize(temp, x) == 0)
+    return 1;
+  return 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file

>From aba8c185d7510b7691a42310527e5aef63bbcc14 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:49:03 +0530
Subject: [PATCH 3/4] tests

---
 libc/test/src/math/smoke/CMakeLists.txt       | 39 ++++++++++++
 libc/test/src/math/smoke/IsCanonicalTest.h    | 60 +++++++++++++++++++
 libc/test/src/math/smoke/iscanonical_test.cpp | 13 ++++
 .../test/src/math/smoke/iscanonicalf_test.cpp | 13 ++++
 .../test/src/math/smoke/iscanonicall_test.cpp | 13 ++++
 5 files changed, 138 insertions(+)
 create mode 100644 libc/test/src/math/smoke/IsCanonicalTest.h
 create mode 100644 libc/test/src/math/smoke/iscanonical_test.cpp
 create mode 100644 libc/test/src/math/smoke/iscanonicalf_test.cpp
 create mode 100644 libc/test/src/math/smoke/iscanonicall_test.cpp

diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 9f9203c491d044..5385d571d1a7e1 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -327,6 +327,45 @@ add_fp_unittest(
     libc.src.__support.integer_literals
 )
 
+add_fp_unittest(
+  iscanonical_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    iscanonical_test.cpp
+  HDRS
+    IsCanonicalTest.h
+  DEPENDS
+    libc.src.math.iscanonical
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  iscanonicalf_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    iscanonicalf_test.cpp
+  HDRS
+    IsCanonicalTest.h
+  DEPENDS
+    libc.src.math.iscanonicalf
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  iscanonicall_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    iscanonicall_test.cpp
+  HDRS
+    IsCanonicalTest.h
+  DEPENDS
+    libc.src.math.iscanonicall
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   ceil_test
   SUITE
diff --git a/libc/test/src/math/smoke/IsCanonicalTest.h b/libc/test/src/math/smoke/IsCanonicalTest.h
new file mode 100644
index 00000000000000..7d5a3ccaa7da23
--- /dev/null
+++ b/libc/test/src/math/smoke/IsCanonicalTest.h
@@ -0,0 +1,60 @@
+//===-- Utility class to test iscanonical[f|l] ------------------*- C++ -*-===//
+//
+// 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_TEST_SRC_MATH_SMOKE_ISCANONICALTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISCANONICALTEST_H
+
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "hdr/math_macros.h"
+
+template <typename T>
+class IsCanonicalTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+
+  DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+  typedef int (*IsCanonicalFunc)(T);
+
+  void testSpecialNumbers(IsCanonicalFunc func) {
+    EXPECT_EQ(func(aNaN), 0);
+    EXPECT_EQ(func(neg_aNaN), 0);
+    EXPECT_EQ(func(sNaN), 0);
+    EXPECT_EQ(func(neg_sNaN), 0);
+    EXPECT_EQ(func(inf), 0);
+    EXPECT_EQ(func(neg_inf), 0);
+    EXPECT_EQ(func(min_normal), 0);
+    EXPECT_EQ(func(max_normal), 0);
+    EXPECT_EQ(func(neg_max_normal), 0);
+    EXPECT_EQ(func(min_denormal), 0);
+    EXPECT_EQ(func(neg_min_denormal), 0);
+    EXPECT_EQ(func(max_denormal), 0);
+    EXPECT_EQ(func(zero), 1);
+    EXPECT_EQ(func(neg_zero), 1);
+  }
+
+  void testRoundedNumbers(IsCanonicalFunc func) {
+    EXPECT_EQ(func(T(1.0)), 1);
+    EXPECT_EQ(func(T(-1.0)), 1);
+    EXPECT_EQ(func(T(10.0)), 1);
+    EXPECT_EQ(func(T(-10.0)), 1);
+    EXPECT_EQ(func(T(1234.0)), 1);
+    EXPECT_EQ(func(T(-1234.0)), 1);
+  }
+};
+
+#define LIST_ISCANONICAL_TESTS(T, func)                                        \
+  using LlvmLibcIsCanonicalTest = IsCanonicalTest<T>;                          \
+  TEST_F(LlvmLibcIsCanonicalTest, SpecialNumbers) {                            \
+    testSpecialNumbers(&func);                                                 \
+  }                                                                            \
+  TEST_F(LlvmLibcIsCanonicalTest, RoundedNubmers) { testRoundedNumbers(&func); }
+
+#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISCANONICALTEST_H
\ No newline at end of file
diff --git a/libc/test/src/math/smoke/iscanonical_test.cpp b/libc/test/src/math/smoke/iscanonical_test.cpp
new file mode 100644
index 00000000000000..2dd1c2ac6f0451
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonical_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonical -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "IsCanonicalTest.h"
+
+#include "src/math/iscanonical.h"
+
+LIST_ISCANONICAL_TESTS(double, LIBC_NAMESPACE::iscanonical)
diff --git a/libc/test/src/math/smoke/iscanonicalf_test.cpp b/libc/test/src/math/smoke/iscanonicalf_test.cpp
new file mode 100644
index 00000000000000..eba8688f61f940
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonicalf_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonicalf ----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "IsCanonicalTest.h"
+
+#include "src/math/iscanonicalf.h"
+
+LIST_ISCANONICAL_TESTS(float, LIBC_NAMESPACE::iscanonicalf)
diff --git a/libc/test/src/math/smoke/iscanonicall_test.cpp b/libc/test/src/math/smoke/iscanonicall_test.cpp
new file mode 100644
index 00000000000000..d180bcb7443e54
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonicall_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonicall ----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "IsCanonicalTest.h"
+
+#include "src/math/iscanonicall.h"
+
+LIST_ISCANONICAL_TESTS(long double, LIBC_NAMESPACE::iscanonicall)

>From 2a9c560b8cce6d8b65795dc4d25ad230c218ef64 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:55:22 +0530
Subject: [PATCH 4/4] Updated tests

---
 libc/src/math/generic/iscanonical.cpp      |  2 +-
 libc/src/math/generic/iscanonicalf.cpp     |  2 +-
 libc/src/math/generic/iscanonicall.cpp     |  2 +-
 libc/src/math/iscanonical.h                |  2 +-
 libc/src/math/iscanonicalf.h               |  2 +-
 libc/src/math/iscanonicall.h               |  2 +-
 libc/test/src/math/smoke/IsCanonicalTest.h | 20 ++++++++++----------
 7 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
index ce2a84ca8d830c..6da76a43a1231c 100644
--- a/libc/src/math/generic/iscanonical.cpp
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -20,4 +20,4 @@ LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
   return 0;
 }
 
-} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
index 3a84cea06ac0a1..0662758353aac4 100644
--- a/libc/src/math/generic/iscanonicalf.cpp
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -20,4 +20,4 @@ LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
   return 0;
 }
 
-} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
index 07e9df45ada5d0..29459c7a9ad972 100644
--- a/libc/src/math/generic/iscanonicall.cpp
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -20,4 +20,4 @@ LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
   return 0;
 }
 
-} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/iscanonical.h b/libc/src/math/iscanonical.h
index 20f83161d45a89..14b2d17c8bbe9a 100644
--- a/libc/src/math/iscanonical.h
+++ b/libc/src/math/iscanonical.h
@@ -17,4 +17,4 @@ int iscanonical(double x);
 
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LLVM_LIBC_SRC_MATH_ISCANONICAL_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICAL_H
diff --git a/libc/src/math/iscanonicalf.h b/libc/src/math/iscanonicalf.h
index 4f599e12b1d884..fdb48bc2767be4 100644
--- a/libc/src/math/iscanonicalf.h
+++ b/libc/src/math/iscanonicalf.h
@@ -17,4 +17,4 @@ int iscanonicalf(float x);
 
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF_H
diff --git a/libc/src/math/iscanonicall.h b/libc/src/math/iscanonicall.h
index cb028f0dcbe428..edda6e334f1ab9 100644
--- a/libc/src/math/iscanonicall.h
+++ b/libc/src/math/iscanonicall.h
@@ -17,4 +17,4 @@ int iscanonicall(long double x);
 
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LLVM_LIBC_SRC_MATH_ISCANONICALL_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALL_H
diff --git a/libc/test/src/math/smoke/IsCanonicalTest.h b/libc/test/src/math/smoke/IsCanonicalTest.h
index 7d5a3ccaa7da23..47f21cde335a8f 100644
--- a/libc/test/src/math/smoke/IsCanonicalTest.h
+++ b/libc/test/src/math/smoke/IsCanonicalTest.h
@@ -24,18 +24,18 @@ class IsCanonicalTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   typedef int (*IsCanonicalFunc)(T);
 
   void testSpecialNumbers(IsCanonicalFunc func) {
-    EXPECT_EQ(func(aNaN), 0);
-    EXPECT_EQ(func(neg_aNaN), 0);
+    EXPECT_EQ(func(aNaN), 1);
+    EXPECT_EQ(func(neg_aNaN), 1);
     EXPECT_EQ(func(sNaN), 0);
     EXPECT_EQ(func(neg_sNaN), 0);
-    EXPECT_EQ(func(inf), 0);
-    EXPECT_EQ(func(neg_inf), 0);
-    EXPECT_EQ(func(min_normal), 0);
-    EXPECT_EQ(func(max_normal), 0);
-    EXPECT_EQ(func(neg_max_normal), 0);
-    EXPECT_EQ(func(min_denormal), 0);
-    EXPECT_EQ(func(neg_min_denormal), 0);
-    EXPECT_EQ(func(max_denormal), 0);
+    EXPECT_EQ(func(inf), 1);
+    EXPECT_EQ(func(neg_inf), 1);
+    EXPECT_EQ(func(min_normal), 1);
+    EXPECT_EQ(func(max_normal), 1);
+    EXPECT_EQ(func(neg_max_normal), 1);
+    EXPECT_EQ(func(min_denormal), 1);
+    EXPECT_EQ(func(neg_min_denormal), 1);
+    EXPECT_EQ(func(max_denormal), 1);
     EXPECT_EQ(func(zero), 1);
     EXPECT_EQ(func(neg_zero), 1);
   }



More information about the libc-commits mailing list