plotly.js
Version:
The open source javascript graphing library that powers plotly
26 lines (25 loc) • 699 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mod = mod;
exports.modHalf = modHalf;
/**
* Sanitized modulus function that always returns in the range [0, d)
* rather than (-d, 0] if v is negative.
*
* @param v - dividend
* @param d - divisor (the modulus); assumed positive
*/
function mod(v, d) {
const out = v % d;
return out < 0 ? out + d : out;
}
/**
* Sanitized modulus function that always returns in the range [-d/2, d/2]
* rather than (-d, 0] if v is negative.
*
* @param v - dividend
* @param d - divisor (the modulus); assumed positive
*/
function modHalf(v, d) {
return Math.abs(v) > d / 2 ? v - Math.round(v / d) * d : v;
}