Skip to content

Add zero-range guard to map() to prevent NaN/Infinity when start1 equals stop1 #8282

@VIPAX-JIT

Description

@VIPAX-JIT

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:

  1. Call map() with a collapsed input range (start1 === stop1)
  2. Example: map(5, 10, 10, 0, 100)
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions