float lower limit at given precision

Slava Feshchenko slavaf2000 at gmail.com
Fri Feb 24 01:48:23 CET 2012


I am not wrong... here is a quote from the documentation found here:
http://gmplib.org/manual/Floating_002dpoint-Functions.html#Floating_002dpoint-Functions


The mantissa [is] stored in binary, as might be imagined from the fact
precisions are expressed in bits. One consequence of this is that decimal
fractions like 0.1 cannot be represented exactly. The same is true of plain
IEEE double floats. This makes both highly unsuitable for calculations
involving money or other values that should be exact decimal fractions.
(Suitably scaled integers, or perhaps rationals, are better choices.)

Therefore, in the absence of complete understanding of that person's
computation requirements, especially if he stated that he needs high
precision calculations, I thought it would be prudent to warn him of this
limitation of mpf_t type. In the end it's up to him to decide what base is
acceptable: 10 or 2 and wheather he wants to specify precision in bits or
decimals digits.

Cheers!


On Thu, Feb 23, 2012 at 4:50 PM, Torbjorn Granlund <tg at gmplib.org> wrote:

> Slava Feshchenko <slavaf2000 at gmail.com> writes:
>
>  I don't necessarily understand what you are doing, but when you say you
>  require great precision, i want to warn you that mpf_t might not be your
>  best choice since it is still a binary floating point - just arbitrary
>  precision, meaning extremely large range. So it behaves just like double
> or
>  float native types, but with much larger (virtually unlimited) range.
>
> This is plain and simply wrong.
>
> The precision is for all practical purposes unlimited, but while the
> range is lagre, it is not unlimited.  And no, mpf does not behave like
> the C double type, for any meaningful definition of "behave like".
>
> I would suggest that you actually take a quick look at the mpf
> documentation before you advice others about its operation.
>
> To answer the original question:
>
> The GMP team usually recommends new project to use mpfr instead of mpf.
> This is a GMP extension library, with an API similar to GMP's.
>
> See mpfr.org.
>
> --
> Torbjörn
>


More information about the gmp-discuss mailing list