switch to using `half` for f16 implementation
authorJacob Lifshay <programmerjake@gmail.com>
Sun, 2 May 2021 23:48:09 +0000 (16:48 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Sun, 2 May 2021 23:48:09 +0000 (16:48 -0700)
Cargo.toml
src/lib.rs
src/traits.rs

index 833a28966c960bc7ce9a07cb42b7adf414d8c2a3..02c3dcd85f54fd19301f1a3af660f249b39c3f3b 100644 (file)
@@ -6,3 +6,8 @@ edition = "2018"
 license = "MIT OR Apache-2.0"
 
 [dependencies]
 license = "MIT OR Apache-2.0"
 
 [dependencies]
+half = { version = "1.7.1", optional = true }
+
+[features]
+default = ["f16"]
+f16 = ["half"]
index 088d074ea417f0c9340291e786924fe69622497d..2f64c51b340ce1152fd70dc73cfe039da5543d22 100644 (file)
@@ -2,6 +2,10 @@
 
 pub mod traits;
 
 
 pub mod traits;
 
-#[derive(Clone, Copy, Debug, Default, Hash)]
-#[repr(transparent)]
-pub struct F16(pub u16);
+#[cfg(feature = "f16")]
+pub use half::f16;
+
+#[cfg(not(feature = "f16"))]
+#[allow(non_camel_case_types)]
+#[derive(Clone, Copy, PartialEq, PartialOrd, Debug, Hash)]
+pub enum f16 {}
index b8eb99da065bd19f75a22fa548d50bcb07ea9fd7..c1d8095f2ca78bcde9e13ee19132afd676b25448 100644 (file)
@@ -3,7 +3,7 @@ use core::ops::{
     Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
 };
 
     Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
 };
 
-use crate::F16;
+use crate::f16;
 
 #[rustfmt::skip] // work around for https://github.com/rust-lang/rustfmt/issues/4823
 macro_rules! make_float_type {
 
 #[rustfmt::skip] // work around for https://github.com/rust-lang/rustfmt/issues/4823
 macro_rules! make_float_type {
@@ -286,7 +286,7 @@ macro_rules! make_types {
                     $U16;
                     #[int(prim = i16 $(, scalar = $ScalarI16)?)]
                     $I16;
                     $U16;
                     #[int(prim = i16 $(, scalar = $ScalarI16)?)]
                     $I16;
-                    #[float(prim = F16 $(, scalar = $ScalarF16)?)]
+                    #[float(prim = f16 $(, scalar = $ScalarF16)?)]
                     $F16;
                 },
                 {
                     $F16;
                 },
                 {