From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [PATCH v2] box: add support for decimals in update ops From: Serge Petrenko In-Reply-To: <20190821213726.GC24288@atlas> Date: Thu, 22 Aug 2019 11:54:37 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190821085808.12236-1-sergepetrenko@tarantool.org> <20190821213726.GC24288@atlas> To: Konstantin Osipov Cc: Vladimir Davydov , tarantool-patches@freelists.org List-ID: > 22 =D0=B0=D0=B2=D0=B3. 2019 =D0=B3., =D0=B2 0:37, Konstantin Osipov = =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0):= >=20 > * Serge Petrenko [19/08/21 12:03]: >> Closes #4413 >>=20 >> @TarantoolBot document >> Title: update operations on decimal fields. >>=20 >> tuple:update and space:update now support deicmal operands for >> arithmetic operations ('+' and '-'). The syntax is as usual: >=20 > Please document how type arithmetics work, and cover it with > tests. Hi! I added the following text to the docbot request in commit message: =C2=ABWhen performing an arithmetic operation ('+', '-'), where either = the updated field or the operand is decimal, the result will be decimal. When both the updated field and the operand are decimal, the result will, of course, be decimal.=C2=BB Here=E2=80=99s the tests diff: diff --git a/test/box/update.result b/test/box/update.result index a3f731b55..cc8fa7ad0 100644 --- a/test/box/update.result +++ b/test/box/update.result @@ -677,6 +677,46 @@ s:update({0}, {{'+', 2, ffi.new("float", 1.2)}}) -- = float + float =3D float 1.2 --- - [0, 1.2000000476837] ... +-- decimal +decimal =3D require('decimal') +--- +... +s:replace{0, decimal.new("2.000")} +--- +- [0, 2.000] +... +s:update({0}, {{'+', 2, 2ULL}}) -- decimal + unsigned =3D decimal 4.000 +--- +- [0, 4.000] +... +s:update({0}, {{'+', 2, -4LL}}) -- decimal + signed =3D decimal 0.000 +--- +- [0, 0.000] +... +s:update({0}, {{'+', 2, 2}}) -- decimal + number =3D decimal 2.000 +--- +- [0, 2.000] +... +s:update({0}, {{'-', 2, 2}}) -- decimal - number =3D decimal 0.000 +--- +- [0, 0.000] +... +s:update({0}, {{'-', 2, ffi.new('float', 2)}}) -- decimal - float =3D = decimal -2.000 +--- +- [0, -2.000] +... +s:update({0}, {{'-', 2, ffi.new('double', 2)}}) -- decimal - double =3D = decimal -4.000 +--- +- [0, -4.000] +... +s:update({0}, {{'+', 2, decimal.new(4)}}) -- decimal + decimal =3D = decimal 0.000 +--- +- [0, 0.000] +... +s:update({0}, {{'-', 2, decimal.new(2)}}) -- decimal - decimal =3D = decimal -2.000 +--- +- [0, -2.000] +... -- overflow -- s:replace{0, 0xfffffffffffffffeull} --- diff --git a/test/box/update.test.lua b/test/box/update.test.lua index c455bc1e1..ac7698ce9 100644 --- a/test/box/update.test.lua +++ b/test/box/update.test.lua @@ -210,6 +210,17 @@ s:update({0}, {{'-', 2, ffi.new("float", 1.5)}}) -- = float - float =3D float 5.5 s:update({0}, {{'+', 2, ffi.new("float", 3.5)}}) -- float + float =3D = float 9 s:update({0}, {{'-', 2, ffi.new("float", 9)}}) -- float + float =3D = float 0 s:update({0}, {{'+', 2, ffi.new("float", 1.2)}}) -- float + float =3D = float 1.2 +-- decimal +decimal =3D require('decimal') +s:replace{0, decimal.new("2.000")} +s:update({0}, {{'+', 2, 2ULL}}) -- decimal + unsigned =3D decimal 4.000 +s:update({0}, {{'+', 2, -4LL}}) -- decimal + signed =3D decimal 0.000 +s:update({0}, {{'+', 2, 2}}) -- decimal + number =3D decimal 2.000 +s:update({0}, {{'-', 2, 2}}) -- decimal - number =3D decimal 0.000 +s:update({0}, {{'-', 2, ffi.new('float', 2)}}) -- decimal - float =3D = decimal -2.000 +s:update({0}, {{'-', 2, ffi.new('double', 2)}}) -- decimal - double =3D = decimal -4.000 +s:update({0}, {{'+', 2, decimal.new(4)}}) -- decimal + decimal =3D = decimal 0.000 +s:update({0}, {{'-', 2, decimal.new(2)}}) -- decimal - decimal =3D = decimal -2.000 -- overflow -- s:replace{0, 0xfffffffffffffffeull} s:update({0}, {{'+', 2, 1}}) -- ok >=20 > --=20 > Konstantin Osipov, Moscow, Russia -- Serge Petrenko sergepetrenko@tarantool.org