Skip to content

Commit 6d3e355

Browse files
VIPAX-JITVIPAX-JIT
authored andcommitted
fix(math): add zero-range guard to map() to prevent NaN/Infinity
1 parent ff2e5c3 commit 6d3e355

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/math/calculation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ p5.prototype.mag = function(x, y) {
604604
*/
605605
p5.prototype.map = function(n, start1, stop1, start2, stop2, withinBounds) {
606606
p5._validateParameters('map', arguments);
607+
// NEW: guard against zero input range to avoid division by zero
608+
if (start1 === stop1) {
609+
return start2;
610+
}
607611
const newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2;
608612
if (!withinBounds) {
609613
return newval;

0 commit comments

Comments
 (0)