[Tarantool-patches] [PATCH 2/5] box/sql: func -- fix compilation warning

Mergen Imeev imeevma at tarantool.org
Mon May 18 14:13:07 MSK 2020


On Mon, May 18, 2020 at 01:14:59PM +0300, Cyrill Gorcunov wrote:
> The @r is "double" value thus use explicit
> conversion to placate clang compiler.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
> ---
>  src/box/sql/func.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index 2c510940b..d5463facd 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> @@ -845,9 +845,9 @@ roundFunc(sql_context * context, int argc, sql_value ** argv)
>  	 * handle the rounding directly,
>  	 * otherwise use printf.
>  	 */
> -	if (n == 0 && r >= 0 && r < LARGEST_INT64 - 1) {
> +	if (n == 0 && r >= 0 && r < (double)(LARGEST_INT64 - 1)) {
>  		r = (double)((sql_int64) (r + 0.5));
I am not sure that this change worth to do since
LARGEST_INT64 = 2^63 -1 and
(double)(LARGEST_INT64 - 1) == 2^63, if I am not wrong.
I also not sure that this worked right before.
I think it makes sense to compare with someting like 2^53,
because if absolute value of r is greater that 2^53 than
we do not have to round it anymore.
 
> -	} else if (n == 0 && r < 0 && (-r) < LARGEST_INT64 - 1) {
> +	} else if (n == 0 && r < 0 && (-r) < (double)(LARGEST_INT64 - 1)) {
>  		r = -(double)((sql_int64) ((-r) + 0.5));
>  	} else {
>  		const char *rounded_value = tt_sprintf("%.*f", n, r);
> -- 
> 2.26.2
> 


More information about the Tarantool-patches mailing list