nanval 0.2.1

A no_std, zero-dependency crate for the creation and handling of NaN-tagged 64-bit floating-point values.
Documentation
  • Coverage
  • 98.46%
    64 out of 65 items documented0 out of 32 items with examples
  • Size
  • Source code size: 26.16 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.83 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Longor1996/nanval
    8 3 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Longor1996

nanval

Crates.io Docs.rs GitHub LOC

A no_std, zero-dependency crate for the creation and handling of NaN-tagged 64-bit floating-point values.

Inspired by this article and this crate.

How does this work?

When a 64-bit floating-point number is set to NaN/0x7FF8000000000000, its bits are as follows:

s111 1111 1111 1qxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
^               ^\____________________________________________________________/
|               |                             ^
| Sign Bit      | Quiet Bit                   | Data Bits

As long as the data bits aren't all set to 0, indicating the original/sentinel NaN value, they can be literally anything else! This gives us 50 bits to mess with/use as we please...

UInts / Unsigned Integers

Look at the module [crate::uint] for this.

TODO: Add explanation.

Cells / Pointers

Look at the module [crate::cell] for this.

Since it doesn't matter what the sign-bit s is set to, we can use it as a flag/marker that indicates that the value is some kind of cell or ptr.

Combine this with the fact that basically all x64-platforms only use the lower 48 or 50 bits for addressing (ignoring CHERI shenanigans), we are left with 3 bits (that includes the 'quiet' bit) to store some kind of type-tag for the cell; look at the [crate::cell::CellTag].

References