[llvm] [libc][math] Implement double precision expm1 function correctly rounded for all rounding modes. (PR #67048)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 12:20:58 PDT 2023


github-actions[bot] wrote:


<!--LLVM CODE FORMAT COMMENT: {clang-format}-->

:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 8fb28e45ce043eb8869da139cf58ac2602d3bafa 0b9a9151bdc61df1e613da5a14da8d68ddaa1ccd -- libc/src/math/expm1.h libc/src/math/generic/expm1.cpp libc/test/src/math/expm1_test.cpp libc/test/src/math/smoke/expm1_test.cpp libc/src/__support/FPUtil/FPBits.h libc/src/__support/FPUtil/except_value_utils.h libc/src/math/generic/exp.cpp libc/src/math/generic/expm1f.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/src/__support/FPUtil/except_value_utils.h b/libc/src/__support/FPUtil/except_value_utils.h
index 70318048643b..49e8e40f062e 100644
--- a/libc/src/__support/FPUtil/except_value_utils.h
+++ b/libc/src/__support/FPUtil/except_value_utils.h
@@ -100,16 +100,14 @@ template <typename T, size_t N> struct ExceptValues {
 };
 
 // Helper functions to set results for exceptional cases.
-template<typename T>
-LIBC_INLINE T round_result_slightly_down(T value_rn) {
+template <typename T> LIBC_INLINE T round_result_slightly_down(T value_rn) {
   volatile T tmp = value_rn;
   constexpr T MIN_NORMAL = FPBits<T>::min_normal().get_val();
   tmp = tmp - MIN_NORMAL;
   return tmp;
 }
 
-template <typename T>
-LIBC_INLINE T round_result_slightly_up(T value_rn) {
+template <typename T> LIBC_INLINE T round_result_slightly_up(T value_rn) {
   volatile T tmp = value_rn;
   const T MIN_NORMAL = FPBits<T>::min_normal().get_val();
   tmp = tmp + MIN_NORMAL;
diff --git a/libc/src/math/generic/expm1f.cpp b/libc/src/math/generic/expm1f.cpp
index 0d384a20e5a7..7ae00beb5c64 100644
--- a/libc/src/math/generic/expm1f.cpp
+++ b/libc/src/math/generic/expm1f.cpp
@@ -111,11 +111,13 @@ LLVM_LIBC_FUNCTION(float, expm1f, (float x)) {
 #endif // LIBC_TARGET_CPU_HAS_FMA
     }
 
-    constexpr double COEFFS[] = {
-        0x1p-1, 0x1.55555555557ddp-3, 0x1.55555555552fap-5,
-                         0x1.111110fcd58b7p-7, 0x1.6c16c1717660bp-10,
-                         0x1.a0241f0006d62p-13, 0x1.a01e3f8d3c06p-16
-    };
+    constexpr double COEFFS[] = {0x1p-1,
+                                 0x1.55555555557ddp-3,
+                                 0x1.55555555552fap-5,
+                                 0x1.111110fcd58b7p-7,
+                                 0x1.6c16c1717660bp-10,
+                                 0x1.a0241f0006d62p-13,
+                                 0x1.a01e3f8d3c06p-16};
 
     // 2^-25 <= |x| < 2^-4
     double xd = static_cast<double>(x);
@@ -123,7 +125,7 @@ LLVM_LIBC_FUNCTION(float, expm1f, (float x)) {
     // Degree-8 minimax polynomial generated by Sollya with:
     // > display = hexadecimal;
     // > P = fpminimax((expm1(x) - x)/x^2, 6, [|D...|], [-2^-4, 2^-4]);
-    
+
     double c0 = fputil::multiply_add(xd, COEFFS[1], COEFFS[0]);
     double c1 = fputil::multiply_add(xd, COEFFS[3], COEFFS[2]);
     double c2 = fputil::multiply_add(xd, COEFFS[5], COEFFS[4]);

``````````

</details>


https://github.com/llvm/llvm-project/pull/67048


More information about the llvm-commits mailing list