Skip to content
Snippets Groups Projects
Commit c52ef4ac authored by Naveen Albert's avatar Naveen Albert Committed by Friendly Automation
Browse files

func_math: Return integer instead of float if possible

The MIN, MAX, and ABS functions all support float
arguments, but currently return floats even if the
arguments are all integers and the response is
a whole number, in which case the user is likely
expecting an integer. This casts the float to an integer
before printing into the response buffer if possible.

ASTERISK-29495

Change-Id: I902d29eacf3ecd0f8a6a5e433c97f0421d205488
parent 9cac1c16
Branches
Tags
1 merge request!48asterisk uplift to 18.11.2
...@@ -525,7 +525,11 @@ static int acf_min_exec(struct ast_channel *chan, const char *cmd, ...@@ -525,7 +525,11 @@ static int acf_min_exec(struct ast_channel *chan, const char *cmd,
} }
ast_debug(1, "%f is the minimum of [%f,%f]\n", response_num, num1, num2); ast_debug(1, "%f is the minimum of [%f,%f]\n", response_num, num1, num2);
snprintf(buffer, buflen, "%f", response_num); if ((int) response_num == response_num) {
snprintf(buffer, buflen, "%d", (int) response_num);
} else {
snprintf(buffer, buflen, "%f", response_num);
}
return 0; return 0;
} }
...@@ -567,7 +571,11 @@ static int acf_max_exec(struct ast_channel *chan, const char *cmd, ...@@ -567,7 +571,11 @@ static int acf_max_exec(struct ast_channel *chan, const char *cmd,
} }
ast_debug(1, "%f is the maximum of [%f,%f]\n", response_num, num1, num2); ast_debug(1, "%f is the maximum of [%f,%f]\n", response_num, num1, num2);
snprintf(buffer, buflen, "%f", response_num); if ((int) response_num == response_num) {
snprintf(buffer, buflen, "%d", (int) response_num);
} else {
snprintf(buffer, buflen, "%f", response_num);
}
return 0; return 0;
} }
...@@ -589,7 +597,11 @@ static int acf_abs_exec(struct ast_channel *chan, const char *cmd, ...@@ -589,7 +597,11 @@ static int acf_abs_exec(struct ast_channel *chan, const char *cmd,
response_num = fabs(num1); response_num = fabs(num1);
ast_debug(1, "%f is the absolute value of %f\n", response_num, num1); ast_debug(1, "%f is the absolute value of %f\n", response_num, num1);
snprintf(buffer, buflen, "%f", response_num); if ((int) response_num == response_num) {
snprintf(buffer, buflen, "%d", (int) response_num);
} else {
snprintf(buffer, buflen, "%f", response_num);
}
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment