logoalt Hacker News

maplanttoday at 8:37 PM1 replyview on HN

It can't do these things because it's not wanted. Say you have the following:

  enum Value {
      Float(f64),
      Ptr(*const T),
  }
Do you want the compiler to disallow certain bit patterns in the Float variant simply so that it can implement NanBoxing?

Replies

vlovich123today at 8:51 PM

Probably with an annotation around a NanBoxable(f64) type that tells it to do that.

That being said, the optimization is complex that may be insufficient:

> For my boxing scheme, I picked a bias value such that the lowest two bits end up being 10. That 1 in bit index 1 indicates that doubles can't be directly compared for equality. Amazingly, we only lose two bits of exponent, and we keep the full precision of the mantissa, meaning we lose no significant digits in the flonum representation.

This suggests the optimization needs more information about specifically how you want to box the float. There probably is some primitives worth considering standardizing to make this kind of optimization possible so that the tunable parameters are passed as const generic values.