Faster addition in string math. Now with multiplication!
#18
Here's a way which seems like it'd be mighty speed to me -- and it doesn't take any multiplication after a 1 run look-up table!

Make an array from 0 to 9.  (DIM foo(9) AS STRING)
Take your divisor and multiply it by 0 to 9.  Store the results.

For example, my divisor is 100.
foo(1) = 100
foo(2) = 200
...
foo(9) = 900)

With your lookup table, you now just grab chunks of your string and compare.

Write a SELECT CASE to find your value

SELECT CASE num2check$
    CASE < foo(1): dividend = 0
    CASE < foo(2): dividend = 1
    CASE < foo(3): dividend = 2
....
    CASE ELSE: dividend = 9
END SELECT

*******

In practice, let's use 123456789/ 3 as an easy example:
f1 = 3
f2 = 6
f3 = 9
... you get the array....

start with the first digit: 1...  smaller than f1, result is 0. 1 - 0 = 1 carryover
bring down the 2.  Value is now 12.  is smaller than f5, result is 4.  12 - 12 = 0 carryover
bring down the 3.  Carryover was 0, value is 3.  Less than f2, result is 1.  3 - 3 = 0
bring down the 4.  Carryover was 0, value is 4.  Less than f2, result is 1.  4 - 3 = 1 carryover
bring down the 5.  Carryover was 1, value is 15.  Less than f6, result is 5....
... and on.

Instead of doing that multiplication math over and over, do it once and store it in an array.  I imagine you'll save a boatload of time processing, if you do so.
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
RE: Faster addition in string math. Now with multiplication! - by SMcNeill - 08-20-2022, 09:52 AM



Users browsing this thread: 8 Guest(s)