mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-06-22 18:51:22 +02:00
Fixed imaginary number being ignored in eval_fn_call
This commit is contained in:
parent
68e0769942
commit
ead9dd9caf
@ -213,6 +213,7 @@ mod tests {
|
|||||||
KalkNum::new_with_imaginary(KalkNum::from(2f64).value, "", KalkNum::from(3f64).value),
|
KalkNum::new_with_imaginary(KalkNum::from(2f64).value, "", KalkNum::from(3f64).value),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
println!("{}", result.to_f64());
|
||||||
assert!(cmp(result.to_f64(), -4.5f64) || cmp(result.to_f64(), -4.499999f64));
|
assert!(cmp(result.to_f64(), -4.5f64) || cmp(result.to_f64(), -4.499999f64));
|
||||||
assert!(cmp(result.imaginary_to_f64(), 18f64));
|
assert!(cmp(result.imaginary_to_f64(), 18f64));
|
||||||
}
|
}
|
||||||
|
@ -384,12 +384,19 @@ pub(crate) fn eval_fn_call_expr(
|
|||||||
// Initialise the arguments as their own variables.
|
// Initialise the arguments as their own variables.
|
||||||
let mut new_argument_values = Vec::new();
|
let mut new_argument_values = Vec::new();
|
||||||
for (i, argument) in arguments.iter().enumerate() {
|
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(
|
let var_decl = Stmt::VarDecl(
|
||||||
Identifier::parameter_from_name(identifier_parts[1], identifier_parts[0]),
|
argument_identifier,
|
||||||
Box::new(Expr::Literal(
|
Box::new(crate::ast::build_literal_ast(&eval_expr(
|
||||||
eval_expr(context, &expressions[i], "")?.to_f64(),
|
context,
|
||||||
)),
|
&expressions[i],
|
||||||
|
"",
|
||||||
|
)?)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Don't set these values just yet, since
|
// Don't set these values just yet, since
|
||||||
|
Loading…
x
Reference in New Issue
Block a user