Skip to content

Numbers

Arthur Guiot edited this page May 16, 2018 · 9 revisions

The concept of BigNumber

We use the BigNumber library to do most of our computation. In this docs, if you see a comment with => BigNumber, the output of the function will be a BigNumber instance.

You can create any BigNumber using t.n(x) (where x is your number)

It has the convenience of being able to do float operations without any errors:

0.2 + 0.4 // 0.6000000000000001

t.n(0.2).add(0.4) // 0.6 => BigNumber

We strongly recommend you checking the BigNumber.js website to understand how to use it.

Round, floor, and ceil

You can round, floor or ceil a number like:

t.round(5.2) // 5 => BigNumber

t.floor(5.7) // 5 => BigNumber

t.ceil(5.2) // 6 => BigNumber

Constants

Get constants

You can get any constants like:

t.c("pi") // 3.141592653589793 => BigNumber
t.c("e", 4) // 2.7182 => BigNumber

These are all the constants:

Name Value
pi 3.14159265
e 2.71828182
sqrt(2) 1.41421356
goldenRatio 1.61803398
EulerGamma 0.57721566
UltimateAnswer 42

All constants are stored with 250 digits

Compute constants

You can compute constants such as pi, e or the goldenRatio. Computing these value may take a lot more time. For example, computing 1000 digits of pi took me around 19 seconds on my MacBook Pro.

Here is how you use it:

t.pi() // 3.1415926535897932408 => BigNumber
t.pi(4) // 3.14159264 => BigNumber

t.e() // 2.71828182845904523536 => BigNumber

t.goldenRatio() // 1.618033988749895 => BigNumber

Note that you can't compute more than 15 digits of the golden ratio, because of a BigNumber limitation.

Is Prime

You can check pretty efficiently if a number is prime or not

Clone this wiki locally