Skip to content

Commit

Permalink
clamp nan
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Dec 24, 2024
1 parent 61a22d4 commit 8be3633
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hypothesis-python/src/hypothesis/internal/floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ def sign_aware_lte(x: float, y: float) -> bool:

def clamp(lower: float, value: float, upper: float) -> float:
"""Given a value and lower/upper bounds, 'clamp' the value so that
it satisfies lower <= value <= upper."""
it satisfies lower <= value <= upper. NaN is mapped to lower."""
# this seems pointless (and is for integers), but handles the -0.0/0.0 case.
if sign_aware_lte(value, lower):
if not sign_aware_lte(lower, value):
return lower
if sign_aware_lte(upper, value):
if not sign_aware_lte(value, upper):
return upper
return value

Expand Down

0 comments on commit 8be3633

Please sign in to comment.