Skip to content

Conversation

@roelandschoukens
Copy link

@roelandschoukens roelandschoukens commented Jan 13, 2026

Description

The division (xclamped - edge0) / (edge1 - edge0) is not guaranteed to be exactly 1 for xclamped == edge1 if the backend floating point math has higher than expected error bounds. Eg. it is common on GPU backends to use faster but less precise instructions for division.

The modified code is mathematically equivalent and it logically guarantees the returned value is exactly 1.0 for x > edge1 > edge0.

Fixes #2063

Tests

This should not break the existing test for linearstep. A difference in behaviour will be observed only on back-ends that implement some form of fast math.

Checklist:

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have ensured that the change is tested somewhere in the testsuite (adding new test cases if necessary).
  • My code follows the prevailing code style of this project. If I haven't
    already run clang-format v17 before submitting, I definitely will look at
    the CI test that runs clang-format and fix anything that it highlights as
    being nonconforming.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 13, 2026

CLA Not Signed

The division (xclamped - edge0) / (edge1 - edge0) is not guaranteed
to be exactly 1 for xclamped == edge1 if the backend floating point
math has higher than expected error bounds. Eg. it is common on GPU
backends to use faster but less precise instructions for division.

The modified code is mathematically equivalent and it logically
guarantees the returned value is exactly 1.0 for x > edge1 > edge0.
@lgritz
Copy link
Collaborator

lgritz commented Jan 15, 2026

You seem to still need DCO and CLA fixed up

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.

[BUG] linearstep is not guaranteed to return exactly 0 or 1 outside the edges

2 participants