Discrepency between JPython and CPython

John W. Baxter jwbnews at scandaroon.com
Sun Apr 30 21:50:18 EDT 2000


In article <etdpur72pmx.fsf at w20-575-109.mit.edu>, Alex 
<cut_me_out at hotmail.com> wrote:

> > Consider the expression str(1.14 * 200).
> > In CPython it yields 228.0
> > In JPython it yields 227.99999999999997
> > 
> > Shouldn't this result in consistent values across variuos 
> > implementation?  
> > If so, which of the implementation is buggy?  
> > I think it is JPython, may be I am wrong.
> 
> Both implementations just reach down to a lower level routine -- for
> CPython, it's multiplication in C, for JPython, it's multiplication in
> Java.  So probably the discrepency is between the C compiler used to
> build your CPython (or maybe your CPU, if it does floating point
> operations.  I understand they do, these days.  [The only CPU I ever
> learnt anything about in detail was the 6809.] :) and the JVM your
> JPython is running on.
> 
> Alex

No...this is just yet another instance of CPython (less than 1.6) lying 
about the value of floats.  Since 1.14 is not precise, 1.14 * 200 can't 
be...yet the interpreter lies (by rounding off) and pretends that it is.

   --John

-- 
John W. Baxter   Port Ludlow, WA USA  jwbnews at scandaroon.com



More information about the Python-list mailing list