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

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Feb 11 00:18:46 MSK 2020


Hi! Thanks for the review!

On 10/02/2020 15:41, Nikita Pettik wrote:
> 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.

Added a comment:

================================================================================

diff --git a/src/box/xrow_update_field.c b/src/box/xrow_update_field.c
index 6ac29de5d..0540e8c3e 100644
--- a/src/box/xrow_update_field.c
+++ b/src/box/xrow_update_field.c
@@ -403,6 +403,12 @@ xrow_update_arith_make(struct xrow_update_op *op,
 			break;
 		}
 		float fc = (float) c;
+		/*
+		 * If fits into float - store as a float.
+		 * Otherwise as a double. Fits means, that the
+		 * value precision is not truncated by float, and
+		 * its value is inside the float range.
+		 */
 		if ((lowest_type == XUPDATE_TYPE_DOUBLE && c != (double) fc) ||
 		    (lowest_type == XUPDATE_TYPE_FLOAT &&
 		     (c >= FLT_MAX || c <= -FLT_MAX))) {


More information about the Tarantool-patches mailing list