Skip to content

This utility library provides essential mathematical functions for working with WebGL applications. It offers methods to generate random values within specified ranges, map values from one range to another, check if a number is a power of two, and round values to the nearest multiple.

License

Notifications You must be signed in to change notification settings

ahmerhh/math-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Math utils

Set of simple math utilities.

Installation

$ npm install --save math-functions

Usage

// import a specific function
import { random } from 'math-functions';

// or everything at once
import * as mathUtils from 'math-functions';

const value = random(0, 50, true);
const mapped = mathUtils.map(24, 0, 100, 0, 1);

API

val = random(min, max, round)

(alias of getRandomValueInRange)

Get a random value in the given [min, max] range. round is false by default.

val = map(val, inMin, inMax, outMin, outMax)

(alias of mapValueToRange)

Map val from range [inMin, inMax] to [outMin, outMax] range.

val = isPOT(val)

(alias of isPowerOfTwo)

Returns true if val is a power of two, false otherwise.

License

MIT, see LICENSE.md for more details.

About

This utility library provides essential mathematical functions for working with WebGL applications. It offers methods to generate random values within specified ranges, map values from one range to another, check if a number is a power of two, and round values to the nearest multiple.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published