-
Notifications
You must be signed in to change notification settings - Fork 69
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
A cube root. #1802
A cube root. #1802
Conversation
|
||
constexpr std::uint64_t C = 0x2A9F7893782DA1CE; | ||
static const __m128d sign_bit = | ||
_mm_castsi128_pd(_mm_cvtsi64_si128(0x8000'0000'0000'0000)); |
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.
In other places we condition the use of intrinsics on some preprocessor symbol and use a slow path otherwise. Should we do the same in this function?
namespace principia { | ||
namespace numerics { | ||
|
||
constexpr std::uint64_t C = 0x2A9F7893782DA1CE; |
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.
No idea what this constant does and how it was computed. Could we have references to some literature in this code?
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.
numerics/cbrt.cpp
Outdated
double const denominator = | ||
(7 * x³ + 42 * abs_y) * x⁶ + (30 * x³ + 2 * abs_y) * y²; | ||
return _mm_cvtsd_f64( | ||
_mm_or_pd(_mm_set_sd(x - numerator / denominator), sign)); |
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.
Is this faster than multiplying by sign?
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.
Yes, but we could gain a cycle by moving this or away from the critical path.
numerics/cbrt_test.cpp
Outdated
|
||
class CubeRootTest : public ::testing::Test { | ||
protected: | ||
static std::uint64_t bits(double const x) { |
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 be Bits
?
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.
Done.
numerics/cbrt.hpp
Outdated
|
||
// Computes ∛y with a maximal error in [0.50005, 0.50022] ULPs; the result is | ||
// incorrectly rounded for approximately 5 inputs per million. | ||
double cbrt(double y); |
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.
Why not Cbrt
?
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.
Done.
numerics/cbrt_test.cpp
Outdated
Eq(-std::numeric_limits<double>::infinity())); | ||
EXPECT_THAT(cbrt(std::numeric_limits<double>::quiet_NaN()), | ||
Truly(&std::isnan<double>)); | ||
EXPECT_THAT(cbrt(-std::numeric_limits<double>::quiet_NaN()), |
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.
What about signalling NaNs?
numerics/cbrt_test.cpp
Outdated
} | ||
|
||
TEST_F(CubeRootTest, ParticularlyBadRounding) { | ||
EXPECT_THAT(cbrt(0x1.14E35E87EA5DFp0), Eq(0x1.06C80FCCA8E18p0)); |
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.
How do we know that it's bad? Could we log some indication of error?
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.
Done.
retest this please |
This is part of the effort on #1760.