[PD] Long long numbers

Mathieu Bouchard matju at artengine.ca
Fri Dec 21 18:11:17 CET 2007

On Fri, 21 Dec 2007, Dafydd Hughes wrote:

> Working on a project that needs really long numbers. I'm sure there's a 
> way of doing it that's obvious to those with better math brains and more 
> experience, but I basically need to keep Pd from slipping into 
> scientific notation.

Everybody learned that at the beginning of elementary school, it's just 
not obvious that it's the same thing, only obvious in retrospect. When you 
compute one digit at a time on paper, that's pretty much the same thing 
that you have to do to work with long numbers that don't fit in float32.

However, you don't have to do it in base 10. Computers work with base 2, 
but computing many bits at once, so you could argue that you are really 
working in base 256 (uint8) or in base 4294967296 (uint32). For floats 
it's more complicated, you could do up to base 16777216, perhaps less.

But there's nothing preventing you from trying out base 10, or base 
1000 or 1000000 (group digits in packs of 3 or 6 for more efficiency: 
123456789 becomes list 123 456 789 or list 123 456789). There are actually 
some libraries for doing that (in C or Perl or other), because several 
uses for long digits are much better if you stick in the same base as what 
you are gonna use in the end (e.g. finance).

It might be easier to use another programming language to do those 
calculations. E.g. Ruby supports this since a long time, and Tcl has it 
since some preview of version 8.5. I don't know much about others, but I 
expect most programming languages to have a library for long ints.

  _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada

More information about the Pd-list mailing list