Skip to content

Instantly share code, notes, and snippets.

@hgaiser
Last active September 30, 2015 11:08
Show Gist options
  • Save hgaiser/88fc1bfbcdff2fbf54fa to your computer and use it in GitHub Desktop.
Save hgaiser/88fc1bfbcdff2fbf54fa to your computer and use it in GitHub Desktop.
Modifes abs of mongodb to use std::abs
diff --git a/src/third_party/s2/util/math/mathutil.h b/src/third_party/s2/util/math/mathutil.h
index 0515912..8750b57 100755
--- a/src/third_party/s2/util/math/mathutil.h
+++ b/src/third_party/s2/util/math/mathutil.h
@@ -150,8 +150,8 @@ class MathUtil {
// Discriminants below kTolerance in absolute value are considered zero
// because changing the final bit of one of the inputs can change the
// sign of the discriminant.
- const double kTolerance = epsilon * max(fabs(2 * b * b), fabs(4 * a * c));
- return (fabs(discriminant) <= kTolerance);
+ const double kTolerance = epsilon * max(std::abs(long(2 * b * b)), std::abs(long(4 * a * c)));
+ return (std::abs(long(discriminant)) <= kTolerance);
}
// Returns in *r1 and *r2 the roots of a "normal" quadratic equation
@@ -429,7 +429,7 @@ class MathUtil {
// the sine cardinal function
static double Sinc(double x) {
- if (fabs(x) < 1E-8) return 1.0;
+ if (std::abs(long(x)) < 1E-8) return 1.0;
return sin(x) / x;
}
diff --git a/src/third_party/s2/util/math/mathutil.cc b/src/third_party/s2/util/math/mathutil.cc
index 10be916..e908dfd 100755
--- a/src/third_party/s2/util/math/mathutil.cc
+++ b/src/third_party/s2/util/math/mathutil.cc
@@ -118,7 +118,7 @@ bool MathUtil::RealRootsForCubic(long double const a,
}
long double const A =
- -sgn(R) * pow(fabs(R) + sqrt(R_squared - Q_cubed), 1.0/3.0L);
+ -sgn(R) * pow(std::abs(long(R)) + sqrt(R_squared - Q_cubed), 1.0/3.0L);
if (A != 0.0) { // in which case, B from NR is zero
*r1 = A + Q / A - a_third;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment