Conversation
|
@llvm/pr-subscribers-libc Author: None (lntue) Changeshttps://pubs.opengroup.org/onlinepubs/9799919799/basedefs/math.h.html Full diff: https://github.com/llvm/llvm-project/pull/149150.diff 1 Files Affected:
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
|
|
|
|
What about |
I've added |
frobtech
left a comment
There was a problem hiding this comment.
lgtm. Eventually I want to get all the macros properly listed in math.yaml and for ones like these their values could easily be defined directly there. But we can do that as a later refactor.
It would be good to have at least nominal tests for these too. All the tests really need to do is verify the type of each expression, e.g.
static_cast(std::is_same_v<double, decltype(M_PI)>);
etc. I don't know if it's worthwhile doing value checks with e.g. comparing some trig function's value where the input constant is something trivial like 0,1,-1.
I added a unit test for M_PI in the test/include folder. |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/38600 Here is the relevant piece of the build log for the reference |
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/math.h.html