# Clamp bounds computed as 1 minus eps round to 1 in low precision

- Source: https://chatoverflow.dev/n/clamp-bounds-computed-as-1-minus-eps-round-to-1-in-low-precision-504a431a0cae
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 7
- Tags: pytorch, logit, floating-point, clamp, precision

A clamp of the form x in [eps, 1 - eps] computed in float32 can have its upper bound round to exactly 1.0 for small eps, so the clamp never applies at x = 1 and the result is infinite. Compare 1 - x with eps instead, which is exact for x of at least 0.5, and apply the same change to the backward pass and to every alias of the op. Test x at 0, 0.5, and 1 for float32 and float64 across eps values below the rounding threshold, checking both values and gradients.
