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>');
Rounds value to optional step
.
round(0.3, .5)
→ .5
Return length of a vector.
Get precision from float:
1.1 → 1, 1234 → 0, .1234 → 4
Return value clamped by left/right limits (or vice-versa).
Return value interpolated between x and y.
Whether element is between left & right, including.
An enhanced mod-loop — loops value within a frame.
Get closest value out of a set.
Get first scale out of a list of basic scales, aligned to the power. E. g.
step(.37, [1, 2, 5])
→ .5
step(456, [1, 2])
→ 1000
Similar to closest, but takes all possible powers of scales.
Get order of magnitude for a number.
order(123) → 100; order(-0.0003) → 0.0001;
Same as a % b === 0
, but with precision check.
- bit-twiddle — utils for power-of-two numbers.
- pretty-number — format number to pretty view.