fix(range-map): guard the zero-width from range instead of dividing by zero - #96
Open
eeshsaxena wants to merge 1 commit into
Open
fix(range-map): guard the zero-width from range instead of dividing by zero#96eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
Conversation
…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
force-pushed
the
fix/range-map-zero-span
branch
from
August 6, 2026 04:50
5802ebe to
e73cc98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
RangeMapcomputes(input - from.min) * (to.max - to.min) / (from.max - from.min) + to.minin both the runtime preview and the generated C++. A zero-widthfromrange (min == max) divides by zero, producinginf/nanthat 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:range_map.rs): guardif in_max == in_min.emit): thefromrange is constant at codegen time, so emitto.mindirectly instead of the division.Adds a codegen test for the zero-span case (
from5..5maps toto.minwithout emitting the(5.0 - 5.0)division).