Why does bfloat behave this way?



Floating point numbers are represented in Maxima (as in most computer
systems) as IEEE-754 double precision
floating-point<https://en.wikipedia.org/wiki/Double-precision_floating-point_format>;,
that is, (53-bit integer) * 2^n. The best double precision
floating-point approximation to

     3.4567890123 = 34567890123 / 10^10

is

     486499803365397 / 2^47

To convert this to a decimal fraction integer * 10^n, we need to multiply
numerator and denominator by 5^47, giving

   (486499803365397*5^47) / (2^47 * 5^47)

that is:

   345678901229999979705098667182028293609619140625 / 10^47

which can also be written as

    3.45678901229999979705098667182028293609619140625

If you would like to work with the *exact* decimal number 3.4567890123 in
Maxima, you can write it as 34567890123 * 10^-10, which uses an exact
rational number representation.

            -s



On Sat, Nov 2, 2013 at 7:29 AM, Igor Korepanov <paloff at ya.ru> wrote:

> Dear all,
>
> I have just joined this mailing list, so I would like to say first that I
> have enjoyed using Maxima for quite a while already, since I switched to
> free software a few years ago. Maxima is great, and my thanks to its
> creators and maintainers (I also often acknowledge this explicitly in my
> mathematical papers).
>
> Now the question: why does bfloat behave exactly this way? And not some
> other way?
>
> (%i1) float2bf: false;
> (%o1) false
>
> (%i2) fpprec: 300;
> (%o2) 300
>
> (%i3) x: bfloat( 3.4567890123 );
> bfloat: converting float 3.4567890123 to bigfloat.
> (%o3) 3.45678901229999979705098667182028293609619140625b0
>
> Best wishes,
>
> Igor
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>