From: Serge Petrenko <sergepetrenko@tarantool.org> To: Konstantin Osipov <kostja@tarantool.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>, tarantool-patches@freelists.org Subject: Re: [PATCH v2] box: add support for decimals in update ops Date: Thu, 22 Aug 2019 11:54:37 +0300 [thread overview] Message-ID: <E060B6C0-F83A-4126-BA7B-0D83E678777D@tarantool.org> (raw) In-Reply-To: <20190821213726.GC24288@atlas> > 22 авг. 2019 г., в 0:37, Konstantin Osipov <kostja@tarantool.org> написал(а): > > * Serge Petrenko <sergepetrenko@tarantool.org> [19/08/21 12:03]: >> Closes #4413 >> >> @TarantoolBot document >> Title: update operations on decimal fields. >> >> tuple:update and space:update now support deicmal operands for >> arithmetic operations ('+' and '-'). The syntax is as usual: > > Please document how type arithmetics work, and cover it with > tests. Hi! I added the following text to the docbot request in commit message: «When 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.» Here’s 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 = float 1.2 --- - [0, 1.2000000476837] ... +-- decimal +decimal = require('decimal') +--- +... +s:replace{0, decimal.new("2.000")} +--- +- [0, 2.000] +... +s:update({0}, {{'+', 2, 2ULL}}) -- decimal + unsigned = decimal 4.000 +--- +- [0, 4.000] +... +s:update({0}, {{'+', 2, -4LL}}) -- decimal + signed = decimal 0.000 +--- +- [0, 0.000] +... +s:update({0}, {{'+', 2, 2}}) -- decimal + number = decimal 2.000 +--- +- [0, 2.000] +... +s:update({0}, {{'-', 2, 2}}) -- decimal - number = decimal 0.000 +--- +- [0, 0.000] +... +s:update({0}, {{'-', 2, ffi.new('float', 2)}}) -- decimal - float = decimal -2.000 +--- +- [0, -2.000] +... +s:update({0}, {{'-', 2, ffi.new('double', 2)}}) -- decimal - double = decimal -4.000 +--- +- [0, -4.000] +... +s:update({0}, {{'+', 2, decimal.new(4)}}) -- decimal + decimal = decimal 0.000 +--- +- [0, 0.000] +... +s:update({0}, {{'-', 2, decimal.new(2)}}) -- decimal - decimal = 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 = float 5.5 s:update({0}, {{'+', 2, ffi.new("float", 3.5)}}) -- float + float = float 9 s:update({0}, {{'-', 2, ffi.new("float", 9)}}) -- float + float = float 0 s:update({0}, {{'+', 2, ffi.new("float", 1.2)}}) -- float + float = float 1.2 +-- decimal +decimal = require('decimal') +s:replace{0, decimal.new("2.000")} +s:update({0}, {{'+', 2, 2ULL}}) -- decimal + unsigned = decimal 4.000 +s:update({0}, {{'+', 2, -4LL}}) -- decimal + signed = decimal 0.000 +s:update({0}, {{'+', 2, 2}}) -- decimal + number = decimal 2.000 +s:update({0}, {{'-', 2, 2}}) -- decimal - number = decimal 0.000 +s:update({0}, {{'-', 2, ffi.new('float', 2)}}) -- decimal - float = decimal -2.000 +s:update({0}, {{'-', 2, ffi.new('double', 2)}}) -- decimal - double = decimal -4.000 +s:update({0}, {{'+', 2, decimal.new(4)}}) -- decimal + decimal = decimal 0.000 +s:update({0}, {{'-', 2, decimal.new(2)}}) -- decimal - decimal = decimal -2.000 -- overflow -- s:replace{0, 0xfffffffffffffffeull} s:update({0}, {{'+', 2, 1}}) -- ok > > -- > Konstantin Osipov, Moscow, Russia -- Serge Petrenko sergepetrenko@tarantool.org
next prev parent reply other threads:[~2019-08-22 8:54 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-21 8:58 Serge Petrenko 2019-08-21 10:45 ` Serge Petrenko 2019-08-21 15:09 ` Vladimir Davydov 2019-08-21 21:37 ` Konstantin Osipov 2019-08-22 8:54 ` Serge Petrenko [this message] 2019-08-22 10:07 ` Konstantin Osipov 2019-08-22 10:34 ` [tarantool-patches] " Kirill Yukhin
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=E060B6C0-F83A-4126-BA7B-0D83E678777D@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v2] box: add support for decimals in update ops' \ /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