f256

Crates.iof256
lib.rsf256
version0.6.0
sourcesrc
created_at2023-03-01 07:30:34.829358
updated_at2024-11-26 20:37:38.219134
descriptionOctuple-precision floating-point arithmetic.
homepagehttps://github.com/mamrhein/f256.rs
repositoryhttps://github.com/mamrhein/f256.rs
max_upload_size
id797814
size1,538,865
Michael Amrhein (mamrhein)

documentation

https://docs.rs/f256/

README

This crate provides an implementation of octuple-precision binary floating-point arithmetics.

From Wikipedia:

"In its 2008 revision, the IEEE 754 standard specifies a binary256 format among the interchange formats (it is not a basic format), as having:

    Sign bit: 1 bit
    Exponent width: 19 bits
    Significand precision: 237 bits (236 explicitly stored)

The format is written with an implicit lead bit with value 1 unless the exponent is all zeros. Thus only 236 bits of the significand appear in the memory format, but the total precision is 237 bits (approximately 71 decimal digits: log₁₀(2²³⁷) ≈ 71.344). The bits are laid out as follows:

Layout of octuple-precision floating-point format

Exponent encoding

The octuple-precision binary floating-point exponent is encoded using an offset binary representation, with the zero offset being 262143; also known as exponent bias in the IEEE 754 standard.

    Eₘᵢₙ = −262142
    Eₘₐₓ = 262143
    Exponent bias = 3FFFF₁₆ = 262143

Thus, as defined by the offset binary representation, in order to get the true exponent the offset of 262143 has to be subtracted from the stored exponent.

The stored exponents 00000₁₆ and 7FFFF₁₆ are interpreted specially.

Exponent Significand zero Significand non-zero Equation
00000₁₆ 0, −0 subnormal numbers (-1)signbit × 2⁻²⁶²¹⁴² × 0.significandbits₂
00001₁₆ … 7FFFE₁₆ normalized value normalized value (-1)signbit × 2exponent bits₂ × 1.significandbits₂
7FFFF₁₆ ±∞ NaN (quiet, signalling)

The minimum strictly positive (subnormal) value is 2⁻²⁶²³⁷⁸ ≈ 10⁻⁷⁸⁹⁸⁴ and has a precision of only one bit. The minimum positive normal value is 2⁻²⁶²¹⁴² ≈ 2.4824 × 10⁻⁷⁸⁹¹³. The maximum representable value is 2²⁶²¹⁴⁴ − 2²⁶¹⁹⁰⁷ ≈ 1.6113 × 10⁷⁸⁹¹³.

The type f256 will provide the same stable API as the built-in f64 (besides differences caused by the increased precision).

Getting started

Add f256 to your Cargo.toml:

[dependencies]
f256 = "0.3"

Crate features

By default, only the feature std is enabled.

Ecosystem

  • std - Printing and some tests depend on this feature. Besides that, support for conversion to string and formatting is provided by using crate alloc so that this functionality is also available in non-standard environments.

Optional dependencies

  • num-traits - When enabled, the trait num-traits::Num is implemented for f256.
Commit count: 545

cargo fmt