diff options
Diffstat (limited to 'src/complex.rs')
| -rw-r--r-- | src/complex.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/complex.rs b/src/complex.rs index 642122f..e498234 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -2,7 +2,7 @@ use std::num::ParseFloatError; use std::str::FromStr; use std::f64::consts::E; -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Default, Debug)] pub struct Complex { pub real: f64, pub imag: f64, @@ -103,7 +103,11 @@ impl FromStr for Complex { } } else { if s.contains('i') { - c.imag = s[..s.len() - 1].parse()?; + if s.len() == 1 { + c.imag = 1.0; + } else { + c.imag = s[..s.len() - 1].parse()?; + } } else { c.real = s.parse()?; } |