use crate::c32;
use crate::c64;
pub trait BitWidthConvertible {
type Width32;
type Width64;
fn to32(self) -> Self::Width32;
fn to64(self) -> Self::Width64;
fn from32(width32: Self::Width32) -> Self;
fn from64(width64: Self::Width64) -> Self;
}
impl BitWidthConvertible for f32 {
type Width32 = f32;
type Width64 = f64;
#[inline(always)]
fn to32(self) -> Self::Width32 {
self
}
#[inline(always)]
fn to64(self) -> Self::Width64 {
self as f64
}
#[inline(always)]
fn from32(width32: Self::Width32) -> Self {
width32
}
#[inline(always)]
fn from64(width64: Self::Width64) -> Self {
width64 as f32
}
}
impl BitWidthConvertible for f64 {
type Width32 = f32;
type Width64 = f64;
#[inline(always)]
fn to32(self) -> Self::Width32 {
self as f32
}
#[inline(always)]
fn to64(self) -> Self::Width64 {
self
}
#[inline(always)]
fn from32(width32: Self::Width32) -> Self {
width32 as f64
}
#[inline(always)]
fn from64(width64: Self::Width64) -> Self {
width64
}
}
impl BitWidthConvertible for c32 {
type Width32 = c32;
type Width64 = c64;
#[inline(always)]
fn to32(self) -> Self::Width32 {
self
}
#[inline(always)]
fn to64(self) -> Self::Width64 {
c64::new(self.re as f64, self.im as f64)
}
#[inline(always)]
fn from32(width32: Self::Width32) -> Self {
width32
}
#[inline(always)]
fn from64(width64: Self::Width64) -> Self {
c32::new(width64.re as f32, width64.im as f32)
}
}
impl BitWidthConvertible for c64 {
type Width32 = c32;
type Width64 = c64;
#[inline(always)]
fn to32(self) -> Self::Width32 {
c32::new(self.re as f32, self.im as f32)
}
#[inline(always)]
fn to64(self) -> Self::Width64 {
self
}
#[inline(always)]
fn from32(width32: Self::Width32) -> Self {
c64::new(width32.re as f64, width32.im as f64)
}
#[inline(always)]
fn from64(width64: Self::Width64) -> Self {
width64
}
}