-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<complex>: Improve numerical accuracy of sqrt and log #935
<complex>: Improve numerical accuracy of sqrt and log #935
Conversation
3530c76
to
962917c
Compare
962917c
to
5d43a74
Compare
Modifies the scale factors in `_Fabs` (used by `sqrt`) such that: - `_Fabs` doesn't underflow when the input is tiny. - `sqrt` doesn't overflow when the input is huge.
When |z| is close to 1, compute log(|z|) as log1p(norm_minus_1(z)) / 2, where norm_minus_1(z) = real(z) ^ 2 + imag(z) ^ 2 - 1 computed with double width arithmetic to avoid catastrophic cancellation.
5d43a74
to
a6a5934
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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 looks good to me! 😺 I'll validate and push changes for a number of superficial issues that I noticed, nothing affecting the core logic.
tests/std/tests/GH_000935_complex_numerical_accuracy/floating_point_utils.hpp
Outdated
Show resolved
Hide resolved
tests/std/tests/GH_000935_complex_numerical_accuracy/log_test_cases.hpp
Outdated
Show resolved
Hide resolved
tests/std/tests/GH_000935_complex_numerical_accuracy/log_test_cases.hpp
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
I've pushed a change for compatibility with our internal test harness - it doesn't contain the same option-parsing machinery that the Python/lit test harness does, so it attempts to use ARM64-only options on x86 and x64 (and vice versa). Unfortunately, significant changes are needed to be compatible with |
I've pushed a merge, resolving conflicts with the test harness rewrite. The This doesn't do anything about |
Changelog
|
Thanks again for these accuracy improvements and bug fixes! 🎯 😸 This will ship in VS 2019 16.9 Preview 3. |
Goals:
sqrt
overflow when input is huge.sqrt
inaccuracy when input is tiny, due to internal underflow.log
inaccuracy when input is tiny, due to internal underflow.log
when |z| ≈ 1, and fixlog(complex<float>{1, 0}) != 0
under certain combinations of compile time and runtime settings. (DevCom-1093507 is a symptom of the inaccuracy. It is itself non-bug.)arm/arm64 when available.The changes contain algorithm described in W. Kahan (1987), Branch Cuts for Complex Elementary Functions, or Much Ado About Nothing's Sign Bit.