Home

Awesome

f16 and bf16 floating point types for Rust

Crates.io Documentation Crates.io Build status CircleCI

This crate implements a half-precision floating point f16 type for Rust implementing the IEEE 754-2008 standard binary16 a.k.a "half" format, as well as a bf16 type implementing the bfloat16 format.

Usage

The f16 and bf16 types attempt to match existing Rust floating point type functionality where possible, and provides both conversion operations (such as to/from f32 and f64) and basic arithmetic operations. Hardware support for these operations will be used whenever hardware support is available—either through instrinsics or targeted assembly—although a nightly Rust toolchain may be required for some hardware.

This crate provides no_std support so can easily be used in embedded code where a smaller float format is most useful.

Requires Rust 1.70 or greater. If you need support for older versions of Rust, use 1.x versions of this crate.

See the crate documentation for more details.

Optional Features

Hardware support

The following list details hardware support for floating point types in this crate. When using std library, runtime CPU target detection will be used. To get the most performance benefits, compile for specific CPU features which avoids the runtime overhead and works in a no_std environment.

ArchitectureCPU Target FeatureNotes
x86/x86_64f16cThis supports conversion to/from f16 only (including vector SIMD) and does not support any bf16 or arithmetic operations.
aarch64fp16This supports all operations on f16 only.

More Documentation

License

This library is distributed under the terms of either of:

at your option.

This project is REUSE-compliant. Copyrights are retained by their contributors. Some files may include explicit copyright notices and/or license SPDX identifiers. For full authorship information, see the version control history.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.