[libc-commits] [libc] [llvm] [libc][math] Move hypot to shared/math and make it constexpr (PR #177588)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Thu Jan 29 18:54:47 PST 2026
================
@@ -88,6 +88,28 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::rsqrtf(1.0f));
}
+// Add this AFTER the AllFloat test block
+TEST(LlvmLibcSharedMathTest, Hypot) {
+ // 1. Basic Pythagorean triples (Runtime check)
+ // We use EXPECT_FP_EQ for safe floating-point comparison
+ EXPECT_FP_EQ(5.0, LIBC_NAMESPACE::math::hypot(3.0, 4.0));
+ EXPECT_FP_EQ(13.0, LIBC_NAMESPACE::math::hypot(5.0, 12.0));
+
+ // 2. Compile-time check (Constexpr)
+ // This verifies your "header-only" logic works at compile time
+ constexpr double result = LIBC_NAMESPACE::math::hypot(3.0, 4.0);
+ static_assert(result == 5.0, "Constexpr hypot failed");
+
+ // 3. Special values (Inf/NaN)
+ constexpr double inf = __builtin_inf();
+ constexpr double nan = __builtin_nan("");
+
+ // Use EXPECT_NE(..., 0) because __builtin functions return int, not bool
+ EXPECT_NE(__builtin_isinf(LIBC_NAMESPACE::math::hypot(inf, 1.0)), 0);
+ EXPECT_NE(__builtin_isinf(LIBC_NAMESPACE::math::hypot(1.0, inf)), 0);
+ EXPECT_NE(__builtin_isnan(LIBC_NAMESPACE::math::hypot(nan, 1.0)), 0);
+}
+
----------------
bassiounix wrote:
Not resolved
https://github.com/llvm/llvm-project/pull/177588
More information about the libc-commits
mailing list