box: add support for decimals in update ops
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: ``` d = box.tuple.new(decimal.new('1')) --- ... d:update{{'+', 1, decimal.new('0.5')}} --- - [1.5] ... ``` Insertion ('!') and assignment ('=') are also supported: ``` a = decimal.new('1') --- ... b = decimal.new('1e10') --- ... c = decimal.new('1e-10') --- ... d = box.tuple.new{5, a, 6, b, 7, c, "string"} --- ... d --- - [5, 1, 6, 10000000000, 7, 0.0000000001, 'string'] ... d:update{{'!', 3, dec.new('1234.5678')}} --- - [5, 1, 1234.5678, 6, 10000000000, 7, 0.0000000001, 'string'] ... d:update{{'=', -1, dec.new('0.12345678910111213')}} --- - [5, 1, 6, 10000000000, 7, 0.0000000001, 0.12345678910111213] 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. ... ```
Showing
- src/box/errcode.h 1 addition, 1 deletionsrc/box/errcode.h
- src/box/tuple_update.c 86 additions, 9 deletionssrc/box/tuple_update.c
- test/box/misc.result 1 addition, 0 deletionstest/box/misc.result
- test/box/tuple.result 58 additions, 0 deletionstest/box/tuple.result
- test/box/tuple.test.lua 24 additions, 0 deletionstest/box/tuple.test.lua
- test/box/update.result 40 additions, 0 deletionstest/box/update.result
- test/box/update.test.lua 11 additions, 0 deletionstest/box/update.test.lua
- test/engine/decimal.result 36 additions, 0 deletionstest/engine/decimal.result
- test/engine/decimal.test.lua 11 additions, 0 deletionstest/engine/decimal.test.lua
Loading
Please register or sign in to comment