[issue7704] Math calculation problem (1.6-1.0)>0.6, python said TRUE

pedro flores report at bugs.python.org
Thu Jan 14 23:04:46 CET 2010


pedro flores <pflores82 at gmail.com> added the comment:

kk, then i cannot use this comparison?, and this not happen
with....8.6-8>0.6 this is false, according to python.

2010/1/14 Mark Dickinson <report at bugs.python.org>

>
> Mark Dickinson <dickinsm at gmail.com> added the comment:
>
> This is not a bug:  Python, like many other computer languages, stores
> floats in binary.  The values 1.6 and 0.6 aren't exactly representable in
> the internal format used, so the stored versions of 1.6 and 0.6 are actually
> just very close approximations to those values.  It just so happens that the
> approximation for 1.6 is a tiny amount larger than 1.6 (the exact value
> stored is 1.600000000000000088817841970012523233890533447265625), while the
> approximation for 0.6 is a tiny amount smaller than 0.6 (the exact value is
> 0.59999999999999997779553950749686919152736663818359375).
>
> I recommend looking at the appendix to the Python tutorial for more
> information about floating point:
>
> http://docs.python.org/tutorial/floatingpoint.html
>
> ----------
> nosy: +mark.dickinson
> resolution:  -> invalid
> status: open -> closed
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <http://bugs.python.org/issue7704>
> _______________________________________
>

----------
Added file: http://bugs.python.org/file15884/unnamed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7704>
_______________________________________
-------------- next part --------------
kk, then i cannot use this comparison?, and this not happen with....8.6-8&gt;0.6 this is false, according to python.<br><br><div class="gmail_quote">2010/1/14 Mark Dickinson <span dir="ltr">&lt;<a href="mailto:report at bugs.python.org">report at bugs.python.org</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Mark Dickinson &lt;<a href="mailto:dickinsm at gmail.com">dickinsm at gmail.com</a>&gt; added the comment:<br>
<br>
This is not a bug:  Python, like many other computer languages, stores floats in binary.  The values 1.6 and 0.6 aren&#39;t exactly representable in the internal format used, so the stored versions of 1.6 and 0.6 are actually just very close approximations to those values.  It just so happens that the approximation for 1.6 is a tiny amount larger than 1.6 (the exact value stored is 1.600000000000000088817841970012523233890533447265625), while the approximation for 0.6 is a tiny amount smaller than 0.6 (the exact value is 0.59999999999999997779553950749686919152736663818359375).<br>

<br>
I recommend looking at the appendix to the Python tutorial for more information about floating point:<br>
<br>
<a href="http://docs.python.org/tutorial/floatingpoint.html" target="_blank">http://docs.python.org/tutorial/floatingpoint.html</a><br>
<br>
----------<br>
nosy: +mark.dickinson<br>
resolution:  -&gt; invalid<br>
status: open -&gt; closed<br>
<div><div></div><div class="h5"><br>
_______________________________________<br>
Python tracker &lt;<a href="mailto:report at bugs.python.org">report at bugs.python.org</a>&gt;<br>
&lt;<a href="http://bugs.python.org/issue7704" target="_blank">http://bugs.python.org/issue7704</a>&gt;<br>
_______________________________________<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Pedro Flores C.<br>Estudiante Memorista de Informática 2009-2010<br>Universidad de Concepción, Concepción<br>Chile<br>


More information about the Python-bugs-list mailing list