Skip to content

Conversation

@menacingly-coded
Copy link
Contributor

@menacingly-coded menacingly-coded commented Jan 8, 2026

Resolves #8104

Description:
This pull request fixes the behavior of the min() and max() functions in p5.js when called with Infinity or -Infinity. Previously, passing infinite values triggered a “friendly error,” even though comparisons involving infinities are valid JavaScript behavior. This restores consistent and expected functionality for edge numeric values, closing the unexpected error reported in issue #8104 .

Changes:
-Updated the internal logic used to validate arguments for min() and max() so that Infinity and -Infinity are no longer treated as invalid.

-Refactored condition checks to respect valid number comparisons without throwing unnecessary friendly errors.

-Added unit tests covering numeric edge cases including infinite values, ensuring correct results are returned for all valid numerical inputs.

How To Test:
console.log(min(Infinity, 42)); // Should log 42
console.log(max(-Infinity, 42)); // Should log 42
console.log(min(Infinity, -Infinity)); // Should behave consistently

PR Checklist

@perminder-17 perminder-17 self-requested a review January 10, 2026 18:18
Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we did a pretty large refactor, I'll probably give a look to this again.

Thanks for your work on this @menacingly-coded , looks nice so far.

@menacingly-coded
Copy link
Contributor Author

@perminder-17 , Thanks for reviewing this.
The added conditions were necessary for correctness, which is why the refactor grew a bit.
Open to refining it further if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants