The primitive float type.
Methods
Returns true if this value is NaN.
Examples
let nan = f64NAN;
let f = 7.0_f64;
assert!;
assert!;
Returns true if this value is positive infinity or negative infinity, and false otherwise.
Examples
let f = 7.0f64;
let inf = f64INFINITY;
let neg_inf = f64NEG_INFINITY;
let nan = f64NAN;
assert!;
assert!;
assert!;
assert!;
Returns true if this number is neither infinite nor NaN.
Examples
let f = 7.0f64;
let inf = f64INFINITY;
let neg_inf = f64NEG_INFINITY;
let nan = f64NAN;
assert!;
assert!;
assert!;
assert!;
Returns true if the number is subnormal.
Examples
let min = f64MIN_POSITIVE; // 2.2250738585072014e-308_f64
let max = f64MAX;
let lower_than_min = 1.0e-308_f64;
let zero = 0.0_f64;
assert!;
assert!;
assert!;
assert!;
assert!;
// Values between `0` and `min` are Subnormal.
assert!;
Returns true if the number is neither zero, infinite, subnormal, or NaN.
Examples
let min = f64MIN_POSITIVE; // 2.2250738585072014e-308f64
let max = f64MAX;
let lower_than_min = 1.0e-308_f64;
let zero = 0.0f64;
assert!;
assert!;
assert!;
assert!;
assert!;
// Values between `0` and `min` are Subnormal.
assert!;
Computes the absolute value of self.
Examples
let x = 3.5_f64;
let y = -3.5_f64;
let abs_difference_x = .abs;
let abs_difference_y = .abs;
assert!;
assert!;
assert!;
Computes the arccosine of a number.
Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1].
Examples
let f = FRAC_PI_4;
// acos(cos(pi/4))
let abs_difference = .abs;
assert!;
Computes the arcsine of a number.
Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1].
Examples
let f = FRAC_PI_2;
// asin(sin(pi/2))
let abs_difference = .abs;
assert!;
Computes the arctangent of a number.
Return value is in radians in the range [-pi/2, pi/2];
Examples
let f = 1.0;
// atan(tan(1))
let abs_difference = .abs;
assert!;
Computes the four quadrant arctangent of self (y) and other (x) in radians.
x = 0,y = 0:0x >= 0:arctan(y/x)->[-pi/2, pi/2]y >= 0:arctan(y/x) + pi->(pi/2, pi]y < 0:arctan(y/x) - pi->(-pi, -pi/2)
Examples
// Positive angles measured counter-clockwise
// from positive x axis
// -pi/4 radians (45 deg clockwise)
let x1 = 3.0;
let y1 = -3.0;
// 3pi/4 radians (135 deg counter-clockwise)
let x2 = -3.0;
let y2 = 3.0;
let abs_difference_1 = .abs;
let abs_difference_2 = .abs;
assert!;
assert!;
Returns the cube root of a number.
Examples
let x = 8.0_f64;
// x^(1/3) - 2 == 0
let abs_difference = .abs;
assert!;
Returns the smallest integer greater than or equal to self.
Examples
let f = 3.01_f64;
let g = 4.0_f64;
assert_eq!;
assert_eq!;
Restrict a value to a certain interval unless it is NaN.
Returns max if self is greater than max, and min if self is less than min. Otherwise this returns self.
Note that this function returns NaN if the initial value was NaN as well.
Panics
Panics if min > max, min is NaN, or max is NaN.
Examples
assert!;
assert!;
assert!;
assert!;
Computes the cosine of a number (in radians).
Examples
let x = 2.0 * PI;
let abs_difference = .abs;
assert!;
Calculates Euclidean division, the matching method for rem_euclid.
This computes the integer n such that self = n * rhs + self.rem_euclid(rhs). In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs.
Examples
let a = 7.0;
let b = 4.0;
assert_eq!; // 7.0 > 4.0 * 1.0
assert_eq!; // -7.0 >= 4.0 * -2.0
assert_eq!; // 7.0 >= -4.0 * -1.0
assert_eq!; // -7.0 >= -4.0 * 2.0
Returns e^(self), (the exponential function).
Examples
let one = 1.0_f64;
// e^1
let e = one.exp;
// ln(e) - 1 == 0
let abs_difference = .abs;
assert!;
Returns 2^(self).
Examples
let f = 2.0_f64;
// 2^2 - 4 == 0
let abs_difference = .abs;
assert!;
Returns the largest integer less than or equal to self.
Examples
let f = 3.7_f64;
let g = 3.0_f64;
let h = -3.7_f64;
assert!;
assert!;
assert!;
Returns the natural logarithm of the number.
This returns NaN when the number is negative, and negative infinity when number is zero.
Examples
let one = 1.0;
// e^1
let e = one.exp;
// ln(e) - 1 == 0
let abs_difference = .abs;
assert!;
Returns the logarithm of the number with respect to an arbitrary base.
This returns NaN when the number is negative, and negative infinity when number is zero.
The result might not be correctly rounded owing to implementation details; self.log2() can produce more accurate results for base 2, and self.log10() can produce more accurate results for base 10.
Examples
let twenty_five = 25.0_f64;
// log5(25) - 2 == 0
let abs_difference = .abs;
assert!;
Returns the base 10 logarithm of the number.
This returns NaN when the number is negative, and negative infinity when number is zero.
Examples
let hundred = 100.0_f64;
// log10(100) - 2 == 0
let abs_difference = .abs;
assert!;
Returns the base 2 logarithm of the number.
This returns NaN when the number is negative, and negative infinity when number is zero.
Examples
let four = 4.0_f64;
// log2(4) - 2 == 0
let abs_difference = .abs;
assert!;
Non-positive values:
assert_eq!;
assert!;
Raises a number to a floating point power.
Examples
let x = 2.0_f64;
let abs_difference = .abs;
assert!;
Raises a number to an integer power.
Using this function is generally faster than using powf. It might have a different sequence of rounding operations than powf, so the results are not guaranteed to agree.
Examples
let x = 2.0_f64;
let abs_difference = .abs;
assert!;
Computes the least nonnegative remainder of self (mod rhs).
In particular, the return value r satisfies 0.0 <= r < rhs.abs() in most cases. However, due to a floating point round-off error it can result in r == rhs.abs(), violating the mathematical definition, if self is much smaller than rhs.abs() in magnitude and self < 0.0. This result is not an element of the function’s codomain, but it is the closest floating point number in the real numbers and thus fulfills the property self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs) approximately.
Examples
let a = 7.0;
let b = 4.0;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// limitation due to round-off error
assert!;
Returns the nearest integer to self. If a value is half-way between two integers, round away from 0.0.
Examples
let f = 3.3_f64;
let g = -3.3_f64;
let h = -3.7_f64;
let i = 3.5_f64;
let j = 4.5_f64;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Computes the sine of a number (in radians).
Examples
let x = FRAC_PI_2;
let abs_difference = .abs;
assert!;
Returns the square root of a number.
Returns NaN if self is a negative number other than -0.0.
Examples
let positive = 4.0_f64;
let negative = -4.0_f64;
let negative_zero = -0.0_f64;
let abs_difference = .abs;
assert!;
assert!;
assert!;
Computes the tangent of a number (in radians).
Examples
let x = FRAC_PI_4;
let abs_difference = .abs;
assert!;
Converts radians to degrees.
Examples
let abs_difference = .abs;
assert!;
Converts degrees to radians.
Examples
let abs_difference = .abs;
assert!;
Trait Implementations
Clone the specified value.
Examples
let a = 42;
let b = a;
let c = a.clone;
a += 1;
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values for equality.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values for inequality.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values.
Examples
use Ordering;
assert_eq!;
assert_eq!;
assert_eq!;
Tests less than (for self and other) and is used by the < operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests less than or equal to (for self and other) and is used by the <= operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests greater than (for self and other) and is used by the > operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests greater than or equal to (for self and other) and is used by the >= operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values.
Examples
use Ordering;
assert_eq!;
assert_eq!;
assert_eq!;
Return the minimum of two values.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Return the maximum of two values.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Protocols
$a.max
Returns the maximum of the two numbers, ignoring NaN.
If one of the arguments is NaN, then the other argument is returned. This follows the IEEE 754-2008 semantics for maxNum, except for handling of signaling NaNs; this function handles all NaNs the same way and avoids maxNum's problems with associativity. This also matches the behavior of libm’s fmax.
Examples
let x = 1.0_f64;
let y = 2.0_f64;
assert_eq!;
$a.min
Returns the minimum of the two numbers, ignoring NaN.
If one of the arguments is NaN, then the other argument is returned. This follows the IEEE 754-2008 semantics for minNum, except for handling of signaling NaNs; this function handles all NaNs the same way and avoids minNum's problems with associativity. This also matches the behavior of libm’s fmin.
Examples
let x = 1.0_f64;
let y = 2.0_f64;
assert_eq!;
let $out = clone
Clone a f64.
Note that since the type is copy, cloning has the same effect as assigning it.
Examples
let a = 5.0;
let b = a;
let c = a.clone;
a += 1.0;
assert_eq!;
assert_eq!;
assert_eq!;
if value == b
Test two floats for partial equality.
Examples
assert!;
assert!;
assert!;
assert!;
assert!;
if value == b
Test two floats for total equality.
Examples
use eq;
assert_eq!;
assert_eq!;
assert_eq!;
if value < b
Perform a partial ordered comparison between two floats.
Examples
use Ordering;
use partial_cmp;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
if value < b
Perform a totally ordered comparison between two floats.
Examples
use Ordering;
use cmp;
assert_eq!;
assert_eq!;
assert_eq!;