# [Maxima] Precision of float and bfloat

reyssat eric.reyssat at math.unicaen.fr
Fri Oct 16 01:52:06 CDT 2009

```Leo Butler a écrit :
> On Thu, 15 Oct 2009, Raymond Toy wrote:
>
> < reyssat wrote:
> < > Hi,
> < >
> < > I have some questions and remarks about precision of floats and bigfloats.
> < >
> < > I construct
> < >
> < > f(i):=block([u], u:sqrt(10^(2*i)+1)/10^i, print(bfloat(u)),print(float(u)));
> < >
> < > then :
> < > (%i3) f(2);
> < > 1.000049998750063b0
> < > 1.000049998750062
> < >
> < > **** this is ok, just slightly strange that float gives a better result
> < > than bfloat (the right answer is 1.000049998750062496..., so should be
> < > rounded to ...0062 and not ...0063).
> < >
> < I think bfloats try to be accurate, but there's no guarantee that it is
> < accurate to the last bit, especially for the special functions.
> < > By the way, I cannot find in the documentation (at least in chapter 10,
> < > floating point) the definition and precision of a float.
> < >
> < The precision of a float depends on the double-float type of the
> < underlying lisp.  But I think everyone uses IEEE double-floats, so the
> < precision is well defined.
> < >
> < > (%i5) f(200);
> < > 1.0b0
> < > Maxima encountered a Lisp error:
> < >
> < >  Error in PROGN [or a callee]: Can't print a non-number.
> < >
> < > Automatically continuing.
> < > To reenable the Lisp debugger set *debugger-hook* to nil.
> < >
> < > **** bfloat is ok. But float cannot calculate this since some
> < > intermediate result is too big (once again, is the limit for the
> < > exponent given in the documentation ?), although the result itself is a
> < >
> < No I don't think the limit is in the documentation.  But the largest
> < IEEE number is 2^1024 minus one bit.  There is some package that has
> < this information, but I can't remember the name of the package.
>
> Ray, do you mean the lisp constants
>
> most-positive-double-float
> most-positive-fixnum
>
> etc.? These are accessible in the ususal way from within maxima:
>
> :lisp most-positive-fixnum
> 536870911
>
> :lisp most-positive-double-float
> 1.7976931348623157e308
>
> Leo
>
>
Thank you for the info. I just made some tests to find the limit :

(%i1) build_info ();
Maxima version: 5.17.1
Maxima build date: 19:10 12/18/2008
host type: i686-pc-mingw32
lisp-implementation-type: GNU Common Lisp (GCL)
lisp-implementation-version: GCL 2.6.8

(%o1)
(%i2) float(2^1024-2^970-1);
(%o2)                       1.7976931348623157E+308
(%i3) float(2^1024-2^970);
Maxima encountered a Lisp error:

Error in PROGN [or a callee]: Can't print a non-number.

Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.

And this seems consistent too :
(%i4) 2^1024-2^970+1.0;
Maxima encountered a Lisp error:

Error in PROGN [or a callee]: Can't print a non-number.

Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.
(%i5) 2^1024-2^970-1+2.0;
(%o5)                       1.7976931348623157E+308

Eric Reyssat
```