[libc-commits] [libc] 6a863f7 - [libc] Fix signed zeros for exp10m1f16 and tanhf16. (#116654)

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


Author: lntue
Date: 2024-11-18T15:44:32-05:00
New Revision: 6a863f7e2679a60f2f38ae6a920d0b6e1a2c1690

URL: https://github.com/llvm/llvm-project/commit/6a863f7e2679a60f2f38ae6a920d0b6e1a2c1690
DIFF: https://github.com/llvm/llvm-project/commit/6a863f7e2679a60f2f38ae6a920d0b6e1a2c1690.diff

LOG: [libc] Fix signed zeros for exp10m1f16 and tanhf16. (#116654)

Added: 
    

Modified: 
    libc/src/math/generic/exp10m1f16.cpp
    libc/src/math/generic/tanhf16.cpp

Removed: 
    


################################################################################
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();

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