From 865d7a7886bbddebfada7fabbf5cf450d5b6dfe4 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 17 Sep 2024 14:47:18 -0700 Subject: [PATCH] float tests --- fixed_wide/src/tests.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/fixed_wide/src/tests.rs b/fixed_wide/src/tests.rs index f7278ce..35795be 100644 --- a/fixed_wide/src/tests.rs +++ b/fixed_wide/src/tests.rs @@ -4,13 +4,43 @@ use crate::types::I256F256; #[test] fn you_can_add_numbers(){ let a=I256F256::from((3i128*2).pow(4)); - assert_eq!(a+a,I256F256::from((3i128*2).pow(4)*2)) + assert_eq!(a+a,I256F256::from((3i128*2).pow(4)*2)); +} + +#[test] +fn to_f32(){ + let a=I256F256::from(1)>>2; + let f:f32=a.into(); + assert_eq!(f,0.25f32); + let f:f32=(-a).into(); + assert_eq!(f,-0.25f32); + let a=I256F256::from(0); + let f:f32=(-a).into(); + assert_eq!(f,0f32); + let a=I256F256::from(237946589723468975i64)<<32; + let f:f32=a.into(); + assert_eq!(f,237946589723468975f32*2.0f32.powi(32)); +} + +#[test] +fn to_f64(){ + let a=I256F256::from(1)>>2; + let f:f64=a.into(); + assert_eq!(f,0.25f64); + let f:f64=(-a).into(); + assert_eq!(f,-0.25f64); + let a=I256F256::from(0); + let f:f64=(-a).into(); + assert_eq!(f,0f64); + let a=I256F256::from(237946589723468975i64)<<32; + let f:f64=a.into(); + assert_eq!(f,237946589723468975f64*2.0f64.powi(32)); } #[test] fn you_can_shr_numbers(){ let a=I32F32::from(4); - assert_eq!(a>>1,I32F32::from(2)) + assert_eq!(a>>1,I32F32::from(2)); } #[test]