Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider simplifying the API and using free functions more #8

Open
huonw opened this issue Jan 8, 2019 · 1 comment
Open

Consider simplifying the API and using free functions more #8

huonw opened this issue Jan 8, 2019 · 1 comment

Comments

@huonw
Copy link
Owner

huonw commented Jan 8, 2019

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)

@tspiteri
Copy link

If the API is simplified, I think that most (three from four) associated types can be removed:

  • Ieee754::Exponent and Ieee754::RawExponent can be replaced by i32 and u32, similar to how the standard library's methods that count the number of bits return u32. 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::Significand can be replaced by Ieee754::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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants