-
Notifications
You must be signed in to change notification settings - Fork 984
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
do not ignore explicitly given mantissa width #868
base: main
Are you sure you want to change the base?
Conversation
I haven't yet understand the function completely, but it looks |
Chez also runs out of memory with Your example, on the other hand, is an inexact number, so the final result won't take much space. The question is whether the calculation has to take that much space, especially in the less trivial case |
Here's what I'm seeing:
I don't see why there's inherently a problem here. As long as the number written before the |
(Please excuse the delayed answer; it was night here.) Have you tried
and much larger denominators for higher mantissa widths. It would be wrong to truncate the precision. The reason is that 1/10 has a period of length 4 in binary representation. In fact,
in binary representation. From this, we can deduce that
in binary representation, where I rounded to even. This means that larger and larger denominators (all powers of two) are needed the larger the mantissa width is. |
Sorry, I misunderstood what you meant by "Chez also", and i was confused about fractions and binary representations. Thank you for the tutorial! It makes sense that It still seems like |
Also, the results of |
Oh, I see. Indeed, what I wrote wasn't very clear.
Consider the following number in binary notation (where N* means to repeat the following binary digit N times):
Let If N is sufficiently larger than p and q sufficiently larger than N, we have that |
I do not have a full characterisation. But a denominator N means that the quotient has a period length of at most N - 1, so one should be able to reduce the case of an arbitrary mantissa width roughly to the case of a mantissa width <= 2*N. But I wonder whether it makes sense to spend the time getting the details right and writing extra code for huge mantissa widths. In practice, the largest mantissa widths may come from when using libraries like GNU MPFR. Do you think someone would use floats that use megabytes of memory? |
Maybe it is not that complicated to actually implement mantissa truncation.
The estimates can possibly be off by 1 or 2, but one can code safely. |
That sounds really great. As we've established, I'm not clear on the math, but it certainly sounds plausible. My experience with Scheme numbers is that these details end up being worthwhile, even though it means extra code, and even through the happy spaces often end up being complex (e.g., only power-of-two denominators). Unfortunately, my experience with Scheme numbers is also that I have to learn a lot of new things, and then I forget them soon afterward! |
Avoiding running out of memory for a very large precision request when the number with adjusted precision should take about as much memory as the number without an adjustment.
Hi @mnieper — I pushed a commit to add precision bounding in (I think) the way you describe. Does it look right? Do I understand correctly that this captures all of the cases where the end result number can be represented with about the same amount of memory as the number without a precision adjustment? |
Thanks a lot, Matthew. I am going to take a look at it within the next few days. (I wanted to have come up with some code as well but haven't found the time.) |
This fixes the issue raised in #866, making mantissa widths meaningful.