
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@okiba/math
Advanced tools
Collection of math functions
You can grab it as an npm package
npm i --save @okiba/math
Or use it in the browser
<!-- Minified -->
<script src="https://unpkg.com/@okiba/math@1.0.11/dist/index.min.js"></script>
<!-- Full -->
<script src="https://unpkg.com/@okiba/math@1.0.11/dist/index.js"></script>
Linear interpolation between a two values
import {lerp} from '@okiba/math'
const xPosition = lerp(0, 100, 0.5)
console.log(xPosition) // 50
min: NumberMinimum possible value
max: NumberMaximum possible value
fraction: NumberCurrent position
Number The interpolated value
Maps a value between two ranges
import {map} from '@okiba/math'
const x = map(0.5, 0, 1, 0, 1000)
console.log(x) // 500
const y = map(0, -1, 1, -1000, 1000)
console.log(y) // 0
n: NumberValue to map
min1: NumberSource range minimum
max1: NumberSource range maximum
min2: NumberTarget range minimum
max2: NumberTarget range maximum
Number Mapped value
Limit a value between a min and a max (inclusive)
import {cap} from '@okiba/math'
let progress = 1.1
progress = cap(0, 1, progress)
console.log(progress) // 1
n: NumberValue to cap
min: NumberMinimum possible value
max: NumberMaximum possible value
Number Capped value
Distance between two numbers
import {distance} from '@okiba/math'
const x1 = -100, x2 = 100
const d = distance(x1, x2)
console.log(d) // 200
x1: NumberFirst number
x2: NumberSecond number
Number Distance between the values
Round a number with given precision, with memoized powers
import {round} from '@okiba/math'
const rounded = distance(1.111111, 3)
console.log(rounded) // 1.111
n: NumberNumber to round
p: Number | optional - default: 3Precision of digits to leave
Number Rounded number
FAQs
Math functions used in okiba.js
The npm package @okiba/math receives a total of 5 weekly downloads. As such, @okiba/math popularity was classified as not popular.
We found that @okiba/math demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.