From 04c0f8eec752d1afe09c0b7e0b72f027ce4ee4d0 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 6 May 2021 19:40:31 -0700 Subject: [PATCH] add test_ilogb_f16 --- src/algorithms/ilogb.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/algorithms/ilogb.rs b/src/algorithms/ilogb.rs index 2956c8f..86b5a10 100644 --- a/src/algorithms/ilogb.rs +++ b/src/algorithms/ilogb.rs @@ -94,6 +94,27 @@ mod tests { use super::*; use crate::scalar::Scalar; + #[test] + #[cfg_attr( + not(feature = "f16"), + should_panic(expected = "f16 feature is not enabled") + )] + fn test_ilogb_f16() { + fn ilogb(arg: f32) -> i16 { + let arg: F16 = arg.to(); + ilogb_f16(Scalar, arg) + } + assert_eq!(ilogb(0.), ILOGB_UNDERFLOW_RESULT_F16); + assert_eq!(ilogb(1.), 0); + assert_eq!(ilogb(2.), 1); + assert_eq!(ilogb(3.), 1); + assert_eq!(ilogb(3.998), 1); + assert_eq!(ilogb(0.5), -1); + assert_eq!(ilogb(0.5f32.powi(20)), -20); + assert_eq!(ilogb(f32::INFINITY), ILOGB_OVERFLOW_RESULT_F16); + assert_eq!(ilogb(f32::NAN), ILOGB_NAN_RESULT_F16); + } + #[test] fn test_ilogb_f32() { assert_eq!(ilogb_f32(Scalar, 0f32), ILOGB_UNDERFLOW_RESULT_F32); -- 2.30.2