# mumath

> Practical math utils for components

Latest version **3.3.4** (published 2017-03-08) · Unlicense license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install mumath
pnpm add mumath
yarn add mumath
bun add mumath
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.3.4 |
| Published | 2017-03-08 |
| First published | 2014-09-12 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | separate (@types/mumath) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | dfcreative |
| Maintainers | dfcreative |
| Keywords | math, geometry |

## Links

- npm: https://www.npmjs.com/package/mumath
- Repository: https://github.com/dfcreative/mumath
- Issues: https://github.com/dfcreative/mumath/issues
- npm.io page: https://npm.io/package/mumath

## Dependencies (1)

- [almost-equal](https://npm.io/package/almost-equal.md) ^1.1.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 3.3.4 (latest) — 2017-03-08
- 3.3.3 — 2017-01-23
- 3.3.2 — 2017-01-23
- 3.3.1 — 2016-10-23
- 3.3.0 — 2016-10-23
- 3.2.2 — 2016-10-22
- 3.2.1 — 2016-10-22
- 3.2.0 — 2016-10-22
- 3.1.2 — 2016-10-22
- 3.1.1 — 2016-10-22
- 3.1.0 — 2016-10-22
- 3.0.1 — 2016-10-22
- 3.0.0 — 2016-08-14
- 2.3.0 — 2016-06-26
- 2.2.1 — 2016-05-16
- … 20 more at https://npm.io/package/mumath/versions

## README

# μMath [![Build Status](https://travis-ci.org/dfcreative/mumath.svg?branch=master)](https://travis-ci.org/dfcreative/mumath) [![Code Climate](https://codeclimate.com/github/dfcreative/mumath/badges/gpa.svg)](https://codeclimate.com/github/dfcreative/mumath) <a href="UNLICENSE"><img src="http://upload.wikimedia.org/wikipedia/commons/6/62/PD-icon.svg" width="20"/></a>

Set of practical math utils to shorten code.

[`$ npm install mumath`](https://npmjs.org/package/mumath)

```js
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](http://npmjs.org/package/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

* [bit-twiddle](https://www.npmjs.com/package/bit-twiddle) — utils for power-of-two numbers.
* [pretty-number](https://www.npmjs.com/package/pretty-number) — format number to pretty view.

---
_Source: https://npm.io/package/mumath · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
