[Tarantool-patches] [PATCH v2 1/4] tuple: don't truncate float in :update()

Nikita Pettik korablev at tarantool.org
Mon Feb 10 17:41:15 MSK 2020


On 04 Feb 23:53, Vladislav Shpilevoy wrote:
> diff --git a/src/box/xrow_update_field.c b/src/box/xrow_update_field.c
> index 7c0f5fb5e..6ac29de5d 100644
> --- a/src/box/xrow_update_field.c
> +++ b/src/box/xrow_update_field.c
> @@ -32,6 +32,8 @@
>  #include "tuple_format.h"
>  #include "mp_extension_types.h"
>  
> +#include <float.h>
> +
>  /* {{{ Error helpers. */
>  
>  /** Take a string identifier of a field being updated by @a op. */
> @@ -400,13 +402,15 @@ xrow_update_arith_make(struct xrow_update_op *op,
>  			unreachable();
>  			break;
>  		}

Patch is ok, but I'd add a brief comment here like:

If value fits into float, then store it as a float;
store it as double otherwise.

Up to you.

> -		if (lowest_type == XUPDATE_TYPE_DOUBLE) {
> +		float fc = (float) c;
> +		if ((lowest_type == XUPDATE_TYPE_DOUBLE && c != (double) fc) ||
> +		    (lowest_type == XUPDATE_TYPE_FLOAT &&
> +		     (c >= FLT_MAX || c <= -FLT_MAX))) {
>  			ret->type = XUPDATE_TYPE_DOUBLE;
>  			ret->dbl = c;
>  		} else {
> -			assert(lowest_type == XUPDATE_TYPE_FLOAT);
>  			ret->type = XUPDATE_TYPE_FLOAT;
> -			ret->flt = (float)c;
> +			ret->flt = fc;
>  		}
>  	} else {
>  		decimal_t a, b, c;


More information about the Tarantool-patches mailing list