Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/core/friendly_errors/validate_params.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ if (typeof IS_MINIFIED !== 'undefined') {
* @returns {Boolean} a boolean indicating whether input type is Number
*/
const isNumber = param => {
if (isNaN(parseFloat(param))) return false;
switch (typeof param) {
case 'number':
return true;
case 'string':
return !isNaN(param);
default:
return false;
// Treat numeric Infinity values as numbers
if (param === Infinity || param === -Infinity) return true;
// Real numbers (exclude NaN)
if (typeof param === 'number') return !isNaN(param);
// Accept numeric strings (including "Infinity"/"-Infinity")
if (typeof param === 'string') {
return param.trim() !== '' && !isNaN(Number(param));
}
return false;
};

/**
Expand Down
24 changes: 24 additions & 0 deletions test/unit/math/calculation.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ suite('Calculation', function() {
result = myp5.max([10, 10]);
assert.equal(result, 10);
});
test('should handle Infinity', function() {
result = myp5.max(3, Infinity);
assert.equal(result, Infinity);
});
test('should handle -Infinity', function() {
result = myp5.max(3, -Infinity);
assert.equal(result, 3);
});
test('should handle Infinity in array', function() {
result = myp5.max([3, Infinity, 5]);
assert.equal(result, Infinity);
});
});

suite('p5.prototype.min', function() {
Expand Down Expand Up @@ -325,6 +337,18 @@ suite('Calculation', function() {
result = myp5.min([10, 10]);
assert.equal(result, 10);
});
test('should handle Infinity', function() {
result = myp5.min(Infinity, 3);
assert.equal(result, 3);
});
test('should handle -Infinity', function() {
result = myp5.min(3, -Infinity);
assert.equal(result, -Infinity);
});
test('should handle -Infinity in array', function() {
result = myp5.min([3, -Infinity, 5]);
assert.equal(result, -Infinity);
});
});

suite('p5.prototype.norm', function() {
Expand Down