diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2018-09-19 20:10:06 -0400 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2018-09-19 23:47:33 -0400 |
commit | 5f4f9ca4a567857b3a23b610dd2f0be6b57efcb3 (patch) | |
tree | 803486778f03a735547ce10a28f94df813ed5107 | |
parent | e20a28a7db090dbf39bc8c90487c3d7beb84cbb8 (diff) |
Fix: Strip integer part in "decimals"
Note: Core only.
-rw-r--r-- | core/math/math_funcs.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 5c8512d8bd..0c06d2a2b5 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -57,7 +57,7 @@ uint32_t Math::rand() { } int Math::step_decimals(double p_step) { - static const int maxn = 9; + static const int maxn = 10; static const double sd[maxn] = { 0.9999, // somehow compensate for floating point error 0.09999, @@ -67,17 +67,19 @@ int Math::step_decimals(double p_step) { 0.000009999, 0.0000009999, 0.00000009999, - 0.000000009999 + 0.000000009999, + 0.0000000009999 }; - double as = Math::abs(p_step); + double abs = Math::abs(p_step); + double decs = abs - (int)abs; // Strip away integer part for (int i = 0; i < maxn; i++) { - if (as >= sd[i]) { + if (decs >= sd[i]) { return i; } } - return maxn; + return 0; } double Math::dectime(double p_value, double p_amount, double p_step) { |