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

Rare float overflow bug in complex_numbers strategy #1748

Closed
Zac-HD opened this issue Jan 8, 2019 · 1 comment · Fixed by #1772
Closed

Rare float overflow bug in complex_numbers strategy #1748

Zac-HD opened this issue Jan 8, 2019 · 1 comment · Fixed by #1772
Assignees
Labels
bug something is clearly wrong here

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Jan 8, 2019

Hypothesis 3.86.0 made floats(min_value=inf, allow_infinity=False) an error, because the arguments are contradictory and thus impossible to satisfy.

Many test runs later, it turns out that this condition can sometimes be triggered by the following test:

@given(st.data(), st.floats(0, allow_infinity=False, allow_nan=False))
def test_minmax_magnitude_equal(data, mag):
val = data.draw(st.complex_numbers(min_magnitude=mag, max_magnitude=mag))

Step one is obviously to write a test which can quickly trigger this bug (e.g. by only passing very large magnitude bounds), but by inspection I'm pretty sure it's somewhere in the following lines:

if max_magnitude is None:
zi = draw(floats(**allow_kw))
rmax = float("inf")
else:
zi = draw(floats(-max_magnitude, max_magnitude, **allow_kw))
rmax = cathetus(max_magnitude, zi)
# Draw the real part from the allowed range given the imaginary part
if min_magnitude is None or math.fabs(zi) >= min_magnitude:
zr = draw(floats(-rmax, rmax, **allow_kw))
else:
zr = draw(floats(cathetus(min_magnitude, zi), rmax, **allow_kw))

@Zac-HD Zac-HD added the bug something is clearly wrong here label Jan 8, 2019
@Zac-HD Zac-HD assigned Zac-HD and unassigned Zac-HD Jan 11, 2019
@Zac-HD
Copy link
Member Author

Zac-HD commented Jan 22, 2019

Three times today 😭

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