Skip to content

Commit

Permalink
handle signed zero in li(n)
Browse files Browse the repository at this point in the history
  • Loading branch information
Expander committed Mar 6, 2024
1 parent e27eb5c commit 51618d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/li/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn cli(n: i32, z: Complex<f64>) -> Complex<f64> {
Complex::new(f64::NEG_INFINITY, 0.0)
} else if z.im == 0.0 {
if z.re <= 1.0 || n <= 0 {
Complex::new(z.re.li(n), 0.0)
Complex::new(z.re.li(n), z.im)
} else { // rz > 1.0 && n > 0
let l = z.re.ln();
Complex::new(z.re.li(n), -std::f64::consts::PI*inv_fac(n - 1)*l.powi(n - 1))
Expand Down
2 changes: 1 addition & 1 deletion src/li/rli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn rli(n: i32, x: f64) -> f64 {
let odd_sgn = |n| if is_even(n) { -1.0 } else { 1.0 };

if x == 0.0 {
0.0
x
} else if x == 1.0 {
zeta(n)
} else if x == -1.0 {
Expand Down
21 changes: 21 additions & 0 deletions tests/li.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,24 @@ fn test_values() {
assert!(Complex::new(f64::NAN, f64::NAN).li(7).is_nan());
assert!(Complex::new(f64::INFINITY, f64::INFINITY).li(7).is_infinite());
}


#[test]
fn test_signed_zero() {
let pz64 = 0.0_f64;
let nz64 = -0.0_f64;

for n in (-100..100).into_iter() {
assert!(pz64.li(n).is_sign_positive());
assert!(nz64.li(n).is_sign_negative());

assert!(Complex::new(pz64, pz64).li(n).re.is_sign_positive());
assert!(Complex::new(pz64, pz64).li(n).im.is_sign_positive());
assert!(Complex::new(pz64, nz64).li(n).re.is_sign_positive());
assert!(Complex::new(pz64, nz64).li(n).im.is_sign_negative());
assert!(Complex::new(nz64, pz64).li(n).re.is_sign_negative());
assert!(Complex::new(nz64, pz64).li(n).im.is_sign_positive());
assert!(Complex::new(nz64, nz64).li(n).re.is_sign_negative());
assert!(Complex::new(nz64, nz64).li(n).im.is_sign_negative());
}
}

0 comments on commit 51618d1

Please sign in to comment.