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

* Re: How to get high-precision floating point--MPFR
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry A. Kazakov @ 2012-10-19  9:45 UTC (permalink / raw)


On Fri, 19 Oct 2012 01:57:19 -0700 (PDT), Jerry wrote:

> And why is the Ada type using less
> mantissa bits than the hardware?

AFAIK x86/x86-64 do not have hardware 128-bit floats (IEEE or not). See 

http://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format

Which also says that gcc's long double is merely 80-bit extended precision.
That, I presume, corresponds to the GNAT's Long_Long_Float.

You could compare attributes of Long_Long_Float and
Interfaces.C.long_double, T'Machine_Mantissa (A.5.3), in particular, it
should be 64 for 80-bit extended precision.

Why GNAT uses 128 bit instead of 80 actually used bit? Maybe, because of
alignment issues.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: How to get high-precision floating point--MPFR
  2012-10-19  9:45 ` Dmitry A. Kazakov
@ 2012-10-19 10:31   ` Jerry
  0 siblings, 0 replies; 5+ messages in thread
From: Jerry @ 2012-10-19 10:31 UTC (permalink / raw)
  Cc: mailbox

On Friday, October 19, 2012 2:45:06 AM UTC-7, Dmitry A. Kazakov wrote:
> On Fri, 19 Oct 2012 01:57:19 -0700 (PDT), Jerry wrote:
> 
> > And why is the Ada type using less
> > mantissa bits than the hardware?
> 
> AFAIK x86/x86-64 do not have hardware 128-bit floats (IEEE or not). See 
> 
> http://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format
> 
> Which also says that gcc's long double is merely 80-bit extended precision.
> That, I presume, corresponds to the GNAT's Long_Long_Float.

That makes sense. I think I once knew that.

> You could compare attributes of Long_Long_Float and
> Interfaces.C.long_double, 

The same program reports:
In Interfaces.C, long_double bits is 128

T'Machine_Mantissa (A.5.3), in particular, it
> should be 64 for 80-bit extended precision.
> 
> Why GNAT uses 128 bit instead of 80 actually used bit? Maybe, because of
> alignment issues.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de



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

* Re: How to get high-precision floating point--MPFR
  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:47 ` Georg Bauhaus
  2012-10-19 11:05   ` Jerry
  1 sibling, 1 reply; 5+ messages in thread
From: Georg Bauhaus @ 2012-10-19 10:47 UTC (permalink / raw)


On 19.10.12 10:57, Jerry wrote:
> Here is what I want to do
> 
> type Giant_Float is digits 30;

One possible solution has a description here:

http://web.am.qub.ac.uk/users/j.parker/miscellany/arbitrary/README.arbitrary




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

* Re: How to get high-precision floating point--MPFR
  2012-10-19 10:47 ` Georg Bauhaus
@ 2012-10-19 11:05   ` Jerry
  0 siblings, 0 replies; 5+ messages in thread
From: Jerry @ 2012-10-19 11:05 UTC (permalink / raw)


On Friday, October 19, 2012 3:48:15 AM UTC-7, Georg Bauhaus wrote:
> On 19.10.12 10:57, Jerry wrote:
> > Here is what I want to do
> > 
> > type Giant_Float is digits 30;
> 
> One possible solution has a description here:
> 
> http://web.am.qub.ac.uk/users/j.parker/miscellany/arbitrary/README.arbitrary

That looks interesting. The readme says it is done entirely in integers but suitably optimized runs 1/2 to 2/3 the speed of Fortran quad precision.

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