Skip to content

constrain

Subhajit Sahu edited this page Aug 9, 2022 · 1 revision

Constrain a bigint within a minimum and a maximum value.

Similar: constrain, normalize, remap, lerp.


function constrain(x, minv, maxv)
// x:    a bigint
// minv: minimum value
// maxv: maximum value

const xbigint = require('extra-bigint');


xbigint.constrain(20n, 0n, 50n);
// → 20n

xbigint.constrain(-10n, 0n, 100n);
// → 0n

xbigint.constrain(120n, 0n, 100n);
// → 100n


References

Clone this wiki locally