[Coco] printing out floating point numbers...(only peripherally related to coco)

Carey Eugene carey at cebridge.net
Tue Jul 11 20:06:58 EDT 2006


Aaron;

>   I'm working on a program that can handle floating point numbers with
> gobs and gobs of precision.  I'd like to make a float similar to the IEEE

>   The form of a float I happen to be using is a 32 byte value:

Just 32 bytes, huh...

Hmmm....  Right off hand I can't think of anything specifically taylored for
the CoCo or for just 32 bytes.

Most bignum packages that I have or know of are either very generic (often 
using decimals instead of binary and tend to be somewhat slow) or are for 
large precision (millions to billions of digits).  32 bytes is pretty small.

Also, most multi-precision stuff will be for integers, not floats.

I could probably find several that would be almost what you'd want.  But
they wouldn't really be fast.  They are too generic.  They would also
probably be decimal but you want binary.

Most of it's not a big issue, but the multiplication and division have to be
done carefully so they wont be too slow.  Although I guess for just 32
bytes, you probably wouldn't need anything too fancy.


If you were needing just twice the precision, you could use one of the
"double-double" packages.  David Bailey & Keith Briggs have done that.  It's
a pretty neat trick because it only requires normal C (or Fortran) 'double'.
You could do two levels of that and get higher precision.  It'd be messy,
but you could do it.


I could suggest GMP (or the floating routines that GMP uses), but you'd end
up with quite a bit of bloat.

You could check the following packages:  MAPM.  MPFR.  CALC (source forge)

And quite a few others, but they almost certainly wont be suitable.  Most of
the packages would be far too large for the CoCo.  And they usually carry a
lot of extra baggage & bloat.

I'm a wee bit more familar with larger sizes than what you are wanting.

Sorry, but a 32 byte float is a bit of an odd size.  Most people want much
larger.


> On another note, given such a float, I'm trying to get a good routine to
> print them to the screen (or a string).

Printing them out isn't too difficult, as long as you are willing to accept
that the value you print wont be exactly what the value really is.  That's
due to radix conversion issues.

If you can live with scientific notation (D.DDDD e XX) format, printing them
out is fairly easy.  You shift until you get a digit, print, etc., then
print the exponent.

> This actually sounds like something that would be in a textbook somewhere,
> but I don't seem to be able to find it.  Thanks in advance for your help.

Knuth.  The art of seminumerical algorithms, vol 2 would be a good
reference.  Chapter 4.2 would be for floating point, and chapter 4.3 is for
multi-precision math.


Carey







More information about the Coco mailing list