Skip to content

Commit

Permalink
Some cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
pleroy committed Oct 14, 2024
1 parent 3c03b6d commit d7937bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 5 additions & 5 deletions functions/sin_cos_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST_F(SinCosTest, Random) {
#if _DEBUG
static constexpr std::int64_t iterations = 100;
#else
static constexpr std::int64_t iterations = 4'000'000;
static constexpr std::int64_t iterations = 1'000'000;
#endif

for (std::int64_t i = 0; i < iterations; ++i) {
Expand Down Expand Up @@ -80,10 +80,10 @@ TEST_F(SinCosTest, Random) {
}

// This implementation is not quite correctly rounded, but not far from it.
EXPECT_LE(max_sin_ulps_error, 0.500002);
EXPECT_LE(max_cos_ulps_error, 0.500002);
EXPECT_LE(incorrectly_rounded_sin, 1);
EXPECT_LE(incorrectly_rounded_cos, 1);
EXPECT_LE(max_sin_ulps_error, 0.5);
EXPECT_LE(max_cos_ulps_error, 0.5);
EXPECT_EQ(incorrectly_rounded_sin, 0);
EXPECT_EQ(incorrectly_rounded_cos, 0);

LOG(ERROR) << "Sin error: " << max_sin_ulps_error << std::setprecision(25)
<< " ulps for argument: " << worst_sin_argument
Expand Down
11 changes: 7 additions & 4 deletions numerics/sin_cos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ double FusedMultiplyAdd(double const a, double const b, double const c) {
}
}

//TODO(phl) comment
double DetectDangerousRounding(double const x, double const dx) {
double const value = x + dx;
double const error = (value - x) - dx;
// Evaluates the sum `x + Δx`. If that sum has a dangerous rounding
// configuration (that is, the bits after the last mantissa bit of the sum are
// either 1000... or 0111..., then return `NaN`. Otherwise returns the sum.
double DetectDangerousRounding(double const x, double const Δx) {
DoublePrecision<double> const sum = QuickTwoSum(x, Δx);
double const& value = sum.value;
double const& error = sum.error;
__m128i const value_exponent_128i =
_mm_castpd_si128(_mm_and_pd(masks::exponent_bits, _mm_set_sd(value)));
double const value_exponent =
Expand Down

0 comments on commit d7937bf

Please sign in to comment.