• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / tarantool / 17507
83%
master: 88%

Build:
Build:
LAST BUILD BRANCH: backport/release/2.11/12142
DEFAULT BRANCH: master
Ran 20 Jun 2019 12:07PM UTC
Jobs 1
Files 392
Run time 55s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
17507

push

travis-ci

sergepetrenko
decimal: expose decimal type to lua.

Add a decimal library to lua.

Part of #692

@TarantoolBot document
Title: Document decimal module in lua.

First of all, you have to require the package via
`decimal = require('decimal')`
Now you can construct decimals via `tonumber` method.
Decimals may be constructed from lua numbers, strings, unsigned and
signed 64 bit integers.
Decimal is a fixed-point type with maximum 38 digits of precision. All
the calculations are exact, so, be careful when constructing decimals
from lua numbers: they may hold only 15 decimal digits of precision.
You are advised to construct decimals from strings, since strings
represent decimals exactly, and vice versa.

```
a = decimal.tonumber(123e-7)
b = decimal.tonumber('123.456')
c = decimal.tonumber('123.456e2')
d = decimal.tonumber(123ULL)
e = decimal.tonumber(2)
```
The allowed operations are addition, subtraction, division,
multiplication and power. If at least one of the operands is decimal,
decimal operations are performed. The other operand may be either
decimal or string, containing a number representation, or a lua number.
When the operation is called as `decimal.opname`, both operands may be
strings or lua numbers, e.g. `decimal.add(23, '123.456') == 146.456`:
```
tarantool> a + b
---
- '123.456012300000000'
...

tarantool> decimal.add(a,b)
---
- '123.456012300000000'
...

tarantool> c - d
---
- '12222.6'
...

tarantool> decimal.sub(c,d)
---
- '12222.6'
...

tarantool> c / b
---
- '100'
...

tarantool> decimal.div(c, b)
---
- '100'
...

tarantool> d * d
---
- '15129'
...

tarantool> decimal.mul(d, d)
---
- '15129'
...

tarantool> d ^ 2
---
- '15129'
...

tarantool> 2 ^ d
---
- '10633823966279326983230456482242756608'
...

tarantool> e ^ d
---
- '10633823966279326983230456482242756608'
...
```
The following math functions are also supported:
log10, ln, exp, sqrt, pow. When specified as
`decimal.opname()`, operations may be performed on
strings and lua numbers.
```
f = decim... (continued)

67921 of 82406 relevant lines covered (82.42%)

2279057.92 hits per line

Jobs
ID Job ID Ran Files Coverage
4 17507.4 (TARGET=coverage) 20 Jun 2019 12:07PM UTC 0
82.42
Travis Job 17507.4
Source Files on build 17507
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #17507
  • db06dc90 on github
  • Prev Build on sp/gh-692-decimal-lua (#17490)
  • Next Build on sp/gh-692-decimal-lua (#17566)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc