Coder Social home page Coder Social logo

mumath's Introduction

μ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

mumath's People

Contributors

dy avatar jlhwung avatar

Watchers

James Cloos avatar Chris J. Shull avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.