From 4def8318f78a50a4ce8f6dbef44e79efd7607eeb Mon Sep 17 00:00:00 2001 From: Minseong Jang Date: Mon, 28 Mar 2022 15:27:35 +0900 Subject: [PATCH] Fix ir interpreter --- src/ir/interp.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ir/interp.rs b/src/ir/interp.rs index ae9c4a6..03fdbe0 100644 --- a/src/ir/interp.rs +++ b/src/ir/interp.rs @@ -770,10 +770,17 @@ mod calculator { }, Dtype::Float { width, .. }, ) => { - let casted_value = if is_signed { - value as i128 as f64 - } else { - value as f64 + let size = (width - 1) / Dtype::BITS_OF_BYTE + 1; + let casted_value = match (is_signed, size) { + (true, Dtype::SIZE_OF_FLOAT) => value as i128 as f32 as f64, + (true, Dtype::SIZE_OF_DOUBLE) => value as i128 as f64, + (false, Dtype::SIZE_OF_FLOAT) => value as f32 as f64, + (false, Dtype::SIZE_OF_DOUBLE) => value as f64, + _ => panic!( + "calculate_typecast: not supported case \ + typecast int to float when `width` is {}", + width + ), }; Ok(Value::float(casted_value, width)) }