Struct sscanf::FullF32 [−][src]
A Wrapper around f32 whose RegexRepresentation also includes special floating point values
like nan
, inf
, 2.0e5
, …
This is not part of the regular f32 parser because having a Number match against Text like with
nan
is usually not desirable:
let input = "Match a Banana against a number"; let output = scanf!(input, "{}{}{}", String, f32, String); // There are no Numbers in input, so expect None assert!(output.is_none()); let output = scanf!(input, "{}{}{}", String, FullF32, String); // The 'nan' part in "Banana" is parsed as f32::NaN assert!(output.is_some()); assert!(output.unwrap().1.is_nan());
See FromStr on f32 for the full syntax
Methods from Deref<Target = f32>
pub const RADIX: u32
1.43.0[src]
pub const MANTISSA_DIGITS: u32
1.43.0[src]
pub const DIGITS: u32
1.43.0[src]
pub const EPSILON: f32
1.43.0[src]
pub const MIN: f32
1.43.0[src]
pub const MIN_POSITIVE: f32
1.43.0[src]
pub const MAX: f32
1.43.0[src]
pub const MIN_EXP: i32
1.43.0[src]
pub const MAX_EXP: i32
1.43.0[src]
pub const MIN_10_EXP: i32
1.43.0[src]
pub const MAX_10_EXP: i32
1.43.0[src]
pub const NAN: f32
1.43.0[src]
pub const INFINITY: f32
1.43.0[src]
pub const NEG_INFINITY: f32
1.43.0[src]
pub fn as_ne_bytes(&self) -> &[u8; 4]
[src]
num_as_ne_bytes
)Return the memory representation of this floating point number as a byte array in native byte order.
to_ne_bytes
should be preferred over this whenever possible.
Examples
#![feature(num_as_ne_bytes)] let num = 12.5f32; let bytes = num.as_ne_bytes(); assert_eq!( bytes, if cfg!(target_endian = "big") { &[0x41, 0x48, 0x00, 0x00] } else { &[0x00, 0x00, 0x48, 0x41] } );
pub fn total_cmp(&self, other: &f32) -> Ordering
[src]
total_cmp
)Returns an ordering between self and other values. Unlike the standard partial comparison between floating point numbers, this comparison always produces an ordering in accordance to the totalOrder predicate as defined in IEEE 754 (2008 revision) floating point standard. The values are ordered in following order:
- 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
Note that this function does not always agree with the PartialOrd
and PartialEq
implementations of f32
. In particular, they regard
negative and positive zero as equal, while total_cmp
doesn’t.
Example
#![feature(total_cmp)] 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));
Trait Implementations
impl Clone for FullF32
[src]
impl Copy for FullF32
[src]
impl Debug for FullF32
[src]
impl Deref for FullF32
[src]
impl DerefMut for FullF32
[src]
impl FromStr for FullF32
[src]
type Err = <f32 as FromStr>::Err
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl PartialEq<FullF32> for FullF32
[src]
impl PartialEq<FullF32> for f32
[src]
impl PartialEq<f32> for FullF32
[src]
impl RegexRepresentation for FullF32
[src]
const REGEX: &'static str
[src]
Matches any floating point number, including nan
, inf
, 2.0e5
, …
See FromStr on f32 for details
impl StructuralPartialEq for FullF32
[src]
Auto Trait Implementations
impl RefUnwindSafe for FullF32
impl Send for FullF32
impl Sync for FullF32
impl Unpin for FullF32
impl UnwindSafe for FullF32
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,