[libc-commits] [libc] [libc][math][c23] Add acospif16() function (PR #134664)

via libc-commits libc-commits at lists.llvm.org
Thu Apr 17 06:07:26 PDT 2025


================
@@ -70,6 +70,25 @@ MPFRNumber MPFRNumber::acosh() const {
   return result;
 }
 
+MPFRNumber MPFRNumber::acospi() const {
+  MPFRNumber result(*this);
+
+#if MPFR_VERSION_MAJOR > 4 ||                                                  \
+    (MPFR_VERSION_MAJOR == 4 && MPFR_VERSION_MINOR >= 2)
+  mpfr_acospi(result.value, value, mpfr_rounding);
+  return result;
+#else
+  if (result.is_nan()) {
+    return result;
+  }
+  mpfr_acos(result.value, value, mpfr_rounding);
+  MPFRNumber value_pi(0.0, 1280);
+  mpfr_const_pi(value_pi.value, MPFR_RNDN);
+  mpfr_div(result.value, value, value_pi.value, mpfr_rounding);
+  return result;
----------------
overmighty wrote:

The following code works. However, it's ~10x slower than `mpfr_acospi()`.

```suggestion
  MPFRNumber value_acos(0.0, 1280);
  mpfr_acos(value_acos.value, value, MPFR_RNDN);
  MPFRNumber value_pi(0.0, 1280);
  mpfr_const_pi(value_pi.value, MPFR_RNDN);
  mpfr_div(result.value, value_acos.value, value_pi.value, mpfr_rounding);
  return result;
```

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


More information about the libc-commits mailing list