-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc][math] Implement double precision expm1 function correctly rounded for all rounding modes. #67048
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM from the libc side, with minor nits.
|
||
#include <errno.h> | ||
|
||
// #define DEBUGDEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to leave the debug code in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found myself retyping these debug codes quite many times, and I couldn't find a better place to share this type of debugging codes yet. So I think I should leave it at least in one function so that a simple copy paste during development of other functions would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
libc/test/src/math/expm1_test.cpp
Outdated
0x3FD79289C6E6A5C0, | ||
0x3FD05DE80A173EA0, // 0x1.05de80a173eap-2 | ||
0xbf1eb7a4cb841fcc, // -0x1.eb7a4cb841fccp-14 | ||
0xbf19a61fb925970d, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this one have a comment on its value as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
✅ With the latest revision this PR passed the C/C++ code formatter. |
looks good to me. All core-math tests do pass for all 4 rounding modes, and efficiency is quite good:
(first timings are for core-math, last for llvm) |
…ded for all rounding modes. (llvm#67048) Implementing expm1 function for double precision based on exp function algorithm: - Reduced x = log2(e) * (hi + mid1 + mid2) + lo, where: * hi is an integer * mid1 * 2^-6 is an integer * mid2 * 2^-12 is an integer * |lo| < 2^-13 + 2^-30 - Then exp(x) - 1 = 2^hi * 2^mid1 * 2^mid2 * exp(lo) - 1 ~ 2^hi * (2^mid1 * 2^mid2 * (1 + lo * P(lo)) - 2^(-hi) ) - We evaluate fast pass with P(lo) is a degree-3 Taylor polynomial of (e^lo - 1) / lo in double precision - If the Ziv accuracy test fails, we use degree-6 Taylor polynomial of (e^lo - 1) / lo in double double precision - If the Ziv accuracy test still fails, we re-evaluate everything in 128-bit precision.
Implementing expm1 function for double precision based on exp function algorithm: