This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Improve accuracy of complex asinh and acosh
ClosedPublic

Authored by miyuki on Dec 29 2017, 5:38 AM.

Details

Summary

Currently std::asinh and std::acosh use std::pow to compute x^2. This
results in a significant error when computing e.g. asinh(i) or
acosh(-1).

This patch expresses x^2 directly via x.real() and x.imag(), like it
is done in libstdc++/glibc, and adds tests that checks the accuracy.

Diff Detail

Repository
rCXX libc++

Event Timeline

miyuki created this revision.Dec 29 2017, 5:38 AM
miyuki added inline comments.Jan 3 2018, 5:26 PM
test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp
59

Ideally, I would prefer some approximate comparison instead of == here, but is_about is not suitable for arguments that have zero or near-zero sum. That's why I used exact comparison (several other cases in this file do the same). This test passes on x86_64, so hopefully it will work the same way in any IEEE-compliant environment.

This all looks good to me.
I think that one more test should be added - and that's one that tests __sqr directly.
Since that's not a public routine, the test should go in "test/libcxx/numerics/complex.number"

miyuki updated this revision to Diff 133408.Feb 8 2018, 5:55 AM

Added a test for __sqr

mclow.lists accepted this revision.Feb 17 2018, 6:03 PM

LGTM. Do you need me to commit this?

This revision is now accepted and ready to land.Feb 17 2018, 6:03 PM

No, I'll commit it myself. Thank you for the review.

This revision was automatically updated to reflect the committed changes.