#no_std #f16 #bfloat16

no-std half

Half-precision floating point f16 and bf16 types for Rust implementing the IEEE 754-2008 standard binary16 and bfloat16 types

9 stable releases

✓ Uses Rust 2018 edition

new 1.4.0 Oct 13, 2019
1.3.0 Oct 3, 2018
1.1.2 Jul 13, 2018
1.1.0 Mar 17, 2018
0.1.0 Mar 18, 2016

#3 in No standard library

Download history 6624/week @ 2019-06-30 5397/week @ 2019-07-07 6440/week @ 2019-07-14 6296/week @ 2019-07-21 5958/week @ 2019-07-28 6793/week @ 2019-08-04 6800/week @ 2019-08-11 7895/week @ 2019-08-18 6624/week @ 2019-08-25 6751/week @ 2019-09-01 7185/week @ 2019-09-08 8785/week @ 2019-09-15 7313/week @ 2019-09-22 8986/week @ 2019-09-29 12034/week @ 2019-10-06

32,135 downloads per month
Used in 130 crates (17 directly)


2.5K SLoC

f16 and bf16 floating point types for Rust

Crates.io docs.rs Build Status Build status

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.


The f16 and bf16 types provides conversion operations as a normal Rust floating point type, but since they are primarily leveraged for minimal floating point storage and most major hardware does not implement them, all math operations should be done as an f32 type.

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

Requries Rust 1.32 or greater. If you need support for older versions of Rust, use versions 1.3 and earlier of this crate.

See the crate documentation for more details.

Optional Features

  • serde - Implement Serialize and Deserialize traits for f16 and bf16. This adds a dependency on the serde crate.

  • use-intrinsics - Use hardware intrinsics for f16 and bf16 conversions if available on the compiler host target. By default, without this feature, conversions are done only in software, which will be the fallback if the host target does not have hardware support. Available only on Rust nightly channel.

  • std - Enable features that depend on the Rust std library.

    This enables the vec module, which contains zero-copy conversions for the Vec type. This allows fast conversion between raw Vec<u16> bits and Vec<f16> or Vec<bf16> arrays, and vice versa.

    In addition, enabling the std feature enables runtime CPU feature detection when the use-intrsincis feature is also enabled. Without this feature detection, intrinsics are only used when compiler host target supports them.

More Documentation


This library is distributed under the terms of either of:

at your option.


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.