comp.lang.ada
 help / color / mirror / Atom feed
* How to get high-precision floating point--MPFR
@ 2012-10-19  8:57 Jerry
  2012-10-19  9:45 ` Dmitry A. Kazakov
  2012-10-19 10:47 ` Georg Bauhaus
  0 siblings, 2 replies; 5+ messages in thread
From: Jerry @ 2012-10-19  8:57 UTC (permalink / raw)


I have a few lines of floating point code in a large program which I suspect could be causing subtle errors. (It uses lots of recursion with some dicey numbers.) I am using GNAT GPL 2011 on an Intel Mac, Long_Float (64 bits) everywhere.

I understand that recent versions of GCC come with MPFR (Multiple Precision Floating-Point Reliably).

Here is what I want to do

type Giant_Float is digits 30;

but GNAT says, sorry not more than digits 18 (see below related note). So what I think I have to do is find an Ada binding to MPFR and re-write my code. Is that correct? Do I already have the library with GPL 2011 or OS X 10.7? If not, I can build with Macports. I gather that Vincent's binding here
http://code.google.com/p/adabindinggmpmpfr/
is the way to go. Did this binding ever make it into GCC?

If I do quadruple precision I would expect the relevant lines to execute 5-6 times slower than with Long_Float. I need only multiplication and addition, and will convert the result to Long_Float.

I don't need a computational model where the precision increases every time I do an operation; I'm certain that I can easily specify a fixed precision that will suffice. Is that the way MPFR works?



On a related note, I have a (borrowed/stolen) program which prints out some numeric attributes. I won't bother pasting the code, but a partial output listing is this:

Long_Float bits is  64
Long_Long_Float bits is  128

The smallest Long_Float is 1.94469227433160678E-62
The largest Long_Float is 2.57110087081438330E+61
The number of digits in Long_Float is 15
The size of the Long_Float mantissa in bits is 51
However, the CPU's Long_Float mantissa is 53

The smallest Long_Long_Float is 1.76868732008334226E-74
The largest Long_Long_Float is 2.82695530364541493E+73
The number of digits in Long_Long_Float is 18
The size of the Long_Long_Float mantissa in bits is 61
However, the CPU's Long_Long_Float mantissa is 64

Can someone explain this? At first it looks like Long_Long_Float is going to be quadruple precision (128 bits) but then the precision results indicate that it is only 3 digits better than Long_Float and has a rather small increase in exponent range. And why is the Ada type using less mantissa bits than the hardware?

Thanks,
Jerry



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-10-19 11:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-19  8:57 How to get high-precision floating point--MPFR Jerry
2012-10-19  9:45 ` Dmitry A. Kazakov
2012-10-19 10:31   ` Jerry
2012-10-19 10:47 ` Georg Bauhaus
2012-10-19 11:05   ` Jerry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox