mumath

Practical math utils for components

Redundant dependency in your project.
Last updated 9 years ago by dfcreative .
Unlicense · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mumath 
SYNC missed versions from official npm registry.

μMath Build Status Code Climate

Set of practical math utils to shorten code.

$ npm install mumath

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.

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.

scale(value, list)

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.

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.

Related

Current Tags

  • 3.3.4                                ...           latest (9 years ago)

35 Versions

  • 3.3.4 [deprecated]           ...           9 years ago
  • 3.3.3 [deprecated]           ...           9 years ago
  • 3.3.2 [deprecated]           ...           9 years ago
  • 3.3.1 [deprecated]           ...           9 years ago
  • 3.3.0 [deprecated]           ...           9 years ago
  • 3.2.2 [deprecated]           ...           9 years ago
  • 3.2.1 [deprecated]           ...           9 years ago
  • 3.2.0 [deprecated]           ...           9 years ago
  • 3.1.2 [deprecated]           ...           9 years ago
  • 3.1.1 [deprecated]           ...           9 years ago
  • 3.1.0 [deprecated]           ...           9 years ago
  • 3.0.1 [deprecated]           ...           9 years ago
  • 3.0.0 [deprecated]           ...           10 years ago
  • 2.3.0 [deprecated]           ...           10 years ago
  • 2.2.1 [deprecated]           ...           10 years ago
  • 2.2.0 [deprecated]           ...           10 years ago
  • 2.1.0 [deprecated]           ...           10 years ago
  • 2.0.1 [deprecated]           ...           10 years ago
  • 2.0.0 [deprecated]           ...           10 years ago
  • 1.0.2 [deprecated]           ...           11 years ago
  • 1.0.0 [deprecated]           ...           11 years ago
  • 0.4.3 [deprecated]           ...           11 years ago
  • 0.4.2 [deprecated]           ...           11 years ago
  • 0.4.1 [deprecated]           ...           11 years ago
  • 0.4.0 [deprecated]           ...           11 years ago
  • 0.3.1 [deprecated]           ...           11 years ago
  • 0.3.0 [deprecated]           ...           11 years ago
  • 0.2.4 [deprecated]           ...           11 years ago
  • 0.2.3 [deprecated]           ...           11 years ago
  • 0.2.2 [deprecated]           ...           11 years ago
  • 0.2.1 [deprecated]           ...           11 years ago
  • 0.2.0 [deprecated]           ...           11 years ago
  • 0.1.1 [deprecated]           ...           11 years ago
  • 0.1.0 [deprecated]           ...           12 years ago
  • 0.0.1 [deprecated]           ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 17
Last Day 0
Last Week 17
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |