Skip to content

fix(range-map): guard the zero-width from range instead of dividing by zero - #96

Open
eeshsaxena wants to merge 1 commit into
xiduzo:mainfrom
eeshsaxena:fix/range-map-zero-span
Open

fix(range-map): guard the zero-width from range instead of dividing by zero#96
eeshsaxena wants to merge 1 commit into
xiduzo:mainfrom
eeshsaxena:fix/range-map-zero-span

Conversation

@eeshsaxena

Copy link
Copy Markdown
Contributor

What

RangeMap computes (input - from.min) * (to.max - to.min) / (from.max - from.min) + to.min in both the runtime preview and the generated C++. A zero-width from range (min == max) divides by zero, producing inf/nan that then propagates to whatever the node drives (a servo angle, LED brightness, pixel value), silently.

Fix

Collapse the degenerate range to the low output bound (to.min) in both places:

  • runtime (range_map.rs): guard if in_max == in_min.
  • codegen (emit): the from range is constant at codegen time, so emit to.min directly instead of the division.

Adds a codegen test for the zero-span case (from 5..5 maps to to.min without emitting the (5.0 - 5.0) division).

…y zero

RangeMap computes (input - from.min) * (to.max - to.min) / (from.max - from.min)
+ to.min in both the runtime and the generated C++. A zero-width from range
(min == max) divides by zero, producing inf/nan that then propagates to whatever
the node drives (servo angle, LED brightness, ...).

Collapse the degenerate range to the low output bound (to.min) in both the
runtime (range_map.rs) and the codegen (decided at codegen time since the range
is constant). Adds a codegen test for the zero-span case.
@eeshsaxena
eeshsaxena force-pushed the fix/range-map-zero-span branch from 5802ebe to e73cc98 Compare August 6, 2026 04:50
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.

1 participant