pub struct CssUnsignedNumber(/* private fields */);
Expand description
A CSS float value similar to f32 but with a more restricted range
Methods from Deref<Target = f32>§
pub const RADIX: u32 = 2u32
pub const MANTISSA_DIGITS: u32 = 24u32
pub const DIGITS: u32 = 6u32
pub const EPSILON: f32 = 1.1920929E-7f32
pub const MIN: f32 = -3.40282347E+38f32
pub const MIN_POSITIVE: f32 = 1.17549435E-38f32
pub const MAX: f32 = 3.40282347E+38f32
pub const MIN_EXP: i32 = -125i32
pub const MAX_EXP: i32 = 128i32
pub const MIN_10_EXP: i32 = -37i32
pub const MAX_10_EXP: i32 = 38i32
pub const NAN: f32 = NaN_f32
pub const INFINITY: f32 = +Inf_f32
pub const NEG_INFINITY: f32 = -Inf_f32
1.62.0 · Sourcepub fn total_cmp(&self, other: &f32) -> Ordering
pub fn total_cmp(&self, other: &f32) -> Ordering
Returns the ordering between self
and other
.
Unlike the standard partial comparison between floating point numbers,
this comparison always produces an ordering in accordance to
the totalOrder
predicate as defined in the IEEE 754 (2008 revision)
floating point standard. The values are ordered in the following sequence:
- negative quiet NaN
- negative signaling NaN
- negative infinity
- negative numbers
- negative subnormal numbers
- negative zero
- positive zero
- positive subnormal numbers
- positive numbers
- positive infinity
- positive signaling NaN
- positive quiet NaN.
The ordering established by this function does not always agree with the
PartialOrd
and PartialEq
implementations of f32
. For example,
they consider negative and positive zero equal, while total_cmp
doesn’t.
The interpretation of the signaling NaN bit follows the definition in the IEEE 754 standard, which may not match the interpretation by some of the older, non-conformant (e.g. MIPS) hardware implementations.
§Example
struct GoodBoy {
name: String,
weight: f32,
}
let mut bois = vec![
GoodBoy { name: "Pucci".to_owned(), weight: 0.1 },
GoodBoy { name: "Woofer".to_owned(), weight: 99.0 },
GoodBoy { name: "Yapper".to_owned(), weight: 10.0 },
GoodBoy { name: "Chonk".to_owned(), weight: f32::INFINITY },
GoodBoy { name: "Abs. Unit".to_owned(), weight: f32::NAN },
GoodBoy { name: "Floaty".to_owned(), weight: -5.0 },
];
bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
// `f32::NAN` could be positive or negative, which will affect the sort order.
if f32::NAN.is_sign_negative() {
assert!(bois.into_iter().map(|b| b.weight)
.zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
.all(|(a, b)| a.to_bits() == b.to_bits()))
} else {
assert!(bois.into_iter().map(|b| b.weight)
.zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
.all(|(a, b)| a.to_bits() == b.to_bits()))
}
Trait Implementations§
Source§impl Add for CssUnsignedNumber
impl Add for CssUnsignedNumber
Source§type Output = CssUnsignedNumber
type Output = CssUnsignedNumber
+
operator.Source§impl AddAssign for CssUnsignedNumber
impl AddAssign for CssUnsignedNumber
Source§fn add_assign(&mut self, rhs: CssUnsignedNumber)
fn add_assign(&mut self, rhs: CssUnsignedNumber)
+=
operation. Read moreSource§impl AppUnitsPer for CssUnsignedNumber
impl AppUnitsPer for CssUnsignedNumber
Source§const AppUnitsPerPX: Self
const AppUnitsPerPX: Self
Number of app units per pixel
Source§const AppUnitsPerIN: Self
const AppUnitsPerIN: Self
Number of app units per inch
Source§const AppUnitsPerCM: Self
const AppUnitsPerCM: Self
Number of app units per centimeter
Source§const AppUnitsPerMM: Self
const AppUnitsPerMM: Self
Number of app units per millimeter
Source§const AppUnitsPerQ: Self
const AppUnitsPerQ: Self
Number of app units per quarter
Source§const AppUnitsPerPT: Self
const AppUnitsPerPT: Self
Number of app units per point
Source§const AppUnitsPerPC: Self
const AppUnitsPerPC: Self
Number of app units per pica
Source§impl Clone for CssUnsignedNumber
impl Clone for CssUnsignedNumber
Source§fn clone(&self) -> CssUnsignedNumber
fn clone(&self) -> CssUnsignedNumber
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl CssNumber for CssUnsignedNumber
impl CssNumber for CssUnsignedNumber
const Zero: Self
const One: Self
const Maximum: Self
const Minimum: Self
const DotsPerInch: Self
const CentimetresPerInch: Self
fn as_f32(&self) -> f32
fn as_u32(&self) -> u32
fn abs(self) -> Self
fn parseNumber<'i>( value: f32, _int_value: Option<i32>, ) -> Result<Self, ParseError<'i, CustomParseError<'i>>>
fn new(value: f32) -> Result<Self, CssNumberConversionError>
fn round(self) -> Self
fn clamp(value: f32) -> Self
fn can_be_negative() -> bool
Source§impl CssNumberNewType<CssUnsignedNumber> for CssUnsignedNumber
impl CssNumberNewType<CssUnsignedNumber> for CssUnsignedNumber
fn to_f32(&self) -> f32
fn as_CssNumber(&self) -> &CssUnsignedNumber
fn to_CssNumber(&self) -> Number
fn is_zero(&self) -> bool
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
fn is_zero_or_positive(&self) -> bool
fn is_zero_or_negative(&self) -> bool
Source§impl Debug for CssUnsignedNumber
impl Debug for CssUnsignedNumber
Source§impl Default for CssUnsignedNumber
impl Default for CssUnsignedNumber
Source§impl Deref for CssUnsignedNumber
impl Deref for CssUnsignedNumber
Source§impl Display for CssUnsignedNumber
impl Display for CssUnsignedNumber
Source§impl Div for CssUnsignedNumber
impl Div for CssUnsignedNumber
Source§type Output = CssUnsignedNumber
type Output = CssUnsignedNumber
/
operator.Source§impl DivAssign for CssUnsignedNumber
impl DivAssign for CssUnsignedNumber
Source§fn div_assign(&mut self, rhs: CssUnsignedNumber)
fn div_assign(&mut self, rhs: CssUnsignedNumber)
/=
operation. Read moreSource§impl From<i16> for CssUnsignedNumber
impl From<i16> for CssUnsignedNumber
Source§fn from(small: i16) -> CssUnsignedNumber
fn from(small: i16) -> CssUnsignedNumber
Source§impl From<i8> for CssUnsignedNumber
impl From<i8> for CssUnsignedNumber
Source§fn from(small: i8) -> CssUnsignedNumber
fn from(small: i8) -> CssUnsignedNumber
Source§impl From<u16> for CssUnsignedNumber
impl From<u16> for CssUnsignedNumber
Source§fn from(small: u16) -> CssUnsignedNumber
fn from(small: u16) -> CssUnsignedNumber
Source§impl From<u8> for CssUnsignedNumber
impl From<u8> for CssUnsignedNumber
Source§fn from(small: u8) -> CssUnsignedNumber
fn from(small: u8) -> CssUnsignedNumber
Source§impl FromStr for CssUnsignedNumber
impl FromStr for CssUnsignedNumber
Source§impl Hash for CssUnsignedNumber
impl Hash for CssUnsignedNumber
Source§impl LowerExp for CssUnsignedNumber
impl LowerExp for CssUnsignedNumber
Source§impl Mul for CssUnsignedNumber
impl Mul for CssUnsignedNumber
Source§type Output = CssUnsignedNumber
type Output = CssUnsignedNumber
*
operator.Source§impl MulAssign for CssUnsignedNumber
impl MulAssign for CssUnsignedNumber
Source§fn mul_assign(&mut self, rhs: CssUnsignedNumber)
fn mul_assign(&mut self, rhs: CssUnsignedNumber)
*=
operation. Read moreSource§impl Neg for CssUnsignedNumber
impl Neg for CssUnsignedNumber
Source§impl Ord for CssUnsignedNumber
impl Ord for CssUnsignedNumber
Source§impl PartialEq for CssUnsignedNumber
impl PartialEq for CssUnsignedNumber
Source§impl PartialOrd for CssUnsignedNumber
impl PartialOrd for CssUnsignedNumber
Source§impl Rem for CssUnsignedNumber
impl Rem for CssUnsignedNumber
Source§type Output = CssUnsignedNumber
type Output = CssUnsignedNumber
%
operator.Source§impl RemAssign for CssUnsignedNumber
impl RemAssign for CssUnsignedNumber
Source§fn rem_assign(&mut self, rhs: CssUnsignedNumber)
fn rem_assign(&mut self, rhs: CssUnsignedNumber)
%=
operation. Read moreSource§impl Sub for CssUnsignedNumber
impl Sub for CssUnsignedNumber
Source§type Output = CssUnsignedNumber
type Output = CssUnsignedNumber
-
operator.Source§impl SubAssign for CssUnsignedNumber
impl SubAssign for CssUnsignedNumber
Source§fn sub_assign(&mut self, rhs: CssUnsignedNumber)
fn sub_assign(&mut self, rhs: CssUnsignedNumber)
-=
operation. Read more