// Copyright 2014-2018 Optimal Computing (NZ) Ltd. // Licensed under the MIT license. See LICENSE for details.
#[cfg(feature="num_traits")] use num_traits::NumCast;
/// A trait for floating point numbers which computes the number of representable /// values or ULPs (Units of Least Precision) that separate the two given values. #[cfg(feature="num_traits")] pubtrait Ulps { type U: Copy + NumCast;
/// The number of representable values or ULPs (Units of Least Precision) that /// separate `self` and `other`. The result `U` is an integral value, and will /// be zero if `self` and `other` are exactly equal. fn ulps(&self, other: &Self) -> <Selfas Ulps>::U;
/// The next representable number above this one fn next(&self) -> Self;
/// The previous representable number below this one fn prev(&self) -> Self;
}
#[cfg(not(feature="num_traits"))] pubtrait Ulps { type U: Copy;
/// The number of representable values or ULPs (Units of Least Precision) that /// separate `self` and `other`. The result `U` is an integral value, and will /// be zero if `self` and `other` are exactly equal. fn ulps(&self, other: &Self) -> <Selfas Ulps>::U;
/// The next representable number above this one fn next(&self) -> Self;
/// The previous representable number below this one fn prev(&self) -> Self;
}
impl Ulps for f32 { type U = i32;
fn ulps(&self, other: &f32) -> i32 {
// IEEE754 defined floating point storage representation to // maintain their order when their bit patterns are interpreted as // integers. This is a huge boon to the task at hand, as we can // reinterpret them as integers to find out how many ULPs apart any // two floats are
// Setup integer representations of the input let ai32: i32 = self.to_bits() as i32; let bi32: i32 = other.to_bits() as i32;
// IEEE754 defined floating point storage representation to // maintain their order when their bit patterns are interpreted as // integers. This is a huge boon to the task at hand, as we can // reinterpret them as integers to find out how many ULPs apart any // two floats are
// Setup integer representations of the input let ai64: i64 = self.to_bits() as i64; let bi64: i64 = other.to_bits() as i64;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.