diff --git a/src/li/cli.rs b/src/li/cli.rs index d52877f..24cf83e 100644 --- a/src/li/cli.rs +++ b/src/li/cli.rs @@ -14,7 +14,7 @@ pub fn cli(n: i32, z: Complex) -> Complex { 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)) diff --git a/src/li/rli.rs b/src/li/rli.rs index b020cb1..aabfb75 100644 --- a/src/li/rli.rs +++ b/src/li/rli.rs @@ -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 { diff --git a/tests/li.rs b/tests/li.rs index 16c4d35..1445652 100644 --- a/tests/li.rs +++ b/tests/li.rs @@ -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()); + } +}