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§
Traits§
- Int
- An integer type that
intandfloatconvert:i8,i16,i32,i64,u8,u16oru32. - Saturates
- A number that
saturatedconverts to the integer typeI: a float to anyInt, and a big integer or au64to any integer type thatTryFromconverts it to.
Functions§
- count
- Appends the
nwhole numbersstart,start + 1,start + 2and so on tooutas floats of typeF, orstart,start - 1and so on wheredownis true. Each is the whole number rounded once toF. A float narrower thanf64counts ini32where every item fits one, because every target convertsi32to it in vector form. Otherwise a target withNATIVE_64converts each item from an integer, asfloatdoes. 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
ias the nearest float of typeF.- floored
- The floor of
xwithintas an integer of typeI, saturated atI’s range assaturatedsaturates: NaN gives 0. The one float-to-integer rule for conversions that change a number’s domain: BPL’sₓmarks and Python’sastypeand integerdtype=. - int
x, a whole float, as an integer of typeI.Nonewherexis NaN or infinite, or lies outsideI. Fori64andu32, a magnitude beyond 2^51 - 1 also givesNone, and so doesi32::MINfrom anf32. A fraction gives an integer next to it, orNone.- saturated
xas an integer of typeI, orI’s largest or smallest value wherexlies past its range. A float converts as Rust’sasconverts it: NaN gives 0, and a fraction gives the integer toward 0. A type that fits ani32converts from a float in vector form on every target, whereaswould convert one item at a time, as it does from anf64on AArch64 and from any float on x86-64.Saturateslists the other sources.