Description
Part of https://github.com/tarantool/tarantool-ee/issues/1188
Task: https://jira.vk.team/browse/TNTP-2277
Product: Tarantool
Since: 3.5.0
Root document:
- https://www.tarantool.io/en/doc/latest/platform/engines/
- https://www.tarantool.io/ru/doc/latest/reference/reference_lua/decimal/
SME: @ nshy @ sergepetrenko
- Новые типы, decimal32/64/... появились во всех движках, не только memcs (memtx и vinyl)
- Это затрагивает модуль decimal
Added support for fixed point decimal types decimal32
, decimal64
,
decimal128
and decimal256
. They differ in number of significant
decimal digits:
decimal32
- 9decimal64
- 18decimal128
- 38decimal256
- 76
These types also has additional parameter scale
which defines the
position of decimal point or it can be seen as implied decimal exponent
with value of -scale
. For example type decimal32
with scale = 4
can represent values from -99999.9999
to 99999.9999
. And decimal
with scale = -2
can represent values from -999999999 * 10^2
to
999999999 * 10^2
.
Example 1. Creating space with field of fixed decimal type.
s = box.schema.create_space('test', {format = {
{'a', 'unsigned'}, {'b', 'decimal32', scale = 4},
}})
Decimal values can be created using decimal
module. It changed to
be able to represent values of new types:
- limitation on exponent is removed
- precision is increased to 76 decimal digits
- printing is done in scientific notation
Example 2. Passing decimal values.
local decimal = require('decimal')
s = box.schema.create_space('test', {format = {
{'a', 'unsigned'}, {'b', 'decimal32', scale = 4},
}})
s:create_index('pk')
s:insert({1, decimal.new(13333)})
s:insert({2, decimal.new(0.0017)})
Requested by @nshy in tarantool/tarantool@92b3102.