summaryrefslogtreecommitdiff
path: root/src/third_party/s2/util/math/mathutil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/s2/util/math/mathutil.cc')
-rwxr-xr-xsrc/third_party/s2/util/math/mathutil.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/third_party/s2/util/math/mathutil.cc b/src/third_party/s2/util/math/mathutil.cc
index 35ab462027c..7ca3b890f8a 100755
--- a/src/third_party/s2/util/math/mathutil.cc
+++ b/src/third_party/s2/util/math/mathutil.cc
@@ -16,6 +16,19 @@ using std::vector;
#include "base/integral_types.h"
#include "base/logging.h"
+ template <class IntOut, class FloatIn>
+ IntOut MathUtil::Round(FloatIn x) {
+ COMPILE_ASSERT(!MathLimits<FloatIn>::kIsInteger, FloatIn_is_integer);
+ COMPILE_ASSERT(MathLimits<IntOut>::kIsInteger, IntOut_is_not_integer);
+
+ // We don't use sgn(x) below because there is no need to distinguish the
+ // (x == 0) case. Also note that there are specialized faster versions
+ // of this function for Intel processors at the bottom of this file.
+ return static_cast<IntOut>(x < 0 ? (x - 0.5) : (x + 0.5));
+ }
+
+template int MathUtil::Round<int,double>(double x);
+
MathUtil::QuadraticRootType MathUtil::RealRootsForQuadratic(long double a,
long double b,
long double c,