[libc-commits] [libc] [libc] Fix signed zeros for exp10m1f16. (PR #116654)

via libc-commits libc-commits at lists.llvm.org
Mon Nov 18 09:12:42 PST 2024


https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/116654

>From 3edd9139c70f491cb3ce9c3a9bf1c9625397e69a Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Mon, 18 Nov 2024 11:53:39 -0500
Subject: [PATCH 1/2] [libc] Fix signed zeros for exp10m1f16.

---
 libc/src/math/generic/exp10m1f16.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libc/src/math/generic/exp10m1f16.cpp b/libc/src/math/generic/exp10m1f16.cpp
index 9f2c1959fa5ec9..449aedf254ca50 100644
--- a/libc/src/math/generic/exp10m1f16.cpp
+++ b/libc/src/math/generic/exp10m1f16.cpp
@@ -119,6 +119,9 @@ LLVM_LIBC_FUNCTION(float16, exp10m1f16, (float16 x)) {
 
     // When |x| <= 2^(-3).
     if (x_abs <= 0x3000U) {
+      if (LIBC_UNLIKELY(x_abs == 0))
+        return x;
+
       if (auto r = EXP10M1F16_EXCEPTS_LO.lookup(x_u);
           LIBC_UNLIKELY(r.has_value()))
         return r.value();

>From 698bd5fd843d52cc38d441d1decd2da5635fb156 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Mon, 18 Nov 2024 12:12:16 -0500
Subject: [PATCH 2/2] Fix signed zeros for tanhf16.

---
 libc/src/math/generic/tanhf16.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libc/src/math/generic/tanhf16.cpp b/libc/src/math/generic/tanhf16.cpp
index ae9b4be46f7cff..0266b5cfc2df1d 100644
--- a/libc/src/math/generic/tanhf16.cpp
+++ b/libc/src/math/generic/tanhf16.cpp
@@ -64,6 +64,9 @@ LLVM_LIBC_FUNCTION(float16, tanhf16, (float16 x)) {
 
     // When |x| <= 0x1.d2p-4.
     if (x_abs <= 0x2f48U) {
+      if (LIBC_UNLIKELY(x_abs == 0))
+        return x;
+
       float xf = x;
       float xf_sq = xf * xf;
       // Degree-7 Taylor expansion generated by Sollya with the following



More information about the libc-commits mailing list