Skip to content

Introduce fixed point decimals #5127

Open
@TarantoolBot

Description

@TarantoolBot

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:

SME: @ nshy @ sergepetrenko

  1. Новые типы, decimal32/64/... появились во всех движках, не только memcs (memtx и vinyl)
  2. Это затрагивает модуль decimal

Added support for fixed point decimal types decimal32, decimal64,
decimal128 and decimal256. They differ in number of significant
decimal digits:

  • decimal32 - 9
  • decimal64 - 18
  • decimal128 - 38
  • decimal256 - 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.5EEEE functionalitymemtx[area] Related to memtxvinyl[area] Related to vinyl

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions