[libc-commits] [libc] [libc][math] Fixed Hypotbf16 build failure. (PR #186415)

via libc-commits libc-commits at lists.llvm.org
Fri Mar 13 08:47:35 PDT 2026


https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/186415

>From 2ea6ef46ed7bfe8fd5ff0062d10815e7af57ed62 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 13 Mar 2026 20:54:02 +0530
Subject: [PATCH 1/4] fix: added static_cast

---
 libc/src/__support/FPUtil/Hypot.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index e23f8b52d8220..699d1cab7ba1c 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -219,7 +219,7 @@ LIBC_INLINE T hypot(T x, T y) {
   for (StorageType current_bit = leading_one >> 1; current_bit;
        current_bit >>= 1) {
     r = static_cast<StorageType>((r << 1)) +
-        ((tail_bits & current_bit) ? 1 : 0);
+        static_cast<StorageType>((tail_bits & current_bit) ? 1 : 0);
     StorageType tmp = static_cast<StorageType>((y_new << 1)) +
                       current_bit; // 2*y_new(n - 1) + 2^(-n)
     if (r >= tmp) {

>From 13a073cb20984a1b32057355676f02dcdc7602cd Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 13 Mar 2026 21:10:44 +0530
Subject: [PATCH 2/4] fix: proper storageType

---
 libc/src/__support/FPUtil/Hypot.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index 699d1cab7ba1c..5d10035b1199e 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -218,8 +218,7 @@ LIBC_INLINE T hypot(T x, T y) {
 
   for (StorageType current_bit = leading_one >> 1; current_bit;
        current_bit >>= 1) {
-    r = static_cast<StorageType>((r << 1)) +
-        static_cast<StorageType>((tail_bits & current_bit) ? 1 : 0);
+    r = static_cast<StorageType>((r << 1) + (tail_bits & current_bit) ? 1 : 0);
     StorageType tmp = static_cast<StorageType>((y_new << 1)) +
                       current_bit; // 2*y_new(n - 1) + 2^(-n)
     if (r >= tmp) {

>From 9f9087207f2f052681b78c96bdd9e7496d46c49b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 13 Mar 2026 21:13:45 +0530
Subject: [PATCH 3/4] nit

---
 libc/src/__support/FPUtil/Hypot.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index 5d10035b1199e..e0d295471fbf6 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -218,7 +218,7 @@ LIBC_INLINE T hypot(T x, T y) {
 
   for (StorageType current_bit = leading_one >> 1; current_bit;
        current_bit >>= 1) {
-    r = static_cast<StorageType>((r << 1) + (tail_bits & current_bit) ? 1 : 0);
+    r = static_cast<StorageType>((r << 1) + ((tail_bits & current_bit) ? 1 : 0));
     StorageType tmp = static_cast<StorageType>((y_new << 1)) +
                       current_bit; // 2*y_new(n - 1) + 2^(-n)
     if (r >= tmp) {

>From ee95c3ed7eb003e88f96a267abebbf48158471a7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 13 Mar 2026 21:17:18 +0530
Subject: [PATCH 4/4] nit

---
 libc/src/__support/FPUtil/Hypot.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index e0d295471fbf6..292140065c754 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -218,7 +218,8 @@ LIBC_INLINE T hypot(T x, T y) {
 
   for (StorageType current_bit = leading_one >> 1; current_bit;
        current_bit >>= 1) {
-    r = static_cast<StorageType>((r << 1) + ((tail_bits & current_bit) ? 1 : 0));
+    r = static_cast<StorageType>((r << 1) +
+                                 ((tail_bits & current_bit) ? 1 : 0));
     StorageType tmp = static_cast<StorageType>((y_new << 1)) +
                       current_bit; // 2*y_new(n - 1) + 2^(-n)
     if (r >= tmp) {



More information about the libc-commits mailing list