floats
f16 and f128 floating point types for compatibility with future Rust versions.
The goal of this crate is to provide some minimal f16 and f128 functionality
on stable Rust today with a smooth transition to the currently unstable f16
and f128 types in the Rust standard library.
This crate provides:
- A custom
f16type for half-precision floating point numbers - A custom
f128type for quadruple-precision floating point numbers
You can load and store the f16 and f128 types to and from bits/bytes and use
the CastFrom/CastInto traits from the casting
crate to cast them to fully supported Rust floating point types where you can do
arithmetic operations. However, no arithmetic operations are yet supported on
the custom f16 and f128 types.
Installation
[]
= { = "0.1", = ["casting"] }
= "0.1.1"
Quick Start
use ;
// Create f16 from bits
let half = from_bits; // 1.0 in f16
assert_eq!;
Types
f16: 16-bit half-precision float (IEEE 754)f128: 128-bit quadruple-precision float (IEEE 754)
Feature Flags
asm(default): Use hardware-accelerated inline assembly for f16 conversions when available (aarch64 fp16, x86_64 f16c). Disable for testing or compatibility.casting(default): Enable the optionalcastingdependency forCastFrom/CastIntotrait implementations betweenf16/f128and other numeric types.nightly: Disable all crate code and simply re-export the nightlyf16/f128types. This makes it trivial to support either our custom types or the nightly types without having to resort to complex dependency management.
Upgrade Path
Upgrading to the standard library f16 and f128 types should be
API-compatible. Use the casting crate's CastFrom
and CastInto traits for conversions.
License
Licensed under the MIT License.