Skip to content

Try to find bit representation mismatch #1

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

Closed
wants to merge 5 commits into from
Closed

Try to find bit representation mismatch #1

wants to merge 5 commits into from

Conversation

youknowone
Copy link
Member

@youknowone youknowone commented Apr 20, 2025

On aarch64-apple-darwin,

x is input.
Left is CPython, right is pymath

thread 'gamma::tests::test_tgamma' panicked at src/gamma.rs:303:17:
assertion `left == right` failed: x = -3.8510064710745118, py_gamma = 0.36222232384328107, rs_gamma = 0.36222232384328096
  left: 4600196837208649423
 right: 4600196837208649421

thread 'gamma::tests::test_tgamma' panicked at src/gamma.rs:303:17:
assertion `left == right` failed: x = -3.8510064710745118, py_gamma = 0.36222232384328107, rs_gamma = 0.36222232384328096
  left: 4600196837208649423
 right: 4600196837208649421

thread 'gamma::tests::test_tgamma' panicked at src/gamma.rs:286:5:
Test failed: assertion `left == right` failed: x = -3.8510064710745118, py_gamma = 0.36222232384328107, rs_gamma = 0.36222232384328096
  left: 4600196837[208](https://github.com/RustPython/pymath/actions/runs/14565988158/job/40855284918?pr=2#step:6:209)649423
 right: 4600196837208649421.
minimal failing input: x = -3.8510064710745118
	successes: 0
	local rejects: 0
	global rejects: 0

On x86_64-unknown-linux-gnu,

x = -3.8510064710745118
py_gamma = 0.36222232384328096
rs_gamma = 0.36222232384328096
py_gamma_repr = 4600196837208649421
rs_gamma_repr = 4600196837208649421

Since CPython and pymath produces identical bit representations in both x86 Linux and Windows, and also aarch64 macOS pymath produce the same, it would be worthwhile to verify if the macOS build of CPython is designed to output these consistent values.

@youknowone
Copy link
Member Author

tgamma.c in x86_64 linux:

$ clang -lm tgamma.c -ffp-contract=off && ./a.out The result of tgamma(-3.8510064710745118) is: 0.362222
Bit representation of result: 4600196837208649421
$ clang -lm tgamma.c -ffp-contract=on && ./a.out 
The result of tgamma(-3.8510064710745118) is: 0.362222
Bit representation of result: 4600196837208649421

tgamma.c in aarch64 macos:

$  clang -lm tgamma.c -ffp-contract=off && ./a.out
The result of tgamma(-3.8510064710745118) is: 0.362222
Bit representation of result: 4600196837208649421
$  clang -lm tgamma.c -ffp-contract=on && ./a.out
The result of tgamma(-3.8510064710745118) is: 0.362222
Bit representation of result: 4600196837208649423

@youknowone
Copy link
Member Author

Bug report to check if this is a bug or not python/cpython#132763

@youknowone
Copy link
Member Author

See #4 for how to make binary representation compatibility
See #6 for why we should not

See linked CPython issue for the details

@youknowone youknowone closed this Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant