From: Jacob Lifshay Date: Sun, 2 May 2021 23:48:09 +0000 (-0700) Subject: switch to using `half` for f16 implementation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bb3868c63a5e0fb3b7383bac22253f3387ab5dbb;p=vector-math.git switch to using `half` for f16 implementation --- diff --git a/Cargo.toml b/Cargo.toml index 833a289..02c3dcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,8 @@ edition = "2018" license = "MIT OR Apache-2.0" [dependencies] +half = { version = "1.7.1", optional = true } + +[features] +default = ["f16"] +f16 = ["half"] diff --git a/src/lib.rs b/src/lib.rs index 088d074..2f64c51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,10 @@ 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 {} diff --git a/src/traits.rs b/src/traits.rs index b8eb99d..c1d8095 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -3,7 +3,7 @@ use core::ops::{ 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 { @@ -286,7 +286,7 @@ macro_rules! make_types { $U16; #[int(prim = i16 $(, scalar = $ScalarI16)?)] $I16; - #[float(prim = F16 $(, scalar = $ScalarF16)?)] + #[float(prim = f16 $(, scalar = $ScalarF16)?)] $F16; }, {