arithmetic operators for arbitrary-precision numbers using bignumber.js
rather than constructing BigNumber
instances from your numbers and using instance methods, this module provides the same methods as static functions.
npm install --save bigmath
test('BigMath', function (t) {
t.ok(BigMath, 'module is require-able')
t.equal(BigMath.add('1', '2'), '3', '1 + 2 = 3')
t.equal(BigMath.sub('1', '2'), '-1', '1 - 2 = -1')
t.equal(BigMath.mul('1', '2'), '2', '1 * 2 = 2')
t.equal(BigMath.div('1', '2'), '0.5', '1 / 2 = 0.5')
t.end()
})
BigMath
is an grab-bag of the following operators from bignumber.js
:
(note: if the operator normally returns a BigNumber
, our operator instead returns a string using .valueOf()
.)
absoluteValue
abs
ceil
comparedTo
cmp
decimalPlaces
dp
dividedBy
div
dividedToIntegerBy
divToInt
equals
eq
floor
greaterThan
gt
greaterThanOrEqualTo
gte
isFinite
isInteger
isInt
isNaN
isNegative
isNeg
isZero
lessThan
lt
lessThanOrEqualTo
lte
minus
sub
modulo
mod
negated
neg
plus
add
precision
sd
round
shift
squareRoot
sqrt
times
max
min
mul
toDigits
toExponential
toFixed
toFormat
toFraction
toJSON
toNumber
toPower
pow
random
toPrecision
toString
truncated
trunc
valueOf
The Apache License
Copyright © 2017 Michael Williams
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.