xur_

> built-in type

float

methods of float values

in the browser

These are methods on integer and float values, available directly without importing a module. In each signature x is the value the method is called on: 3.min(5) calls min with x = 3 and y = 5. Wrap a negative literal in parentheses to call a method on it: (-5).abs().

Integer methods work on 64-bit signed values. A result that doesn't fit, such as 2.pow(70) or abs of the smallest i64, is a runtime error.

> methods

# float.abs(x: f64) -> f64

The absolute value.

# float.ceil(x: f64) -> f64

The smallest whole number not less than x.

# float.floor(x: f64) -> f64

The largest whole number not greater than x.

# float.round(x: f64) -> f64

The nearest whole number, rounding halves away from zero: 2.5.round() is 3 and (-2.5).round() is -3.

# float.sqrt(x: f64) -> f64

The square root. A negative value gives NaN.

# float.to_int(x: f64) -> i64

The value as an integer, dropping the fraction (toward zero). Values beyond the i64 range give the largest or smallest i64, and NaN gives 0.

# float.to_string(x: f64) -> str

The value as a string. Whole numbers have no fraction: 3.0.to_string() is "3".

> examples

use std::io;

fn main() {
    io::println("{}", (-5).abs());
    io::println("{}", 255.to_hex());
    io::println("{}", 3.14.floor());
}