Add zero-range guard to map() to prevent NaN/Infinity when start1 equals stop1
Open
Nobody has claimed this yet.
Area:Math
Bug
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- p5.strands
- WebGL
- DevOps, Build process, Unit testing
- Internationalization (i18n)
- Friendly Errors
- Other (specify if possible)
p5.js version
Latest main branch (development version from the repository)
Web browser and version
All browsers — issue is in core math logic, not rendering
Operating system
macOS (development environment)
Steps to reproduce this
Steps:
- Call map() with a collapsed input range (start1 === stop1)
- Example: map(5, 10, 10, 0, 100)
- The result becomes Infinity or NaN due to division by zero
Snippet:
// This produces Infinity or NaN:
let x = map(5, 10, 10, 0, 100);
console.log(x); // Infinity or NaN
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating p5.js's map() entry point and reproduce map(5, 10, 10, 0, 100). Check the surrounding map tests or conventions to determine the intended result for a collapsed input range. Done means this case has defined behavior and no longer produces NaN or Infinity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100