Fixed imaginary number being ignored in eval_fn_call

This commit is contained in:
bakk 2021-05-31 23:32:08 +02:00
parent 4da372aefe
commit 96a81b1359
2 changed files with 13 additions and 5 deletions

View File

@ -213,6 +213,7 @@ mod tests {
KalkNum::new_with_imaginary(KalkNum::from(2f64).value, "", KalkNum::from(3f64).value),
)
.unwrap();
println!("{}", result.to_f64());
assert!(cmp(result.to_f64(), -4.5f64) || cmp(result.to_f64(), -4.499999f64));
assert!(cmp(result.imaginary_to_f64(), 18f64));
}

View File

@ -384,12 +384,19 @@ pub(crate) fn eval_fn_call_expr(
// Initialise the arguments as their own variables.
let mut new_argument_values = Vec::new();
for (i, argument) in arguments.iter().enumerate() {
let identifier_parts: Vec<&str> = argument.split('-').collect();
let argument_identifier = if argument.contains("-") {
let identifier_parts: Vec<&str> = argument.split('-').collect();
Identifier::parameter_from_name(identifier_parts[1], identifier_parts[0])
} else {
Identifier::from_full_name(argument)
};
let var_decl = Stmt::VarDecl(
Identifier::parameter_from_name(identifier_parts[1], identifier_parts[0]),
Box::new(Expr::Literal(
eval_expr(context, &expressions[i], "")?.to_f64(),
)),
argument_identifier,
Box::new(crate::ast::build_literal_ast(&eval_expr(
context,
&expressions[i],
"",
)?)),
);
// Don't set these values just yet, since