[libc-commits] [libc] [libc][math] Add POSIX math constants to math.h header. (PR #149150)

via libc-commits libc-commits at lists.llvm.org
Wed Jul 16 10:48:42 PDT 2025


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/149150

https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/math.h.html

>From eece7705e75abf701c4af458068cd066e905b9f9 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Wed, 16 Jul 2025 17:46:35 +0000
Subject: [PATCH] [libc][math] Add POSIX math constants to math.h header.

---
 libc/include/llvm-libc-macros/math-macros.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 2f05d7544666e..5195292c7db58 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -50,4 +50,25 @@
 #define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
 #endif
 
+// POSIX math constants
+// https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/math.h.html
+#define M_E (__extension__ 0x1.5bf0a8b145769p1)
+#define M_EGAMMA (__extension__ 0x1.2788cfc6fb619p-1)
+#define M_LOG2E (__extension__ 0x1.71547652b82fep0)
+#define M_LOG10E (__extension__ 0x1.bcb7b1526e50ep-2)
+#define M_LN2 (__extension__ 0x1.62e42fefa39efp-1)
+#define M_LN10 (__extension__ 0x1.26bb1bbb55516p1)
+#define M_PHI (__extension__ 0x1.9e3779b97f4a8p0)
+#define M_PI (__extension__ 0x1.921fb54442d18p1)
+#define M_PI_2 (__extension__ 0x1.921fb54442d18p0)
+#define M_PI_4 (__extension__ 0x1.921fb54442d18p-1)
+#define M_1_PI (__extension__ 0x1.45f306dc9c883p-2)
+#define M_1_SQRTPI (__extension__ 0x1.20dd750429b6dp-1)
+#define M_2_PI (__extension__ 0x1.45f306dc9c883p-1)
+#define M_2_SQRTPI (__extension__ 0x1.20dd750429b6dp0)
+#define M_SQRT2 (__extension__ 0x1.6a09e667f3bcdp0)
+#define M_SQRT3 (__extension__ 0x1.bb67ae8584caap0)
+#define M_SQRT1_2 (__extension__ 0x1.6a09e667f3bcdp-1)
+#define M_SQRT1_3 (__extension__ 0x1.279a74590331cp-1)
+
 #endif // LLVM_LIBC_MACROS_MATH_MACROS_H



More information about the libc-commits mailing list