[PATCH v2 7/8] decimal: add conversions to (u)int64_t

Konstantin Osipov kostja at tarantool.org
Tue Aug 13 00:39:14 MSK 2019


* Serge Petrenko <sergepetrenko at tarantool.org> [19/08/08 15:01]:
> Update decNumber library, add methods to convert decimals to uint64_t
> and int64_t, add unit tests.
> Also replace decimal_round() function with decimal_round_with_mode() to
> allow setting rounding mode.
> We need to round with mode DEC_ROUND_DOWN in to_int64 conversions in
> order to be consistent with double to int conversions.
> It will be needed to compute hints for decimal fields.
> 
> Prerequisite #4333
> ---
>  src/lib/core/decimal.c   | 57 +++++++++++++++++++++++++++++--
>  src/lib/core/decimal.h   | 19 +++++++++++
>  test/unit/decimal.c      | 66 ++++++++++++++++++++++++++++++++++-
>  test/unit/decimal.result | 74 ++++++++++++++++++++++++++++++++++++++--
>  third_party/decNumber    |  2 +-
>  5 files changed, 210 insertions(+), 8 deletions(-)
> 
> diff --git a/src/lib/core/decimal.c b/src/lib/core/decimal.c
> index 840aa5dfe..19b5096ed 100644
> --- a/src/lib/core/decimal.c
> +++ b/src/lib/core/decimal.c
> @@ -157,6 +157,45 @@ decimal_to_string(const decimal_t *dec)
>  	return buf;
>  }
>  
> +static decimal_t *
> +decimal_to_integer(decimal_t *dec)

Why do you think it's the best hint option? Why not keep 2-5 decimal
digits in a hint, as most currencies use? Would it slow down the
hing making process? You call decimalRescale anyway, it seems.

Is decimalRescale optimized to be a no-op if there is no need to
rescale?

-- 
Konstantin Osipov, Moscow, Russia



More information about the Tarantool-patches mailing list