Single precision floating point type
Methods
impl f32 { ... }
-
Parses a floating point number from a string.
Returns
Option::none()if the string does not represent a valid floating point number.Example
assert_eq!(f32::parse("3.1415"), Option::some(3.1415f32)); assert_eq!(f32::parse("inf"), Option::some(f32::infinity()));Run this example -
Returns
trueif the number has a negative sign,falseotherwise. -
fn max_value() -> f32
Returns the maximum value of
f32. -
fn min_value() -> f32
Returns the minimum value of
f32. -
fn min_positive() -> f32
Returns the smallest positive value of
f32. -
fn epsilon() -> f32
Returns the machine epsilon for
f32. -
Create
f64from raw bitsExample
let f = f32::from_bits(0x40490fdb); assert_eq!(f, std::math::PI as f32);Run this example -
Returns the raw bits of
selfExample
let x = 1.0f32; assert_eq!(x.to_bits(), 0x3f800000u32);Run this example -
Returns the smallest floating point number strictly greater than
self.If
selfis NaN or positive infinity, it returnsselfunchanged.Example
assert_eq!(0.0f32.next_up(), 1.0e-45f32); assert_eq!(1.0f32.next_up(), 1.0000001f32); assert_eq!((-1.0f32).next_up(), -0.99999994f32); assert_eq!(f32::neg_infinity().next_up(), -3.4028235e38f32); assert_eq!(f32::infinity().next_up(), f32::infinity()); assert!(f32::nan().next_up().is_nan());Run this example -
Returns the largest floating point number strictly less than
self.If
selfis NaN or negative infinity, it returnsselfunchanged.Example
assert_eq!(0.0f32.next_down(), -1.0e-45f32); assert_eq!(1.0f32.next_down(), 0.99999994f32); assert_eq!((-1.0f32).next_down(), -1.0000001f32); assert_eq!(f32::infinity().next_down(), 3.4028235e38f32); assert_eq!(f32::neg_infinity().next_down(), f32::neg_infinity()); assert!(f32::nan().next_down().is_nan());Run this example -
Inverse cosine
-
Inverse sine
-
Inverse tangent
-
Four-quadrant inverse tangent
-
Inverse hyperbolic cosine
-
Cube root
-
Ceiling of number
-
Cosine
-
Hyperbolic cosine
-
Gauss error function
-
Complementary error function (1 - erf(self))
-
Exponential function (e^
self) -
Floor of number
-
Natural logarithm
-
Base 2 logarithm
-
Base 10 logarithm
-
Decompose
selfinto a whole and fractional part -
Power function
-
Rounds
selfto the closest integer.If the number is halfway between two integers, it is rounded away from zero.
-
Sine function
-
Hyperbolic sine function
-
Square root
-
Tangent function
-
Hyperbolic tangent function
-
Returns the integer part of
self(round towards zero).
Mixins
impl f32 { ... }
-
mixin BuiltinComparable<f32>
-
Returns
falseif arguments are equal,trueotherwise -
Returns
trueiflhsis strictly less thanrhs,falseotherwise -
Returns
trueiflhsis less or equal torhs,falseotherwise -
Returns
trueiflhsstrictly greater thanrhs,falseotherwise -
Returns
trueiflhsgreater than or equalrhs,falseotherwise -
mixin<F> FloatFormattable<f32, F>
F: Formatter<F> -
-
fn nan() -> Self
Returns
NaN. -
fn infinity() -> Self
Returns a positive infinity.
-
fn neg_infinity() -> Self
Returns a negative infinity.
-
Returns
trueif the number is NaN,falseotherwise. -
Returns
trueif the number is infinite,falseotherwise. -
Returns
trueif the number is neither infinite nor NaN,falseotherwise.