Formatted code files

This commit is contained in:
Amuthan Mannar
2023-10-07 12:34:32 +05:30
parent 54d5869457
commit c2f159b24a
2 changed files with 20 additions and 14 deletions

View File

@@ -449,27 +449,33 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
}
// Floats and Integers
(_, JitValue::Int(a), JitValue::Float(b)) |
(_, JitValue::Float(a), JitValue::Int(b)) =>{
(_, JitValue::Int(a), JitValue::Float(b))
| (_, JitValue::Float(a), JitValue::Int(b)) => {
let operand_one = match a_type.unwrap() {
JitType::Int => self.builder.ins().fcvt_from_sint(types::F64, a),
_=> a
_ => a,
};
let operand_two = match b_type.unwrap() {
JitType::Int => self.builder.ins().fcvt_from_sint(types::F64, b),
_=> b
_ => b,
};
match op{
BinaryOperator::Add => JitValue::Float(self.builder.ins().fadd(operand_one, operand_two)),
BinaryOperator::Subtract => JitValue::Float(self.builder.ins().fsub(operand_one, operand_two)),
BinaryOperator::Multiply => JitValue::Float(self.builder.ins().fmul(operand_one, operand_two)),
BinaryOperator::Divide => JitValue::Float(self.builder.ins().fdiv(operand_one, operand_two)),
_ => return Err(JitCompileError::NotSupported)
match op {
BinaryOperator::Add => {
JitValue::Float(self.builder.ins().fadd(operand_one, operand_two))
}
BinaryOperator::Subtract => {
JitValue::Float(self.builder.ins().fsub(operand_one, operand_two))
}
BinaryOperator::Multiply => {
JitValue::Float(self.builder.ins().fmul(operand_one, operand_two))
}
BinaryOperator::Divide => {
JitValue::Float(self.builder.ins().fdiv(operand_one, operand_two))
}
_ => return Err(JitCompileError::NotSupported),
}
}
_ => return Err(JitCompileError::NotSupported),
};

View File

@@ -105,9 +105,9 @@ fn test_mul_with_integer() {
assert_approx_eq!(mul(5.2, 2), Ok(10.4));
assert_approx_eq!(mul(3.4, -1), Ok(-3.4));
assert_bits_eq!(mul(1.0, 0), Ok(0.0f64));
assert_bits_eq!(mul(-0.0,1), Ok(-0.0f64));
assert_bits_eq!(mul(-0.0, 1), Ok(-0.0f64));
assert_bits_eq!(mul(0.0, -1), Ok(-0.0f64));
assert_bits_eq!(mul(-0.0,-1), Ok(0.0f64));
assert_bits_eq!(mul(-0.0, -1), Ok(0.0f64));
}
#[test]