Builtin type std::prelude::f32
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
true
if the number has a negative sign,false
otherwise. -
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
f64
from raw bitsExample
let f = f32::from_bits(0x40490fdb); assert_eq!(f, std::math::PI as f32);
Run this example -
Returns the raw bits of
self
Example
let x = 1.0f32; assert_eq!(x.to_bits(), 0x3f800000u32);
Run this example -
Returns the smallest floating point number strictly greater than
self
.If
self
is NaN or positive infinity, it returnsself
unchanged.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
self
is NaN or negative infinity, it returnsself
unchanged.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
self
into a whole and fractional part -
Power function
-
Rounds
self
to 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
false
if arguments are equal,true
otherwise -
Returns
true
iflhs
is strictly less thanrhs
,false
otherwise -
Returns
true
iflhs
is less or equal torhs
,false
otherwise -
Returns
true
iflhs
strictly greater thanrhs
,false
otherwise -
Returns
true
iflhs
greater than or equalrhs
,false
otherwise -
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
true
if the number is NaN,false
otherwise. -
Returns
true
if the number is infinite,false
otherwise. -
Returns
true
if the number is neither infinite nor NaN,false
otherwise.