Infinite-precision arithmetic
Cubist at aol.com
Cubist at aol.com
Tue May 24 05:55:25 EDT 2005
sez xbury.cs at clearstream.com:
>Very nice!
Thanks!
>That's the easy part though ;)
[nods] Don't I know it!
>Divisions is where it gets harder...
And square roots... and powers... and DIV and MOD... and...
I've already come up with an infinite-precision algorithm for
multiplication which looks promising; I haven't coded it up yet, however, so I am not
entirely certain how well it will work out "in real life". In pseudocode:
InfPreMult N1, N2
put 0 into Rezult
Put N1 into Fred
Repeat until N2 = 0
If N1 is odd then add Adder to Rezult
Add Fred to Fred
put N1 div 2 into N1
end repeat
End of algorithm
Naturally, there's also the option of splitting N1 and N2 up into
7-character chunks, doing all the multiplies for the relevant chunk-pairs, and
combining the results of said multiplies. That looks like it'd be a pain to code, so
I am going to try the other algorithm first. Depending on how fast it is, I
may or may not want to give "7-char chunks" a try as well.
>...and using arrays may be much more efficient than using strings or
numbers...
>But items could work well too but wouldn't it be slower?
I've never touched arrays before. I shall have to see if arrays make a
difference, speed-wise. Every millisecond -- heck, every *micro*second -- counts
in this sort of thing.
More information about the use-livecode
mailing list