From: Nikita Pettik <korablev@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 1/4] tuple: don't truncate float in :update()
Date: Mon, 10 Feb 2020 17:41:15 +0300 [thread overview]
Message-ID: <20200210144115.GH1110@tarantool.org> (raw)
In-Reply-To: <1a28ebaa58b81f4cbc3a1656cf364f281919ade9.1580856721.git.v.shpilevoy@tarantool.org>
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;
next prev parent reply other threads:[~2020-02-10 14:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-04 22:53 [Tarantool-patches] [PATCH v2 0/4] Don't truncate float in update Vladislav Shpilevoy
2020-02-04 22:53 ` [Tarantool-patches] [PATCH v2 1/4] tuple: don't truncate float in :update() Vladislav Shpilevoy
2020-02-10 14:41 ` Nikita Pettik [this message]
2020-02-10 21:18 ` Vladislav Shpilevoy
2020-02-19 21:36 ` Nikita Pettik
2020-02-04 22:53 ` [Tarantool-patches] [PATCH v2 2/4] tuple: pass tuple format to xrow_update_*_store() Vladislav Shpilevoy
2020-02-10 16:51 ` Nikita Pettik
2020-02-10 21:18 ` Vladislav Shpilevoy
2020-02-04 22:53 ` [Tarantool-patches] [PATCH v2 3/4] tuple: allow xrow_update sizeof reserve more memory Vladislav Shpilevoy
2020-02-10 16:05 ` Nikita Pettik
2020-02-04 22:53 ` [Tarantool-patches] [PATCH v2 4/4] tuple: use field type in update of a float/double Vladislav Shpilevoy
2020-02-10 16:16 ` Nikita Pettik
2020-02-10 21:18 ` Vladislav Shpilevoy
2020-02-05 11:09 ` [Tarantool-patches] [PATCH v2 0/4] Don't truncate float in update Konstantin Osipov
2020-02-05 22:11 ` Vladislav Shpilevoy
2020-02-20 6:15 ` Kirill Yukhin
2020-02-20 13:27 ` Nikita Pettik
2020-02-20 20:30 ` Vladislav Shpilevoy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200210144115.GH1110@tarantool.org \
--to=korablev@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v2 1/4] tuple: don'\''t truncate float in :update()' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox