[][src]Crate floatconv

Floating point conversion functions.

Software and hardware implementations

The native module provides only those conversions which are natively available on the target hardware.

The soft module provides a software implementation of all conversion functions, for targets which do not provide them natively.

The root of the crate exposes the best version of all available functions.

Rounding mode

  • Functions named _round round the integer to the closest possible floating point number, and breaks ties to even.
  • Functions named _truncate truncate the result, which means they round towards zero.
  • Functions named _any are an alias of whichever variant is fastest on the target.
  • Functions without a rounding mode in their name do not round. These conversions are always lossless.

Speed

For conversions that aren't available natively, the software implementations in this crate seem to be both faster and smaller in almost all cases compared to the ones currently used by x as f64 (from the compiler builtins runtime support library).

Work in progress

This crate is usable, but still incomplete:

  • There's no support for f32 yet.
  • There's no support for converting to integers yet.
  • Native conversions are only available on ARM (32- and 64-bit) and x86 (32- and 64-bit).
  • The software implementations can probably be optimized further.
  • More benchmarking still needs to happen.

Re-exports

pub use soft::i128_to_f64_round;
pub use soft::i128_to_f64_truncate;
pub use soft::i128_to_f64_truncate as i128_to_f64_any;
pub use soft::i64_to_f64_truncate;
pub use soft::u128_to_f64_round;
pub use soft::u128_to_f64_truncate;
pub use soft::u128_to_f64_truncate as u128_to_f64_any;
pub use soft::u64_to_f64_truncate;
pub use native::i32_to_f64;
pub use native::u32_to_f64;
pub use native::i64_to_f64_round;
pub use native::i64_to_f64_round as i64_to_f64_any;
pub use native::u64_to_f64_round;
pub use native::u64_to_f64_round as u64_to_f64_any;

Modules

native

Floating point conversion instructions natively available on the target.

soft

Software implementations of floating point conversion functions.