diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-04 09:29:30 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-06 18:09:14 +0200 |
commit | bc033ad8d4d3092809945fec502c73f90a1afe09 (patch) | |
tree | aab70e95c953b2f1f63e153b1979266fc331db48 /include | |
parent | 06a8ecdb171a6284f54d1db6847d4cc0cfcc9f91 (diff) | |
download | qtlocation-mapboxgl-bc033ad8d4d3092809945fec502c73f90a1afe09.tar.gz |
[core] util::wrap(): std::fmod is not lossless
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/math/wrap.hpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/include/mbgl/math/wrap.hpp b/include/mbgl/math/wrap.hpp index 16dc598c22..3076225384 100644 --- a/include/mbgl/math/wrap.hpp +++ b/include/mbgl/math/wrap.hpp @@ -9,8 +9,15 @@ namespace util { // arithmetic. template <typename T> T wrap(T value, T min, T max) { - T d = max - min; - return std::fmod((std::fmod((value - min), d) + d), d) + min; + if (value >= min && value < max) { + return value; + } else if (value == max) { + return min; + } + + const T delta = max - min; + const T wrapped = min + std::fmod(value - min, delta); + return value < min ? wrapped + delta : wrapped; } } // namespace util |