Skip to content
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

Merged
merged 2 commits into from
Dec 29, 2020
Merged

Reduction mod 2π #2825

merged 2 commits into from
Dec 29, 2020

Conversation

pleroy
Copy link
Member

@pleroy pleroy commented Dec 28, 2020

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);
Copy link
Member

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

@@ -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);
Copy link
Member

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.

Sorry, something went wrong.

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));
Copy link
Member

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 π]]]

Sorry, something went wrong.

EXPECT_THAT(c.value + c.error,
AlmostEquals(0.000059263529049710376886 * Radian, 0));
EXPECT_THAT(a.value - 2000 * π * Radian,
AlmostEquals(0.000059263529049710376886 * Radian, 94865450));
Copy link
Member

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[π]]]

@eggrobin eggrobin added the LGTM label Dec 28, 2020
@pleroy
Copy link
Member Author

pleroy commented Dec 29, 2020

retest this please

@pleroy pleroy merged commit 8fde9a6 into mockingbirdnest:master Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants