Skip to content

Commit eb8de33

Browse files
committed
Fix ComplexFloat::arg for regular floats
1 parent 29b7b7d commit eb8de33

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/complex_float.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ where
185185
}
186186

187187
fn arg(self) -> Self::Real {
188-
if self > T::zero() {
189-
T::zero()
190-
} else if self < T::zero() {
188+
if self.is_nan() {
189+
self
190+
} else if self.is_sign_negative() {
191191
T::PI()
192192
} else {
193-
T::nan()
193+
T::zero()
194194
}
195195
}
196196

@@ -430,6 +430,9 @@ mod test {
430430
));
431431

432432
assert!(closef(ComplexFloat::arg(-1.), core::f64::consts::PI));
433+
assert!(closef(ComplexFloat::arg(-0.), core::f64::consts::PI));
434+
assert!(closef(ComplexFloat::arg(0.), 0.));
433435
assert!(closef(ComplexFloat::arg(1.), 0.));
436+
assert!(ComplexFloat::arg(f64::NAN).is_nan());
434437
}
435438
}

0 commit comments

Comments
 (0)