From 2d2f4a2a0d1231615f4e46700666c91972cb8764 Mon Sep 17 00:00:00 2001 From: Chen-Pang He Date: Thu, 16 May 2024 15:27:42 +0800 Subject: [PATCH] Implement ToPrimitive for F8 --- src/lib.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 66d1506..e73db83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ use core::marker::ConstParamTy; use core::mem; use core::num::FpCategory; use core::ops::Neg; -use num_traits::AsPrimitive; +use num_traits::{AsPrimitive, ToPrimitive}; /// NaN encoding style /// @@ -1216,3 +1216,32 @@ where f64::from(self).as_() } } + +impl ToPrimitive for F8 +where + f64: From, +{ + fn to_i64(&self) -> Option { + f64::from(*self).to_i64() + } + + fn to_u64(&self) -> Option { + f64::from(*self).to_u64() + } + + fn to_i128(&self) -> Option { + f64::from(*self).to_i128() + } + + fn to_u128(&self) -> Option { + f64::from(*self).to_u128() + } + + fn to_f32(&self) -> Option { + f64::from(*self).to_f32() + } + + fn to_f64(&self) -> Option { + Some(f64::from(*self)) + } +}