08-20-2022, 06:41 AM
When dealing with division, I've found that the way to do it in "chunks" is just like I described for the SQRT method above.
Get a seed using floating point math for an estimate, and then basically multiply on a binary system and zoom in on your decimal values.
Say your next 9 digits are "123456789" in the answer.
Multiply (EA$ + _TRIM$(STR$(500000000))) by your divisor and compare if the result too large or too small. (EA$ is your Existing Answer that you've calculated.) In this case, it's too large.
Half the gap, try again. (250000000) Too large
Half the gap, try again. (125000000) Too large
Half the gap, try again. (062500000) Too small
Half the gap...
You seek the result based on a binary search of basically a value from 0 to 999999999.... at most 30 multiplication runs will get you the answer. 2 ^ 30 is > 999,999,999. And that gives 9 digits to the answer at a time.
There might be a better way to do it, but if so, my brain isn't coming up with it. When dealing with obscene values like dividing (37 digits with 14 decimal places) into a (1234 digit with 36 decimal place) value, I just can't comprehend an easier way towards the solution.
Get a seed using floating point math for an estimate, and then basically multiply on a binary system and zoom in on your decimal values.
Say your next 9 digits are "123456789" in the answer.
Multiply (EA$ + _TRIM$(STR$(500000000))) by your divisor and compare if the result too large or too small. (EA$ is your Existing Answer that you've calculated.) In this case, it's too large.
Half the gap, try again. (250000000) Too large
Half the gap, try again. (125000000) Too large
Half the gap, try again. (062500000) Too small
Half the gap...
You seek the result based on a binary search of basically a value from 0 to 999999999.... at most 30 multiplication runs will get you the answer. 2 ^ 30 is > 999,999,999. And that gives 9 digits to the answer at a time.
There might be a better way to do it, but if so, my brain isn't coming up with it. When dealing with obscene values like dividing (37 digits with 14 decimal places) into a (1234 digit with 36 decimal place) value, I just can't comprehend an easier way towards the solution.