Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Strip integer part in "decimals" #22251

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions core/math/math_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
akien-mga marked this conversation as resolved.
Show resolved Hide resolved
}

double Math::dectime(double p_value, double p_amount, double p_step) {
Expand Down