gamp
v0.2.1
Published
Provide a four operations calculator API with workaround for the common floating-point issue
Downloads
798
Maintainers
Readme
gamp
This small lib provides a four operations calculator API with workaround for the common floating-point issue.
How to use
You can either require it using requireJS, import it inside your Node.js project, or just load it using regular script tag.
The API is pretty simple:
gamp.add(left, right)
: returns the result of the addition of the right operand to the left operandgamp.sub(left, right)
: returns the result of the subtraction of the right operand from the left operandgamp.mul(left, right)
: returns the results of the multiplication of the left operand by the right operandgamp.div(left, right)
: returns the results of the division of the left operand by the right operandgamp.pow(left, right)
: returns the results of the power of the left operand by the right operandgamp.normalize(value, factor)
: normalizes the value by a factor and rounds itgamp.round(value, [digits=16])
: rounds a value to a particular number of digits (default 16)gamp(value1, value2, ..., valueN)
: computes the shared precision of the provided decimal numbers. This precision is the decimal factor needed to normalize the values in order to prevent the floating-point round-off error.