Skip to content
Subhajit Sahu edited this page Aug 9, 2022 · 2 revisions

Re-map a number from one range to another.

Similar: constrain, normalize, remap, lerp.


function remap(x, r, R, t, T)
// x: a number
// r: lower bound of current range
// R: upper bound of current range
// t: lower bound of target range
// T: upper bound of target range

const xnumber = require('extra-number');


xnumber.remap(25, 0, 100, 0, 1366);
// → 341.5

xnumber.remap(110, 0, 100, -20, -10);
// → -9


References

Clone this wiki locally