From 9cc61497ed8a2336f33407d3262181e4ac3b46cb Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 17 Jan 2024 23:28:48 +0100 Subject: add commonsense and expression_functions --- src/complex.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/complex.rs') 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()?; } -- cgit v1.2.3-70-g09d2