-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Use libm implementations in exp for complex numbers #165457
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
Open
nurmukhametov
wants to merge
5
commits into
llvm:main
Choose a base branch
from
nurmukhametov:use-libm-implementations-in-complex-exp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5
−16
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11c9295
[libc++] Use libm implementations in exp for complex numbers
nurmukhametov bda7bce
WIP: preserve original implementation in case when libm can't provide…
nurmukhametov 3670d79
WIP: fix formatting
nurmukhametov 84147ee
Revert "WIP: preserve original implementation in case when libm can't…
nurmukhametov 3bfc2f1
Remove test for accuracy of exp for complex numbers
nurmukhametov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <complex> | ||
|
|
||
| // template<class T> | ||
| // complex<T> | ||
| // exp(const complex<T>& x); | ||
|
|
||
| #include <complex> | ||
| #include <cassert> | ||
| #include <cmath> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| template <class T> | ||
| void test_overflow_case() { | ||
| typedef std::complex<T> C; | ||
|
|
||
| // In this case, the overflow of exp(real_part) is compensated when | ||
| // sin(imag_part) is close to zero, resulting in a finite imaginary part. | ||
| C z(T(90.0238094), T(5.900613e-39)); | ||
| C result = std::exp(z); | ||
|
|
||
| assert(std::isinf(result.real())); | ||
| assert(result.real() > 0); | ||
|
|
||
| assert(std::isfinite(result.imag())); | ||
| assert(std::abs(result.imag() - T(7.3746)) < T(1.0)); | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| test_overflow_case<float>(); | ||
| return 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We generally try to avoid these kinds of shenanigans. Why is this required?
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.
This is required when libm is missing these functions. If they are missing, we can fall back to the old implementation, which is not using builtin_cexp functions. At least one build configuration encounters this issue: Android 5.0 x86.
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 have removed these shenanigans. After that, there are following fails in CI:
Android 5.0, x86 NDK, because underlying libc doesn't provide cexp.std\numerics\complex.number\complex.transcendentals\exp.pass.cppfor some windows and macos jobs.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 think we should guard calling the libc version behind
!defined(__ANDROID__) || __ANDROID_API__ >= 23. It's quite unfortunate, but I expect support for older android version will be dropped somewhat soon, so it's likely just temporary (CC @pirama-arumuga-nainar @Sharjeel-Khan maybe you know more?). The errors inside the test will have to be looked at. My guess is that the test is simply wrong, but I don't know for certain.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.
We will raise the minimum supported version to API 23 next year in NDK r31 as seen in android/ndk#2188. The Android 5 builder is based on API 21 so it should get dropped . We were using it mostly for 32-bit checks I believe so I might have to find another image to replace it.
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.
(cc: @DanAlbert )