浏览代码

Fix: Strip integer part in "decimals"

Note: Core only.
Aaron Franke 7 年之前
父节点
当前提交
5f4f9ca4a5
共有 1 个文件被更改,包括 7 次插入5 次删除
  1. 7 5
      core/math/math_funcs.cpp

+ 7 - 5
core/math/math_funcs.cpp

@@ -57,7 +57,7 @@ uint32_t Math::rand() {
 }
 }
 
 
 int Math::step_decimals(double p_step) {
 int Math::step_decimals(double p_step) {
-	static const int maxn = 9;
+	static const int maxn = 10;
 	static const double sd[maxn] = {
 	static const double sd[maxn] = {
 		0.9999, // somehow compensate for floating point error
 		0.9999, // somehow compensate for floating point error
 		0.09999,
 		0.09999,
@@ -67,17 +67,19 @@ int Math::step_decimals(double p_step) {
 		0.000009999,
 		0.000009999,
 		0.0000009999,
 		0.0000009999,
 		0.00000009999,
 		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++) {
 	for (int i = 0; i < maxn; i++) {
-		if (as >= sd[i]) {
+		if (decs >= sd[i]) {
 			return i;
 			return i;
 		}
 		}
 	}
 	}
 
 
-	return maxn;
+	return 0;
 }
 }
 
 
 double Math::dectime(double p_value, double p_amount, double p_step) {
 double Math::dectime(double p_value, double p_amount, double p_step) {