Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The mumath npm package provides a collection of mathematical utilities for common operations such as rounding, clamping, and interpolation. It is designed to be lightweight and easy to use for basic mathematical tasks.
Rounding
The rounding feature allows you to round numbers to the nearest integer. The code sample demonstrates rounding 4.6 up to 5 and 4.4 down to 4.
const mumath = require('mumath');
console.log(mumath.round(4.6)); // 5
console.log(mumath.round(4.4)); // 4
Clamping
The clamping feature restricts a number to be within a specified range. The code sample shows clamping 10 to the maximum value of 5 and -1 to the minimum value of 0.
const mumath = require('mumath');
console.log(mumath.clamp(10, 0, 5)); // 5
console.log(mumath.clamp(-1, 0, 5)); // 0
Interpolation
The interpolation feature allows you to find a value at a specific point between two numbers. The code sample demonstrates finding the midpoint (0.5) between 0 and 10, which is 5.
const mumath = require('mumath');
console.log(mumath.lerp(0, 10, 0.5)); // 5
Math.js is an extensive math library for JavaScript and Node.js. It provides a wide range of mathematical functions and supports complex numbers, matrices, and units. Compared to mumath, math.js offers a broader set of features and is suitable for more complex mathematical operations.
Lodash is a utility library that provides functions for common programming tasks, including mathematical operations. It includes methods for rounding, clamping, and interpolation, similar to mumath. However, Lodash is a more comprehensive library that covers a wide range of utilities beyond just math.
Numeral.js is a library for formatting and manipulating numbers. While it focuses more on number formatting and parsing, it also provides some basic mathematical operations. Compared to mumath, Numeral.js is more specialized in number formatting rather than general mathematical utilities.
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>');
round(value, step?)
Rounds value to optional step
.
round(0.3, .5)
→ .5
normalize(flt)
Get rid of float remainder.
n(-0.4999999999999998)
→ -.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.
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.
pretty(a, positions?)
DEPRECATED: rounding floats is non-trivial task
Format number into human-readable form. Like toFixed
, but works good.
bit-twiddle — utils for power-of-two numbers.
FAQs
Practical math utils for components
The npm package mumath receives a total of 75,761 weekly downloads. As such, mumath popularity was classified as popular.
We found that mumath demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.