-
-
Notifications
You must be signed in to change notification settings - Fork 30
Numbers
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 => BigNumberYou can get any constants like:
t.c("pi") // 3.141592653589793 => BigNumber
t.c("e", 4) // 2.7182 => BigNumberThese are all the constants:
| Name | Value |
|---|---|
| alphaParticleMass | 6.64465675e-27 |
| atomicMass | 1.66053892e-27 |
| Avogadro | 6.02214129e23 |
| Boltzmann | 1.3806488e-23 |
| conductanceQuantum | 7.74809173e-5 |
| e | 2.71828182 |
| earth-moon | 384401 |
| earth-sun | 1.496e8 |
| earthMass | 5.974e+24 |
| earthRadius | 6378 |
| electric | 8.854187e-12 |
| electronMass | 9.10938291e-31 |
| elementaryCharge | 1.60217656e-19 |
| EulerGamma | 0.57721566 |
| Faraday | 96485.3365 |
| fineStructure | 7.29735256e-3 |
| goldenRatio | 1.61803398 |
| gravity | 9.80665 |
| inverseFineStructure | 137.035999 |
| magnetic | 12.5663706e-7 |
| magneticFluxQuantum | 2.06783375e-15 |
| molarGas | 8.3144621 |
| moonMass | 7.348e22 |
| moonRadius | 1738 |
| neutronMass | 1.67492735e-27 |
| NewtonGravitation | 6.67384e-11 |
| pi | 3.14159265 |
| Planck | 6.62606957e-34 |
| proton-electronMassRatio | 1836.15267 |
| proton-neutronMassRatio | 0.99862347 |
| protonMass | 1.67262177e-27 |
| Rydberg | 10973731.5 |
| speedOfLight | 299792458 |
| speedOfSound | 340.27 |
| sqrt(2) | 1.41421356 |
| Stefan-Boltzmann | 5.670373e-8 |
| sunMass | 1.989e30 |
| sunRadius | 695500 |
| TheRockMass | 124.737901 |
| ThomsonCrossSection | 0.66524587e-28 |
| UltimateAnswer | 42 |
| zeroKelvin | -273.15 |
Constants have a precision limit of 250 digits
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.
In v1.2.0 you can't choose how much digits you want to compute. All constants will return a 15 digit number.
Here is how you use it:
t.pi // 3.1415926535897932408 => BigNumber
t.e // 2.71828182845904523536 => BigNumber
t.goldenRatio // 1.618033988749895 => BigNumberYou can check pretty efficiently if a number is prime or not like that:
t.isPrime(2011) // trueIf your number is superior to
Number.MAX_SAFE_INTEGER, it won't work
You can get the least factor (that is not 1) of any number n inferior to Number.MAX_SAFE_INTEGER like:
t.leastFactor(50) // 2 => BigNumberYou can get a list of prime factors that compose any number n less than Number.MAX_SAFE_INTEGER like that:
t.primeFactors(100) // [2, 2, 5, 5] => [BigNumber]You can get the number of primes below any number n less than Number.MAX_SAFE_INTEGER like that:
t.primePi(100) // 25 => BigNumberGet the nth prime like that:
t.nPrime(10) // 29 => BigNumberAny questions? Don't hesitate to create an issue and tell me about your problem 😊.
Copyright © 2017-2018 Arthur Guiot