GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-130317: fix PyFloat_Pack/Unpack[24] for NaN's with payload by skirpichev · Pull Request #130452 · python/cpython Conversation
|
|
Ok, I've added new tests in test_capi.test_floats (in principle, test_struct's tests are redundant). win32 behavior (you can't unset "quiet" bit for NaN) looks as a bug for me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Any idea why there is a bug only on Windows? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Only on win32. Though, I suspect the situation could be worse. Maybe I should revert win32-workaround and test this with some buildbots? C17 says: "This specification does not define the behavior of signaling NaNs." But I don't think this means you can't flip appropriate bit in float/double to make a signaling NaN. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, I think it's ready for review. Test for Windows failed in 32-bit mode (signaling NaN type not preserved in roundtrip), that seems to be a known issue: https://developercommunity.visualstudio.com/t/155064 (sNaN returned from function becomes qNaN). See also https://developercommunity.visualstudio.com/t/903305 and https://en.delphipraxis.net/topic/12198-delphi-win32-quiets-signaling-nan-on-function-return/. In principle, it's possible to workaround this for the struct module. But not for C-API ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I just have some minor comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| def test_pack_unpack_roundtrip_for_nans(self): | ||
| pack = _testcapi.float_pack | ||
| unpack = _testcapi.float_unpack | ||
| for _ in range(1000): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
100 tests should be enough to validate the implementation, no?
| for _ in range(1000): | |
| for _ in range(100): |
1000 tests might be a little bit too slow, I don't think that it's worth it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Up to you, the test looks instantaneous on my system. 0.3sec vs 0.03. Where the threshold?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think speed is really an issue here, but having the potential for 6000 failed test reports seems like major overkill. I think 10 would actually be plenty for this loop.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <[email protected]>
|
Merged, thank you. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Should we backport this change? It's unclear to me if it's a new feature or a bugfix. The issue is reported as a bug report. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Strictly speaking, it's a bug, though maybe a very minor one (that's why there was no label for 3.13 backport). From IEEE 754 (2008), 6.2.3: "Conversion of a quiet NaN from a narrower format to a wider format in the same radix, and then back to the same narrower format, should not change the quiet NaN payload in any way except to make it canonical." E.g. in C nan's payload is preserved in conversions (e.g. float->double) or partially preserved (e.g. double -> float). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
test_capi.test_float fails on x86 Debian Installed with X 3.x: https://buildbot.python.org/#/builders/1244/builds/5176 test.pythoninfo: There are failures on 16, 32 and 64 bit floats (size: 2, 4, 8). Examples: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I can reproduce the issue on Fedora 42 by building Python using |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hmm, again in all cases sNaN seems transformed to qNaN. I think underlying reason is same and we should apply workaround for 32-bit modes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I replaced |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Aha, just copying a double to another double clears the sNaN flag: d is not equal to ob_fval. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The sNaN flag is easily lost. I added some debug of the uint64_t value in different functions. Between float_pack() and PyFloat_Pack4(), the sNaN flag is lost: PyFloat_Pack4() is called with the wrong value :-( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Hmm, indeed. I should finally do memcpy() to created PyFloat's ob_fval, then return it. Does it work: ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I wrote #133150 to fix 3 bugs, but it's not enough to fix the test on x86. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Tests were fixed by #133204. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.