Repository URL to install this package:
|
Version:
1.0.0-beta.6.webpack ▾
|
import math from 'mathjs';
export function roundUpTo(_value, _increment = 1) {
// return Math.ceil(value / increment) * increment;
let value = math.bignumber(_value);
let increment = math.bignumber(_increment);
return math.number(
math.multiply(
math.ceil(
math.divide(
value,
increment
)
),
increment
)
);
}
export function roundDownTo(_value, _increment = 1) {
// return Math.floor(value / increment) * increment;
let value = math.bignumber(_value);
let increment = math.bignumber(_increment);
return math.number(
math.multiply(
math.floor(
math.divide(
value,
increment
)
),
increment
)
);
}
export function constrain(_value, min = -Infinity, max = Infinity) {
let value = _value;
if (max === min) {
return max;
} else if (max < min) {
throw new Error('Max must be larger than min');
}
if (min !== -Infinity) {
value = Math.max(value, min);
}
if (max !== Infinity) {
value = Math.min(value, max);
}
return value;
}