Skip to content

Commit d555dc1

Browse files
committed
Move our next_*_normal helpers to internal.floats
1 parent 6882087 commit d555dc1

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

hypothesis-python/src/hypothesis/internal/floats.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ def next_down(value, width=64):
102102
return -next_up(-value, width)
103103

104104

105+
def next_down_normal(value, width, allow_subnormal):
106+
value = next_down(value, width)
107+
if (not allow_subnormal) and 0 < abs(value) < width_smallest_normals[width]:
108+
return 0.0 if value > 0 else -width_smallest_normals[width]
109+
return value
110+
111+
112+
def next_up_normal(value, width, allow_subnormal):
113+
return -next_down_normal(-value, width, allow_subnormal)
114+
115+
105116
# Smallest positive non-zero numbers that is fully representable by an
106117
# IEEE-754 float, calculated with the width's associated minimum exponent.
107118
# Values from https://en.wikipedia.org/wiki/IEEE_754#Basic_and_interchange_formats

hypothesis-python/src/hypothesis/strategies/_internal/numbers.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
float_to_int,
3232
int_to_float,
3333
is_negative,
34-
next_down,
34+
next_down_normal,
3535
next_up,
36+
next_up_normal,
3637
width_smallest_normals,
3738
)
3839
from hypothesis.internal.validation import (
@@ -279,17 +280,6 @@ def do_draw(self, data):
279280
return f
280281

281282

282-
def next_down_normal(value, width, allow_subnormal):
283-
value = next_down(value, width)
284-
if (not allow_subnormal) and 0 < abs(value) < width_smallest_normals[width]:
285-
return 0.0 if value > 0 else -width_smallest_normals[width]
286-
return value
287-
288-
289-
def next_up_normal(value, width, allow_subnormal):
290-
return -next_down_normal(-value, width, allow_subnormal)
291-
292-
293283
@cacheable
294284
@defines_strategy(force_reusable_values=True)
295285
def floats(

0 commit comments

Comments
 (0)