Package Exports
- mumath
- mumath/clamp
- mumath/closest
- mumath/is-multiple
- mumath/len
- mumath/lerp
- mumath/log10
- mumath/mod
- mumath/order
- mumath/precision
- mumath/pretty
- mumath/round
- mumath/within
- mumath/wrap
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mumath) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
μMath

Set of practical math utils to shorten code.
var round = require('mumath/round');
round(123.32, .5); //123.5
//require any function as
//var <fn> = require('mumath/<fn>');
API
round(value, step?)
Rounds value to optional step
, which is 1
by default.
round(0.3, .5)
→ .5
len(a, b)
Return length of a vector.
precision(value)
Get precision from float:
1.1 → 1, 1234 → 0, .1234 → 4
clamp(value, left, right)
Return value clamped by left/right limits (or vice-versa).
lerp(x, y, ratio)
Return value interpolated between x and y.
within(value, left, right)
Whether element is between left & right, including.
mod(value, min?, max)
An enhanced mod-loop — loops value within a frame.
closest(value, list)
Get closest value out of a set.
order(value)
Get order of magnitude for a number.
order(123) → 100; order(-0.0003) → 0.0001;
isMultiple(a, b, eps?)
Same as a % b === 0
, but with precision check.
pretty(a, positions?)
Format number into human-readable form. Like toFixed
, but works good.
Related
bit-twiddle — utils for power-of-two numbers.