[Coco] Calculating large numbers using string functions

Mathieu Bouchard matju at artengine.ca
Sat Jul 4 23:58:23 EDT 2015


It's a lot more efficient to do it in binary rather than decimal. I don't 
know any BASIC09, but I suppose that you have 16-bit ints in there, and 
you need 32-bit support. What you can do is use pairs of 16-bit ints to 
implement 32-bit ints. When you add the least-significant words together, 
you check whether the result means that there was a carry, and you take it 
into account when you add the most-significant words together. That's how 
C compilers implement 32-bit numbers using 16-bit variable (or 64-bit 
using 32-bit, etc), and that's surely a trick used within the 
implementation of 40-bit floats in ColorBASIC.

However, to print to screen, you'd have to write a function for converting 
it to a decimal string, which would mean implementing 32-bit division 
yourself...

But if all you want is write it in kilobytes (of the 1024 kind), a 
right-shift of 10 is easy enough to implement (to divide by 1024) and then 
you would just use the normal print function to print something as big as 
"65535 KB".


Le 2015-06-28 à 12:43:00, K. Pruitt a écrit :

> A while back a discussion was had here on the list concerning calculating 
> file sizes under Basic09.
>
> I found a little file listing in the December 1984 issue of Hot CoCo which 
> can large numbers, negative or positive, using the CoCo's standard string 
> functions. This method could be easily adapted for use in Basic09 to 
> calculate large file sizes.
>
> The issue is available in the color computer archives.

  ______________________________________________________________________
| Mathieu BOUCHARD ----- téléphone : +1.514.383.3801 ----- Montréal, QC


More information about the Coco mailing list