Fixed evaluation of exponents

This commit is contained in:
Kasper 2019-12-28 01:59:29 +01:00
parent a0b7a7cdf5
commit 1e541b8313

View File

@ -293,10 +293,10 @@ fn evaluate_node(ast_node: &AstNode) -> Result<Answer, String> {
Caret => { Caret => {
if left.unit == Unit::NoUnit && right.unit == Unit::NoUnit { if left.unit == Unit::NoUnit && right.unit == Unit::NoUnit {
// 3 ^ 2 // 3 ^ 2
return Ok(Answer::new(left.value ^ right.value, left.unit)) return Ok(Answer::new(left.value.pow(right.value), left.unit))
} else if right.unit == Unit::NoUnit && left.unit != Unit::NoUnit { } else if right.unit == Unit::NoUnit && left.unit != Unit::NoUnit {
// 1 km ^ 3 // 1 km ^ 3
return Ok(Answer::new(left.value ^ right.value, left.unit)) return Ok(Answer::new(left.value.pow(right.value), left.unit))
} else { } else {
return Err(format!("Cannot multiply {:?} and {:?}", left.unit, right.unit)) return Err(format!("Cannot multiply {:?} and {:?}", left.unit, right.unit))
} }