Because an integer’s binary representation only has a particular number of leading zero bits if we’re dealing with a fixed bit width: The binary integer 0b1000 always has three trailing zero bits, but it can have 0, 1, 42, a million, or infinite leading zero bits. Put concretely, you need to constrain T.RawSignificand to conform to FixedWidthInteger.
Also, word of advice: I’d implement any code that deals with binary representations of floating-point types only for the concrete type or types you’re actually going to use (chances are, just Float and Double). Float80 doesn’t work like the other types, for example, so you’d either have to expend additional effort to make sure your generic implementation is correct or you’d have a “generic” implementation that isn’t actually. Then consider how you’re actually going to test that your generic code works for a generic floating-point type…
Thank you very much! That explanation makes total sense.
I actually wanted to constrain to Float and Double. I couldn’t find another way that to use BinaryFloatingPoint. What would you suggest to constrain T thus?