[libc-commits] [libc] [libc][math] Fix overflow shifts for dyadic floats and add skip accuracy option for expm1. (PR #98048)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Mon Jul 8 16:11:38 PDT 2024


================
@@ -260,10 +260,19 @@ LIBC_INLINE constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
     return a;
 
   // Align exponents
-  if (a.exponent > b.exponent)
-    b.shift_right(a.exponent - b.exponent);
-  else if (b.exponent > a.exponent)
-    a.shift_right(b.exponent - a.exponent);
+  if (a.exponent > b.exponent) {
+    size_t shift = static_cast<size_t>(a.exponent - b.exponent);
+    if (shift < Bits)
----------------
michaelrj-google wrote:

would it make sense to have this check in the `shift` functions instead of here?

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


More information about the libc-commits mailing list