[libc-commits] [libc] [libc][math] Fix MPI_OVER_2 constant in atan2f_float (PR #205621)
Prabhu Rajasekaran via libc-commits
libc-commits at lists.llvm.org
Wed Jun 24 10:59:18 PDT 2026
https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/205621
Fix a typo in the size-optimized float-float implementation of atan2f
where MPI_OVER_2 (-pi/2) was defined identically to PI_OVER_2 (pi/2).
This caused atan2f to return incorrect values (off by pi) on targets
where the float-float path is selected (e.g. baremetal ARM Cortex-M
with hardware FMA/floating-point support) for inputs requiring
reciprocal range reduction, such as atan2f(10.0f, 1.0f).
>From 2173859964983f3ecead445411cad479005e9d80 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 24 Jun 2026 10:58:23 -0700
Subject: [PATCH] [libc][math] Fix MPI_OVER_2 constant in atan2f_float
Fix a typo in the size-optimized float-float implementation of atan2f
where MPI_OVER_2 (-pi/2) was defined identically to PI_OVER_2 (pi/2).
This caused atan2f to return incorrect values (off by pi) on targets
where the float-float path is selected (e.g. baremetal ARM Cortex-M
with hardware FMA/floating-point support) for inputs requiring
reciprocal range reduction, such as atan2f(10.0f, 1.0f).
---
libc/src/__support/math/atan2f_float.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/math/atan2f_float.h b/libc/src/__support/math/atan2f_float.h
index 1f44b67749964..744783e855cef 100644
--- a/libc/src/__support/math/atan2f_float.h
+++ b/libc/src/__support/math/atan2f_float.h
@@ -134,7 +134,7 @@ LIBC_INLINE constexpr float atan2f(float y, float x) {
constexpr FloatFloat MPI = {0x1.777a5cp-24f, -0x1.921fb6p1f};
constexpr FloatFloat PI_OVER_4 = {-0x1.777a5cp-26f, 0x1.921fb6p-1f};
constexpr FloatFloat PI_OVER_2 = {-0x1.777a5cp-25f, 0x1.921fb6p0f};
- constexpr FloatFloat MPI_OVER_2 = {-0x1.777a5cp-25f, 0x1.921fb6p0f};
+ constexpr FloatFloat MPI_OVER_2 = {0x1.777a5cp-25f, -0x1.921fb6p0f};
constexpr FloatFloat THREE_PI_OVER_4 = {-0x1.99bc5cp-28f, 0x1.2d97c8p1f};
// Adjustment for constant term:
// CONST_ADJ[x_sign][y_sign][recip]
More information about the libc-commits
mailing list