File tree 3 files changed +23
-7
lines changed
3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 19
19
os : [
20
20
ubuntu-latest,
21
21
windows-latest,
22
- # macos-latest # disabled due to incompatibility. See issue #1
22
+ macos-latest,
23
23
]
24
24
rust : [stable]
25
25
steps :
38
38
- name : Build
39
39
run : cargo build --verbose
40
40
- name : Run tests
41
- run : cargo test --verbose
42
- - name : Run tests on Release
43
- run : cargo test --release --verbose
41
+ if : matrix.os != 'macos-latest'
42
+ run : cargo test --verbose && cargo test --release --verbose
43
+ - name : Run tests with FMA (macOS)
44
+ if : matrix.os == 'macos-latest'
45
+ run : cargo test --verbose --features mul_add && cargo test --release --verbose --features mul_add
Original file line number Diff line number Diff line change @@ -3,6 +3,11 @@ name = "pymath"
3
3
version = " 0.1.0"
4
4
edition = " 2024"
5
5
6
+ [features ]
7
+ # Turning on this feature on aarch64-apple-darwin helps bit representation compatibility
8
+ # See also: https://github.com/python/cpython/issues/132763
9
+ mul_add = []
10
+
6
11
[dev-dependencies ]
7
12
proptest = " 1.6.0"
8
13
pyo3 = { version = " 0.24" , features = [" abi3" ] }
Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ const LANCZOS_DEN_COEFFS: [f64; LANCZOS_N] = [
37
37
1.0 ,
38
38
] ;
39
39
40
+ fn mul_add ( a : f64 , b : f64 , c : f64 ) -> f64 {
41
+ if cfg ! ( feature = "mul_add" ) {
42
+ a. mul_add ( b, c)
43
+ } else {
44
+ a * b + c
45
+ }
46
+ }
47
+
40
48
fn lanczos_sum ( x : f64 ) -> f64 {
41
49
let mut num = 0.0 ;
42
50
let mut den = 0.0 ;
@@ -50,8 +58,8 @@ fn lanczos_sum(x: f64) -> f64 {
50
58
// this resulted in lower accuracy.
51
59
if x < 5.0 {
52
60
for i in ( 0 ..LANCZOS_N ) . rev ( ) {
53
- num = num * x + LANCZOS_NUM_COEFFS [ i] ;
54
- den = den * x + LANCZOS_DEN_COEFFS [ i] ;
61
+ num = mul_add ( num, x , LANCZOS_NUM_COEFFS [ i] ) ;
62
+ den = mul_add ( den, x , LANCZOS_DEN_COEFFS [ i] ) ;
55
63
}
56
64
} else {
57
65
for i in 0 ..LANCZOS_N {
@@ -237,7 +245,8 @@ pub fn lgamma(x: f64) -> Result<f64, Error> {
237
245
// absorbed the exp(-lanczos_g) term, and throwing out the lanczos_g
238
246
// subtraction below; it's probably not worth it.
239
247
let mut r = lanczos_sum ( absx) . ln ( ) - LANCZOS_G ;
240
- r += ( absx - 0.5 ) * ( ( absx + LANCZOS_G - 0.5 ) . ln ( ) - 1.0 ) ;
248
+ let t = absx - 0.5 ;
249
+ r = mul_add ( t, ( absx + LANCZOS_G - 0.5 ) . ln ( ) - 1.0 , r) ;
241
250
242
251
if x < 0.0 {
243
252
// Use reflection formula to get value for negative x
You can’t perform that action at this time.
0 commit comments