Skip to content

Commit e0f93a8

Browse files
authored
Merge pull request #3239 from Zac-HD/error-on-fast-math
Error if denormals-are-zero
2 parents e6ed6bd + 8052e6b commit e0f93a8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
RELEASE_TYPE: minor
2+
3+
This release makes :func:`~hypothesis.strategies.floats` error *consistently* when
4+
your floating-point hardware has been configured to violate IEEE-754 for
5+
:wikipedia:`subnormal numbers <Subnormal_number>`, instead of
6+
only when an internal assertion was tripped (:issue:`3092`).
7+
8+
If this happens to you, passing ``allow_subnormal=False`` will suppress the explicit
9+
error. However, we strongly recommend fixing the root cause by disabling global-effect
10+
unsafe-math compiler options instead, or at least consulting e.g. Simon Byrne's
11+
`Beware of fast-math <https://simonbyrne.github.io/notes/fastmath/>`__ explainer first.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,22 @@ def floats(
342342
check_valid_bound(min_value, "min_value")
343343
check_valid_bound(max_value, "max_value")
344344

345+
if allow_subnormal and next_up(0.0, width=width) == 0: # pragma: no cover
346+
# Not worth having separate CI envs and dependencies just to cover this branch;
347+
# discussion in https://github.com/HypothesisWorks/hypothesis/issues/3092
348+
#
349+
# Erroring out here ensures that the database contents are interpreted
350+
# consistently - which matters for such a foundational strategy, even if it's
351+
# not always true for all user-composed strategies further up the stack.
352+
raise FloatingPointError(
353+
f"Got allow_subnormal={allow_subnormal!r}, but we can't represent "
354+
f"subnormal floats right now, in violation of the IEEE-754 floating-point "
355+
f"specification. This is usually because something was compiled with "
356+
f"-ffast-math or a similar option, which sets global processor state. "
357+
f"See https://simonbyrne.github.io/notes/fastmath/ for a more detailed "
358+
f"writeup - and good luck!"
359+
)
360+
345361
min_arg, max_arg = min_value, max_value
346362
if min_value is not None:
347363
min_value = float_of(min_value, width)

0 commit comments

Comments
 (0)