strange behaviour with simple decimals



 

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Henning Siebel
> Sent: Wednesday, April 11, 2007 2:35 AM
> To: maxima at math.utexas.edu
> Subject: strange behaviour with simple decimals
> 
> Hello,
> 
> can anybody help my with this result:
> 
>   Maxima 5.11.0 http://maxima.sourceforge.net
>   Using Lisp CLISP 2.41 (2006-10-13)
>   Distributed under the GNU Public License. See the file COPYING.
>   Dedicated to the memory of William Schelter.
>   This is a development version of Maxima. The function bug_report()
>   provides bug reporting information.
>   (%i1) 3*1.4^2;
>   (%o1)                          5.879999999999999
> 
> 
> It obviously should be 5.88. 


Actually, it is obviously 5.88 only if 1.4 were exactly representable in
machine precision floating point.
And if floating point arithmetic were exact.  Both are false.
So what is obvious to you is in reality based on a misunderstanding of what
kind of computer arithmetic is used when you type 3*1.4^2.

In fact, typing 1.4 gives a number that is, to more precision, about
1.3999999999999999112   which is the closest you can get to a number with a
binary fraction of 53 bits.



>Is there a reason, why maxima 
> produces this result,

Yes.  It is what every computer conforming to the IEEE floating point
standard will get, in double precision arithmetic. It should work the same
in Java, C, Lisp, Fortran, etc etc..

> or is this a bug?

A bug in your understanding of computer arithmetic  :)

You can sometimes get a better answer using softwre bigfloats. In fact if
you type  3*1.4b0^2
perhaps you will get 5.88b0


RJF