Division vs DIV - Valentin's findings
|
04-02-2023, 04:22 PM
Post: #1
|
|||
|
|||
Division vs DIV - Valentin's findings
I feel this observation is worth a discussion, from over on the latest Pi Day offering:
(03-29-2023 01:16 AM)Valentin Albillo Wrote: Indeed IP(T/(K*K)) and T DIV (K*K), which would appear at first sight to be equivalent, do really differ at times (though very rarely and for large values of T, it seems,) when the former's rounding does not match the latter's truncation. I find myself caught in a superposition of states: a lack of surprise that sometimes division will round upwards, and a great surprise that this rounding happens so very rarely in this experiment. Checking a few of the examples, it seems that division on this 12 digit calculation will round upwards if the 13th digit would be 5 or greater. Is it obvious as to why this should happen so rarely - am I missing something? Why these particular divisors, and why should divisors come and go as we traverse the table? Is there pattern here which I'm not seeing? |
|||
04-02-2023, 05:16 PM
Post: #2
|
|||
|
|||
RE: Division vs DIV - Valentin's findings
These cases are not rare at all, as soon as the dividend is >1E11 such as (4E11+7)/4 --> 10000000002 that clearly illustrates what is happening.
Although I don't have a rigorous reasoning, I don't believe the problem can occur with dividend X<1E11, so IP(X/Y) is then safe for integer division. This is not specific to the 71B or Saturn machines, it happens as well on the 10-digit 41C and 34-digit Free42 with the 1E9 and 1E33 limits, respectively. Rule of the thumb: pay attention to integer divisions when the dividend is less than a factor of 10 from the maximum integer. J-F |
|||
04-02-2023, 05:31 PM
Post: #3
|
|||
|
|||
RE: Division vs DIV - Valentin's findings
Mmm, but... if what we had was a rounding from a 13th digit, wouldn't we see it about half of the time? We see it rarely, and I think we don't believe there is a 13th digit, so there's something about the mechanics of division here which is, I think, a bit surprising.
(These are decimal calculations... division proceeds by shift and subtract? Is there an estimating of the next digit?) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)