-
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
Reduction mod 2π #2825
Reduction mod 2π #2825
Conversation
numerics/double_precision_body.hpp
Outdated
inline DoublePrecision<Angle> Mod2π(DoublePrecision<Angle> const& θ) { | ||
static DoublePrecision<Angle> const two_π = []() { | ||
return QuickTwoSum(std::scalbn(7074237752028440.0, -50) * Radian, | ||
std::scalbn(4967757600021511.0, -104) * Radian); |
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.
0x1.921FB54442D18p1, 0x1.1A62633145C07p-53
numerics/double_precision_test.cpp
Outdated
@@ -319,6 +319,17 @@ TEST_F(DoublePrecisionTest, LongQuotient) { | |||
AlmostEquals(-7352815717686216.0 * std::pow(0.5, 110), 0)); | |||
} | |||
|
|||
TEST_F(DoublePrecisionTest, Mod2π) { | |||
// Slightly above 2000 π. | |||
DoublePrecision<Angle> a(0x1.88b2f742cdaf5p12 * Radian); |
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.
(2e3 * 103'993 + 2) / 33'102, so we know where this comes from.
numerics/double_precision_test.cpp
Outdated
auto const c = Mod2π(a); | ||
// TODO(egg): The numbers below should be in hex. | ||
EXPECT_THAT(c.value + c.error, | ||
AlmostEquals(0.000059263529049710376886 * Radian, 0)); |
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.
0x1.F12375A5877D6p-15
, and add a comment that this can be computed as
HexLiteral[CorrectlyRound[Mod[CorrectlyRound[(2000 103993 + 2)/33102], 2 π]]]
numerics/double_precision_test.cpp
Outdated
EXPECT_THAT(c.value + c.error, | ||
AlmostEquals(0.000059263529049710376886 * Radian, 0)); | ||
EXPECT_THAT(a.value - 2000 * π * Radian, | ||
AlmostEquals(0.000059263529049710376886 * Radian, 94865450)); |
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.
0x1.F123760000000p-15
,
which is
HexLiteral[
CorrectlyRound[(2000 103993 + 2)/33102] -
CorrectlyRound[2000 CorrectlyRound[π]]]
retest this please |
#2400.