strange behaviour with simple decimals



n 4/11/07, Henning Siebel <henning.siebel at gmx.de> wrote:
>
>   (%i1) 3*1.4^2;
>   (%o1)                          5.879999999999999
>

Maxima uses native 64-bit floating-point arithmetic for numbers with decimal
points, so rounding errors are of the order of 10^-16.

Maxima by default prints 16 decimal digits of floating-point numbers, so
these rounding errors will be visible. This also means that two distinct
floating-point numbers may have the same printed representation:

       7.0/3 => 2.333333333333334
       7.0/3   -  2.333333333333334 =>  -4.44...E-16

This has nothing to do with Maxima, but with the properties of
floating-point calculation.

There are several things you can do differently:

1) You can set fpprintprec:15 or 14; this will hide many rounding errors,
though not larger errors due to cancellation etc.  This is probably the
easiest and most practical solution in simple cases.

2) You can use bigfloat calculations to calculate to any desired number of
digits, e.g. 3*1.4b0^2.  Bigfloat also carries a few extra invisible bits of
precision, so results generally round better.

3) You can calculate using exact numbers, Maxima rational numbers, e.g.
3*(14/10)^2, giving 147/25.

I trust this is helpful.

             -s