aboutsummaryrefslogtreecommitdiff
path: root/core/math/math_funcs.cpp
diff options
context:
space:
mode:
authorJuan Linietsky2016-08-02 19:11:47 -0300
committerJuan Linietsky2016-08-02 19:11:47 -0300
commit3d1d190dcd2993f87d5804de8a60e8bf5fc2cf49 (patch)
treeaa2c814b744ab970ae79931b419908ff7ebc850e /core/math/math_funcs.cpp
parentad313097ebcb2a0c02c956fdf74a6610c3f7c9a8 (diff)
parentcea949180688add09eb9e69f5e405f361dc96d40 (diff)
downloadgodot-3d1d190dcd2993f87d5804de8a60e8bf5fc2cf49.tar.gz
godot-3d1d190dcd2993f87d5804de8a60e8bf5fc2cf49.tar.zst
godot-3d1d190dcd2993f87d5804de8a60e8bf5fc2cf49.zip
Merge branch 'master' of https://github.com/godotengine/godot
Diffstat (limited to '')
-rw-r--r--core/math/math_funcs.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 0fbd03121..64615fe6b 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -206,25 +206,29 @@ double Math::ceil(double p_x) {
return ::ceil(p_x);
}
-int Math::decimals(double p_step) {
+int Math::step_decimals(double p_step) {
- int max=4;
- double llimit = Math::pow(0.1,max);
- double ulimit = 1.0-llimit;
- int i=0;
- while( max) {
-
- float d = absf(p_step) - Math::floor(absf(p_step));
+ static const int maxn=9;
+ static const double sd[maxn]={
+ 0.9999, // somehow compensate for floating point error
+ 0.09999,
+ 0.009999,
+ 0.0009999,
+ 0.00009999,
+ 0.000009999,
+ 0.0000009999,
+ 0.00000009999,
+ 0.000000009999
+ };
- if (d<llimit || d>ulimit)
- break;
- p_step*=10.0;
- max--;
- i++;
+ double as=absf(p_step);
+ for(int i=0;i<maxn;i++) {
+ if (as>=sd[i]) {
+ return i;
+ }
}
- return i;
-
+ return maxn;
}
double Math::ease(double p_x, double p_c) {