Skip to content

math.gamma result slightly different on aarch64-apple-darwin #132763

Closed as not planned
@youknowone

Description

@youknowone

Bug report

Bug description:

The difference is watched from distributions.
Because the result is changed by fp-contract. It may not be strictly a bug in source code, but can be a bug of build & distrubition.

On x86_64 linux:

Python 3.13.3 (main, Apr 21 2025, 11:31:07) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import math; math.gamma(-3.8510064710745118)
0.36222232384328096

On aarch64 macOS:

Python 3.13.2 (main, Feb  4 2025, 14:51:09) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math; math.gamma(-3.8510064710745118)
0.36222232384328107

tgamma.c file is separated from mathmodule.c to test easy.
new tgamma.c

The result below is the result of tgamma.c, but they are the same in CPython distribution.
Test results:

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

The original test I found this mismatch:
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

Turning off fp-contract will fix aarch64 macos build to match x86 linux/windows build.

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions