ieee754
ieee754 copied to clipboard
Consider simplifying the API and using free functions more
Much of the API can probably be implemented in terms of a much more minimal Ieee754 trait, that basically just describes the bit layout. Everything could then be implemented as (generic) free functions, like ieee754::ulp(1.0), or ieee754::iter(0.0..1.0)
If the API is simplified, I think that most (three from four) associated types can be removed:
Ieee754::ExponentandIeee754::RawExponentcan be replaced byi32andu32, similar to how the standard library's methods that count the number of bits returnu32. This assumes the trait will not be used for floating-point number wider than 2624 bits. (A 2624-bit IEEE754 number has a precision of 2592, that is 1 sign bit, 32 exponent bits and 2591 mantissa bits, with the raw exponent in the range 0 ≤ x ≤ 232 − 1, and the true exponent in the range −231 + 2 ≤ x ≤ 231 − 1 since the true exponent is only meaningful for normal numbers. If that is too tight, a 2208-bit number needs only 31 bits for the exponent.) I don't think this trait is aimed at such large numbers.Ieee754::Significandcan be replaced byIeee754::Bits; is there a point in having a narrower mantissa? The only practical case I can think of is not strictly IEEE754: bfloat16 has a precision of only 8 while the number is 16 bits wide, but I don't think having a narrower significand in this case is worth the extra type.