[libc-commits] [libc] [libc][math] Adding LIBC_MATH_ASSUME_ROUND_NEAREST_ONLY option (PR #201154)

Hoàng Minh Thiên via libc-commits libc-commits at lists.llvm.org
Wed Jun 10 20:53:28 PDT 2026


================
@@ -46,6 +46,18 @@ rounding_direction(const LIBC_NAMESPACE::UInt<Bits> &value, size_t rshift,
       (rshift >= Bits && value == 0))
     return 0; // exact
 
+#ifdef LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
+  if (rshift > 0 && rshift <= Bits && value.get_bit(rshift - 1)) {
+    // We round up, unless the value is an exact halfway case and
+    // the bit that will end up in the units place is 0, in which
+    // case tie-break-to-even says round down.
+    bool round_bit = rshift < Bits ? value.get_bit(rshift) : 0;
+    return round_bit != 0 || (value << (Bits - rshift + 1)) != 0 ? +1 : -1;
+  } else {
+    return -1;
+  }
+#endif
----------------
hmthien050209 wrote:

Done

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


More information about the libc-commits mailing list