Skip to main content

Module convert

Module convert 

Source
Expand description

Conversions between floats and integers whose loops vectorize on every target. AVX2 and wasm have no vector instruction for converting between f64 and a 64-bit integer. AArch64 converts bytes to floats two lanes at a time. A loop that converts such types with as runs one item at a time on those targets. int and float convert them through a float’s bits. They use the conversion instruction for types that every target converts in vector form, and for 64-bit integers where the target can. count writes runs of whole numbers as floats. Where the target can’t convert 64-bit integers in vector form, it converts one item in 8. saturated also converts big integers and u64s, saturating them at an integer type’s range.

Structs§

Conversion
Resolved kinds include the working float width even when the other kind is a word.

Enums§

ConversionKind

Traits§

Int
An integer type that int and float convert: i8, i16, i32, i64, u8, u16 or u32.
Saturates
A number that saturated converts to the integer type I: a float to any Int, and a big integer or a u64 to any integer type that TryFrom converts it to.

Functions§

count
Appends the n whole numbers start, start + 1, start + 2 and so on to out as floats of type F, or start, start - 1 and so on where down is true. Each is the whole number rounded once to F. A float narrower than f64 counts in i32 where every item fits one, because every target converts i32 to it in vector form. Otherwise a target with NATIVE_64 converts each item from an integer, as float does. Wasm and x86-64 without AVX-512 have no vector instruction for that, so there each block of 8 items adds 0 to 7 steps to the block’s first item, which comes from the block’s position.
float
i as the nearest float of type F.
floored
The floor of x within t as an integer of type I, saturated at I’s range as saturated saturates: NaN gives 0. The one float-to-integer rule for conversions that change a number’s domain: BPL’s ₓ marks and Python’s astype and integer dtype=.
int
x, a whole float, as an integer of type I. None where x is NaN or infinite, or lies outside I. For i64 and u32, a magnitude beyond 2^51 - 1 also gives None, and so does i32::MIN from an f32. A fraction gives an integer next to it, or None.
saturated
x as an integer of type I, or I’s largest or smallest value where x lies past its range. A float converts as Rust’s as converts it: NaN gives 0, and a fraction gives the integer toward 0. A type that fits an i32 converts from a float in vector form on every target, where as would convert one item at a time, as it does from an f64 on AArch64 and from any float on x86-64. Saturates lists the other sources.