Struct norad::IntegerOrFloat[][src]

pub struct IntegerOrFloat(_);
Expand description

A number that may be either an integer or float.

It should serialize to an integer if it effectively represents one.

Implementations

impl IntegerOrFloat[src]

pub fn new(value: f64) -> Self[src]

pub fn get(&self) -> f64[src]

pub fn set(&mut self, value: f64)[src]

pub fn is_integer(&self) -> bool[src]

Methods from Deref<Target = f64>

pub const RADIX: u321.43.0[src]

pub const MANTISSA_DIGITS: u321.43.0[src]

pub const DIGITS: u321.43.0[src]

pub const EPSILON: f641.43.0[src]

pub const MIN: f641.43.0[src]

pub const MIN_POSITIVE: f641.43.0[src]

pub const MAX: f641.43.0[src]

pub const MIN_EXP: i321.43.0[src]

pub const MAX_EXP: i321.43.0[src]

pub const MIN_10_EXP: i321.43.0[src]

pub const MAX_10_EXP: i321.43.0[src]

pub const NAN: f641.43.0[src]

pub const INFINITY: f641.43.0[src]

pub const NEG_INFINITY: f641.43.0[src]

pub fn as_ne_bytes(&self) -> &[u8; 8][src]

🔬 This is a nightly-only experimental API. (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.5f64;
let bytes = num.as_ne_bytes();
assert_eq!(
    bytes,
    if cfg!(target_endian = "big") {
        &[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
    } else {
        &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]
    }
);

pub fn total_cmp(&self, other: &f64) -> Ordering[src]

🔬 This is a nightly-only experimental API. (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 f64. In particular, they regard negative and positive zero as equal, while total_cmp doesn’t.

Example

#![feature(total_cmp)]
struct GoodBoy {
    name: String,
    weight: f64,
}

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: f64::INFINITY },
    GoodBoy { name: "Abs. Unit".to_owned(), weight: f64::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 IntegerOrFloat[src]

fn clone(&self) -> IntegerOrFloat[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for IntegerOrFloat[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Deref for IntegerOrFloat[src]

type Target = f64

The resulting type after dereferencing.

fn deref(&self) -> &f64[src]

Dereferences the value.

impl<'de> Deserialize<'de> for IntegerOrFloat[src]

fn deserialize<D>(deserializer: D) -> Result<IntegerOrFloat, D::Error> where
    D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl From<f64> for IntegerOrFloat[src]

fn from(value: f64) -> Self[src]

Performs the conversion.

impl From<i32> for IntegerOrFloat[src]

fn from(value: i32) -> Self[src]

Performs the conversion.

impl PartialEq<IntegerOrFloat> for IntegerOrFloat[src]

fn eq(&self, other: &IntegerOrFloat) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &IntegerOrFloat) -> bool[src]

This method tests for !=.

impl Serialize for IntegerOrFloat[src]

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
    S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl TryFrom<IntegerOrFloat> for NonNegativeIntegerOrFloat[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(value: IntegerOrFloat) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl Copy for IntegerOrFloat[src]

impl StructuralPartialEq for IntegerOrFloat[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

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]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]