Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floats() does not generate subnormal floating-point values #2976

Closed
Zac-HD opened this issue May 25, 2021 · 1 comment · Fixed by #3152
Closed

floats() does not generate subnormal floating-point values #2976

Zac-HD opened this issue May 25, 2021 · 1 comment · Fixed by #3152
Assignees
Labels
bug something is clearly wrong here

Comments

@Zac-HD
Copy link
Member

Zac-HD commented May 25, 2021

# Tests whether we can represent subnormal floating point numbers.
# This is essentially a function of how the python interpreter
# was compiled.
# Everything is terrible
if math.ldexp(0.25, -1022) > 0:
REALLY_SMALL_FLOAT = sys.float_info.min
else:
REALLY_SMALL_FLOAT = sys.float_info.min * 2
# These two tests have been failing for an unknown amount of time, but that
# failure was previously being masked by a bug in our `@fails` decorator.
@pytest.mark.xfail
@fails
@given(floats())
@TRY_HARDER
def test_can_generate_really_small_positive_floats(x):
assume(x > 0)
assert x >= REALLY_SMALL_FLOAT
@pytest.mark.xfail
@fails
@given(floats())
@TRY_HARDER
def test_can_generate_really_small_negative_floats(x):
assume(x < 0)
assert x <= -REALLY_SMALL_FLOAT

This was discovered in #2973, but out of scope for that PR. The first step is to determine when, if ever, this did work; what (if anything) changed to break it, and then to get subnormal-float generation working.

@Zac-HD Zac-HD added the bug something is clearly wrong here label May 25, 2021
@Zac-HD
Copy link
Member Author

Zac-HD commented Nov 16, 2021

OK, on investigation it is strictly speaking possible for us to generate subnormal values; it's just that we do so with negligible probability because they only occur for one-in-2^11 possible exponents. The obvious workaround is to just add a handful of special values to our NASTY_FLOATS table...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant