replace some transmutes
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
use core::mem;
|
|
||||||
use core::ops;
|
use core::ops;
|
||||||
|
|
||||||
use super::int::Int;
|
use super::int::Int;
|
||||||
@@ -85,8 +84,6 @@ pub trait Float:
|
|||||||
fn is_subnormal(&self) -> bool;
|
fn is_subnormal(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Some of this can be removed if RFC Issue #1424 is resolved
|
|
||||||
// https://github.com/rust-lang/rfcs/issues/1424
|
|
||||||
macro_rules! float_impl {
|
macro_rules! float_impl {
|
||||||
($ty:ident, $ity:ident, $sity:ident, $bits:expr, $significand_bits:expr) => {
|
($ty:ident, $ity:ident, $sity:ident, $bits:expr, $significand_bits:expr) => {
|
||||||
impl Float for $ty {
|
impl Float for $ty {
|
||||||
@@ -104,10 +101,10 @@ macro_rules! float_impl {
|
|||||||
const EXPONENT_MASK: Self::Int = !(Self::SIGN_MASK | Self::SIGNIFICAND_MASK);
|
const EXPONENT_MASK: Self::Int = !(Self::SIGN_MASK | Self::SIGNIFICAND_MASK);
|
||||||
|
|
||||||
fn repr(self) -> Self::Int {
|
fn repr(self) -> Self::Int {
|
||||||
unsafe { mem::transmute(self) }
|
self.to_bits()
|
||||||
}
|
}
|
||||||
fn signed_repr(self) -> Self::SignedInt {
|
fn signed_repr(self) -> Self::SignedInt {
|
||||||
unsafe { mem::transmute(self) }
|
self.to_bits() as Self::SignedInt
|
||||||
}
|
}
|
||||||
fn eq_repr(self, rhs: Self) -> bool {
|
fn eq_repr(self, rhs: Self) -> bool {
|
||||||
if self.is_nan() && rhs.is_nan() {
|
if self.is_nan() && rhs.is_nan() {
|
||||||
@@ -117,7 +114,7 @@ macro_rules! float_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn from_repr(a: Self::Int) -> Self {
|
fn from_repr(a: Self::Int) -> Self {
|
||||||
unsafe { mem::transmute(a) }
|
Self::from_bits(a)
|
||||||
}
|
}
|
||||||
fn from_parts(sign: bool, exponent: Self::Int, significand: Self::Int) -> Self {
|
fn from_parts(sign: bool, exponent: Self::Int, significand: Self::Int) -> Self {
|
||||||
Self::from_repr(
|
Self::from_repr(
|
||||||
|
|||||||
@@ -633,7 +633,7 @@ fn main() {
|
|||||||
if a.0.is_nan()
|
if a.0.is_nan()
|
||||||
|| b.0.is_nan()
|
|| b.0.is_nan()
|
||||||
|| c.is_nan()
|
|| c.is_nan()
|
||||||
|| c.abs() <= unsafe { mem::transmute(4503599627370495u64) }
|
|| c.abs() <= f64::from_bits(4503599627370495u64)
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@@ -651,7 +651,7 @@ fn main() {
|
|||||||
if a.0.is_nan()
|
if a.0.is_nan()
|
||||||
|| b.0.is_nan()
|
|| b.0.is_nan()
|
||||||
|| c.is_nan()
|
|| c.is_nan()
|
||||||
|| c.abs() <= unsafe { mem::transmute(16777215u32) }
|
|| c.abs() <= f32::from_bits(16777215u32)
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@@ -671,7 +671,7 @@ fn main() {
|
|||||||
if a.0.is_nan()
|
if a.0.is_nan()
|
||||||
|| b.0.is_nan()
|
|| b.0.is_nan()
|
||||||
|| c.is_nan()
|
|| c.is_nan()
|
||||||
|| c.abs() <= unsafe { mem::transmute(4503599627370495u64) }
|
|| c.abs() <= f64::from_bits(4503599627370495u64)
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@@ -689,7 +689,7 @@ fn main() {
|
|||||||
if a.0.is_nan()
|
if a.0.is_nan()
|
||||||
|| b.0.is_nan()
|
|| b.0.is_nan()
|
||||||
|| c.is_nan()
|
|| c.is_nan()
|
||||||
|| c.abs() <= unsafe { mem::transmute(16777215u32) }
|
|| c.abs() <= f32::from_bits(16777215u32)
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user