
f16 and bf16 half-precision floating types offering conversions to/from f32/f64, arithmetic, hardware-accelerated paths, zero-copy vector conversions, serde and numeric-trait interop, and no_std-friendly usage.
This is a Kotlin Multiplatform line-by-line transliteration port of half.
Original Project: This port is based on half. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced from
https://github.com/starkat99/half-rs. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs where appropriate so they continue to resolve from this repository.
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 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.81 or greater. If you need support for older versions of Rust, use previous versions of this crate.
See the crate documentation for more details.
alloc — Enable use of the alloc crate when not using
the 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.
std — Enable features that depend on the Rust std library, including everything in the
alloc feature.
Enabling the std feature enables runtime CPU feature detection of hardware support.
Without this feature detection, harware is only used when compiler target supports them.
serde - Implement Serialize and Deserialize traits for f16 and bf16. This adds a
dependency on the serde crate.
num-traits — Enable ToPrimitive, FromPrimitive, ToBytes, FromBytes, Num, Float,
FloatCore and Bounded trait implementations from the
num-traits crate.
bytemuck — Enable Zeroable and Pod trait implementations from the
bytemuck crate.
zerocopy — Enable IntoBytes and FromBytes trait implementations from the
zerocopy crate.
rand_distr — Enable sampling from distributions like StandardUniform and StandardNormal
from the rand_distr crate.
rkyv -- Enable zero-copy deserializtion with rkyv crate.
aribtrary -- Enable fuzzing support with arbitrary
crate by implementing Arbitrary trait.
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.
| Architecture | CPU Target Feature | Notes |
|---|---|---|
x86/x86_64
|
f16c |
This supports conversion to/from f16 only (including vector SIMD) and does not support any bf16 or arithmetic operations. |
aarch64 |
fp16 |
This supports all operations on f16 only. |
All files in this library are dual-licensed and 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.
dependencies {
implementation("io.github.kotlinmania:half-kotlin:3.0.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same license terms as the upstream half. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the half authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the half maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.
This is a Kotlin Multiplatform line-by-line transliteration port of half.
Original Project: This port is based on half. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced from
https://github.com/starkat99/half-rs. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs where appropriate so they continue to resolve from this repository.
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 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.81 or greater. If you need support for older versions of Rust, use previous versions of this crate.
See the crate documentation for more details.
alloc — Enable use of the alloc crate when not using
the 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.
std — Enable features that depend on the Rust std library, including everything in the
alloc feature.
Enabling the std feature enables runtime CPU feature detection of hardware support.
Without this feature detection, harware is only used when compiler target supports them.
serde - Implement Serialize and Deserialize traits for f16 and bf16. This adds a
dependency on the serde crate.
num-traits — Enable ToPrimitive, FromPrimitive, ToBytes, FromBytes, Num, Float,
FloatCore and Bounded trait implementations from the
num-traits crate.
bytemuck — Enable Zeroable and Pod trait implementations from the
bytemuck crate.
zerocopy — Enable IntoBytes and FromBytes trait implementations from the
zerocopy crate.
rand_distr — Enable sampling from distributions like StandardUniform and StandardNormal
from the rand_distr crate.
rkyv -- Enable zero-copy deserializtion with rkyv crate.
aribtrary -- Enable fuzzing support with arbitrary
crate by implementing Arbitrary trait.
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.
| Architecture | CPU Target Feature | Notes |
|---|---|---|
x86/x86_64
|
f16c |
This supports conversion to/from f16 only (including vector SIMD) and does not support any bf16 or arithmetic operations. |
aarch64 |
fp16 |
This supports all operations on f16 only. |
All files in this library are dual-licensed and 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.
dependencies {
implementation("io.github.kotlinmania:half-kotlin:3.0.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same license terms as the upstream half. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the half authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the half maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.