add test_ilogb_f16
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 7 May 2021 02:40:31 +0000 (19:40 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 7 May 2021 02:40:31 +0000 (19:40 -0700)
src/algorithms/ilogb.rs

index 2956c8f5027f15b6a7454d28a3b25cfdd45539d8..86b5a1013837ae5573403269b13cc2bb4ac848bf 100644 (file)
@@ -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);