tdelmas/typed_floats

Implement Layout optimisation

Opened this issue · 0 comments

For Option<Float> like https://doc.rust-lang.org/stable/std/num/struct.NonZeroUsize.html

Cf https://internals.rust-lang.org/t/nonmaxusize-and-niche-value-optimisation/19661

  • At least for NonZero* (as their binary representation is only zeros)
  • Ideally for all, as all representations of NaNs can be used
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]

For NaN:
rustc_layout_scalar_valid_range_end

After 11111111110000000000000000000000 it's only (negatives) NaN
How to exclude NaNs starting with 0 ? (Positive NaNs.

If strictly positive, we can exclude >= 10000000000000000000000000000000

https://www.h-schmidt.net/FloatConverter/IEEE754.html

So:

  • For Negative:
#[repr(transparent)]
// Exclude all positive numbers
#[rustc_layout_scalar_valid_range_start(0x80000000)]
// 0xff800001 and after: Negative NaNs
#[rustc_layout_scalar_valid_range_end(0xff800001)]
  • For Non-Zero:
#[repr(transparent)]
// Exclude 0x00000000 (`0.0`)
#[rustc_layout_scalar_valid_range_start(1)]
// 0xff800001 and after: Negative NaNs
#[rustc_layout_scalar_valid_range_end(0xff800001)]
  • For Others:
#[repr(transparent)]
// 0xff800001 and after: Negative NaNs
#[rustc_layout_scalar_valid_range_end(0xff800001)]