Faster addition in string math. Now with multiplication!
#16
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.
Reply


Messages In This Thread
RE: Faster addition in string math. - by SMcNeill - 08-18-2022, 08:16 PM
RE: Faster addition in string math. - by Pete - 08-18-2022, 09:15 PM
RE: Faster addition in string math. - by SMcNeill - 08-18-2022, 09:59 PM
RE: Faster addition in string math. - by SMcNeill - 08-18-2022, 10:08 PM
RE: Faster addition in string math. - by SMcNeill - 08-18-2022, 11:46 PM
RE: Faster addition in string math. - by Pete - 08-19-2022, 10:07 AM
RE: Faster addition in string math. - by SMcNeill - 08-19-2022, 11:26 AM
RE: Faster addition in string math. - by Pete - 08-19-2022, 04:44 PM
RE: Faster addition in string math. - by SMcNeill - 08-19-2022, 04:58 PM
RE: Faster addition in string math. - by SMcNeill - 08-19-2022, 05:57 PM
RE: Faster addition in string math. - by Jack - 08-19-2022, 09:54 PM
RE: Faster addition in string math. - by SMcNeill - 08-19-2022, 11:48 PM
RE: Faster addition in string math. - by SMcNeill - 08-20-2022, 03:49 AM
RE: Faster addition in string math. - by Pete - 08-20-2022, 06:16 AM
RE: Faster addition in string math. - by SMcNeill - 08-20-2022, 06:41 AM



Users browsing this thread: 6 Guest(s)