#nan #pointers #collection #cross-platform #data #float #nan-box

boxing

Easy-to-use, cross-platform implementations for NaN and ptr boxes

3 releases

0.1.2 Jun 6, 2023
0.1.1 Jun 6, 2023
0.1.0 Jun 5, 2023

#1042 in Data structures

35 downloads per month

MIT/Apache

66KB
1.5K SLoC

Boxing

crates.io Documentation MIT/Apache-2 licensed

An easy-to-use, cross-platform library for pointer and NaN boxing data - storing other data values in the unused portions of a float or pointer.

Examples

For more detailed examples, see the nan module documentation.

use boxing::nan::NanBox;

assert_eq!(core::mem::size_of::<NanBox<()>>(), core::mem::size_of::<f64>());

let a = NanBox::<()>::from_float(2.0);
let b = NanBox::<()>::from_inline(-1i32);

assert_eq!(a.clone().try_into_float(), Ok(2.0));
assert_eq!(b.clone().try_into_inline::<i32>(), Ok(-1i32));
assert!((a.into_float_unchecked() + b.into_float_unchecked()).is_nan());

lib.rs:

An easy-to-use, cross-platform library for pointer and NaN boxing data - storing other data values in the unused portions of a float or pointer.

Examples

For more detailed examples, see the [nan] module documentation.

use boxing::nan::NanBox;

assert_eq!(core::mem::size_of::<NanBox<()>>(), core::mem::size_of::<f64>());

let a = NanBox::<()>::from_float(2.0);
let b = NanBox::<()>::from_inline(-1i32);

assert_eq!(a.clone().try_into_float(), Ok(2.0));
assert_eq!(b.clone().try_into_inline::<i32>(), Ok(-1i32));
assert!((a.into_float_unchecked() + b.into_float_unchecked()).is_nan());

Dependencies

~58KB