| Crates.io | floats |
| lib.rs | floats |
| version | 0.2.0 |
| created_at | 2026-01-04 06:50:25.676452+00 |
| updated_at | 2026-01-13 05:10:03.291873+00 |
| description | f16 and f128 floating point types for compatibility with future Rust versions |
| homepage | https://github.com/npmccallum/floats |
| repository | https://github.com/npmccallum/floats |
| max_upload_size | |
| id | 2021449 |
| size | 128,490 |
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:
f16 type for half-precision floating point numbersf128 type for quadruple-precision floating point numbersYou 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.
[dependencies]
floats = { version = "0.1", features = ["casting"] }
casting = "0.1.1"
#![cfg_attr(feature = "nightly", feature(f16, f128))]
use floats::{f16, f128};
// Create f16 from bits
let half = f16::from_bits(0x3C00); // 1.0 in f16
assert_eq!(half.to_bits(), 0x3C00);
#[cfg(feature = "casting")]
{
use casting::CastInto;
// Cast to f32 for arithmetic
let float: f32 = half.cast_into();
assert_eq!(float, 1.0f32);
// Create f128 from f64
let quad: f128 = 3.141592653589793f64.cast_into();
let back: f64 = quad.cast_into();
assert_eq!(back, std::f64::consts::PI);
}
f16: 16-bit half-precision float (IEEE 754)f128: 128-bit quadruple-precision float (IEEE 754)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 optional casting dependency for
CastFrom/CastInto trait implementations between f16/f128 and other
numeric types.nightly: Disable all crate code and simply re-export the nightly
f16/f128 types. This makes it trivial to support either our custom types
or the nightly types without having to resort to complex dependency
management.Upgrading to the standard library f16 and f128 types should be
API-compatible. Use the casting crate's CastFrom
and CastInto traits for conversions.
Licensed under the MIT License.