summaryrefslogtreecommitdiff
path: root/src/mbgl/util/math.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/util/math.hpp')
-rw-r--r--src/mbgl/util/math.hpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mbgl/util/math.hpp b/src/mbgl/util/math.hpp
index f969ecaedd..eb3c7d0fde 100644
--- a/src/mbgl/util/math.hpp
+++ b/src/mbgl/util/math.hpp
@@ -106,5 +106,18 @@ T smoothstep(T edge0, T edge1, T x) {
return t * t * (T(3) - T(2) * t);
}
+template <typename T>
+inline T division(const T dividend, const T divisor, const T nan) {
+ if (divisor == 0) {
+ if (dividend == 0) {
+ return nan;
+ } else {
+ return std::copysign(std::numeric_limits<T>::infinity(), dividend);
+ }
+ } else {
+ return dividend / divisor;
+ }
+}
+
} // namespace util
} // namespace mbgl