Hello.

I would like to know precisely why 0.1 + 0.2 = 0.30000000000000004. I know
that the floating arithmetic needs binary truncations.

I have do this first : keeping power of 2 until 2**{-52}.

*================================*
*k = var('k')*

*s_1 = sum(2**(-2-4*k), k, 0, 12)*
*s_2 = sum(2**(-5-4*k), k, 0, 11)*
*s   = s_1 + s_2*

*print "s =", s.n(digits = 17)*
*--------------------------------*
*s = 0.29999999999999982*
*================================*

We understand the approximation but we do not have the one expected. So I
look at the binary approximations from Sage point of view.

*======================================================================*
*approx_1   = 0.1.str(base=2)*
*approx_2   = 0.2.str(base=2)*
*approx_sum = (0.1+0.2).str(base=2)*
*approx_3   = 0.3.str(base=2)*

*print "      0.1 =", approx_1*
*print "      0.2 =", approx_2*
*print "0.1 + 0.2 =", approx_sum*
*print "      0.3 =", approx_3*
*----------------------------------------------------------------------*
*      0.1 = 0.00011001100110011001100110011001100110011001100110011010*
*      0.2 = 0.0011001100110011001100110011001100110011001100110011010*
*0.1 + 0.2 = 0.010011001100110011001100110011001100110011001100110100*
*      0.3 = 0.010011001100110011001100110011001100110011001100110011*
*======================================================================*

The approximations for 0.1 and 0.2 have more bits that the two other ones,
and this output do not allow to do by hand the evaluation of the
approximation of 0.1 + 0.2.

What I'm doing wrong in my investigations ?

Christophe BAL

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to