diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-01-17 23:28:48 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-01-17 23:28:48 +0100 |
| commit | 9cc61497ed8a2336f33407d3262181e4ac3b46cb (patch) | |
| tree | aac75b57b0fffea64abcd23cbac4d27c875fee48 /src/complex.rs | |
| parent | 77cf9aa7535a1d9481f0bd3caeea26e2b85c5019 (diff) | |
add commonsense and expression_functions
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()?; } |