-
Notifications
You must be signed in to change notification settings - Fork 586
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
Float strategy generates -0.0 for max_value=0.0 when exclude_max=True #2201
Comments
FWIW this was intentional as it exposes the underlying - and I agree unintuitive - behaviour of IEEE754 floats regarding signed zeros. I can see that it might be a better compromise to ensure that excluding either zero excludes both though! |
|
I think regardless of what we decide as the API our documentation of the floats strategy needs to clearly signal it - right now it's pretty non-obvious from the documentation that this is the behaviour! |
Was there any reason in particular to distinguish between signed/unsigned zeros in next_up? In any case, should this still be the desired behaviour, then I definitely agree that the docs should be made clearer! But I do think that the API should exclude both zeros in exclude_min/max. |
Yes - they are in fact distinct values, and code - including |
|
I understand that they are distinct values and that treating -0.0 as 0.0, as was done before, would break the property you describe. My point was just that other properties one would intuitively expect are Is it more important to guarantee that Anyway, thanks for the helpful responses! |
|
Huh, it turns out that the IEEE754 standard prefers the opposite convention to us: " Fortunately our I'm more confident now that changing the public-facing behaviour is correct, though! |
As a user, I'd expect values drawn from a strategy with
exclude_max=Trueto have the invariantvalue < max_value. However, I discovered that a floats strategy with max_value set to 0.0 can generate -0.0 even ifexclude_max=True. This is unexpected since 0.0 == -0.0.Example program (hypothesis 4.43.6):
Example output (excluding traceback):
The issue seems to stem from changes to
floats.pyin 36d641d. The version of prior to this commit matches the referenced Stack Overflow solution and would not cause this particular issue.If I understood it correctly, PR #1860 solved the issue of
floats(min_value=0.0, max_value=-0.0)and excluding endpoints at infinity ( #1859).Perhaps this was an unintended side-effect?
For now, I can avoid this with, for instance:
but this should not really be necessary. Would it be possible to consolidate solutions to both issues?
The text was updated successfully, but these errors were encountered: