From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Serge Petrenko Message-Id: <999C425D-CF87-4D4D-B31D-F350C99EE8A6@tarantool.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_5F92A8F9-FE86-4D62-8145-8F8A26E179B5" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [PATCH v2 7/8] decimal: add conversions to (u)int64_t Date: Tue, 13 Aug 2019 17:18:50 +0300 In-Reply-To: <20190812213914.GJ32337@atlas> References: <20190812213914.GJ32337@atlas> To: Konstantin Osipov Cc: Vladimir Davydov , tarantool-patches@freelists.org List-ID: --Apple-Mail=_5F92A8F9-FE86-4D62-8145-8F8A26E179B5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > 13 =D0=B0=D0=B2=D0=B3. 2019 =D0=B3., =D0=B2 0:39, Konstantin Osipov = =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0):= >=20 > * Serge Petrenko > [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. >>=20 >> 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(-) >>=20 >> 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; >> } >>=20 >> +static decimal_t * >> +decimal_to_integer(decimal_t *dec) >=20 > 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. It wouldn=E2=80=99t slow down hint calculation (timing difference is = tiny). It will slow down decimal comparison with doubles and integers, though. We will get faster comparison for decimals that differ in first 2-5 = fractional digits at the cost of having to cast every double and int to decimal for = comparison with decimals. Is this worth it? >=20 > Is decimalRescale optimized to be a no-op if there is no need to > rescale? Yes >=20 > --=20 > Konstantin Osipov, Moscow, Russia -- Serge Petrenko sergepetrenko@tarantool.org --Apple-Mail=_5F92A8F9-FE86-4D62-8145-8F8A26E179B5 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
13 = =D0=B0=D0=B2=D0=B3. 2019 =D0=B3., =D0=B2 0:39, Konstantin Osipov <kostja@tarantool.org> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0= =D0=BB(=D0=B0):

* Serge = Petrenko <sergepetrenko@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.

It wouldn=E2=80=99t slow down hint calculation = (timing difference is tiny).
It will slow down decimal = comparison with doubles and integers, though.

We will get faster comparison for decimals that = differ in first 2-5 fractional
digits at the cost of having to = cast every double and int to decimal for comparison
with = decimals.
Is this worth it?


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

Yes


-- Konstantin Osipov, Moscow, = Russia

--
Serge = Petrenko

= --Apple-Mail=_5F92A8F9-FE86-4D62-8145-8F8A26E179B5--