Fixed eg. 'x(2x + 1)' not working inside functions

This commit is contained in:
bakk 2021-05-27 23:15:53 +02:00
parent 475556788f
commit 1b01e9f41e
2 changed files with 3 additions and 2 deletions

View File

@ -201,7 +201,7 @@ impl KalkNum {
let result_str = if (-6..8).contains(&sci_notation_real.exponent) || self.value == 0f64 {
self.to_string_real()
} else if sci_notation_real.exponent <= -14 {
adjusted_num.value = KalkNum::from(1f64).value;
adjusted_num.value = KalkNum::from(0f64).value;
String::from("0")
} else {
sci_notation_real.to_string().trim().to_string()
@ -790,6 +790,7 @@ mod tests {
(10e-17, 1.0, "i"),
(1.0, 10e-17, "1"),
(10e-15, 0.0, "0"),
(3.00000000004, 0.0, "3"),
];
for (real, imaginary, output) in in_out {
let result = KalkNum::new_with_imaginary(

View File

@ -546,7 +546,7 @@ fn parse_identifier(context: &mut Context) -> Result<Expr, CalcError> {
// Eg. x
if parse_as_var_instead || context.symbol_table.contains_var(&identifier.pure_name) {
Ok(Expr::Var(identifier))
Ok(build_var(context, &identifier.full_name))
} else if context.parsing_unit_decl {
context.unit_decl_base_unit = Some(identifier.full_name);
Ok(Expr::Var(Identifier::from_full_name(DECL_UNIT)))