Dealing with large numbers

Mikey mikeythek at gmail.com
Wed Sep 17 14:09:45 EDT 2008


You would not believe the Real and Integer issues that can be
encountered these days, in all kinds of tools.  Reals especially lose
precision in normal ranges, due to the way they are represented.

The easiest way, imho, to deal with these issues, is, when you reach
some threshold, switch your math routines to manual ones.

This used to be a standard problem at ACM competitions.  The fibonacci
problem was one of them.  You start with numbers that are out of
bounds for a real or integer of any precision or size, and manipulate
them.

So, you take each digit, perform the operation, and move to the next
one, just like when you're doing it by hand.

The good news is that with RR it's significantly easier than many
other tools because there isn't all the (st00p1d) conversion from
string to integer to string.  You just do it.

One trick in this regard - sometimes you can save yourself some
headaches if you reverse the order of the digits.  Adding a position
to the front of a string CAN be slow, but adding one on the back
GENERALLY is not.

You could also use blobs, which have arbitrarily large size, and
perform the same operations.  Note that in the case of blobs and other
binary types, you can perform arithmetic operations by using logical
binary ones, as well (AND, OR, XOR).

All of this is left as an exercise for the reader.



More information about the use-livecode mailing list