Alan Gauld wrote:
"Lie Ryan" <[email protected]> wrote
A friend of mine suggested me to do the next experiment in python
and Java.
It's a simple program to sum all the numbers from 0 to 1000000000.
result = i = 0
while i < 1000000000:
result += i
i += 1
print result
Are you sure you're not causing Java to overflow here? In Java,
Arithmetic Overflow do not cause an Exception, your int will simply wrap
to the negative side.
Thats why I asked if he got a float number back.
I never thought of it just wrapping, I assumed it would convert to
floats.
Now that would be truly amusing.
If Java gives you the wrong answer much faster than Python gives the
right one, which is best in that scenario?! :-)
Alan G.
It's been years, but I believe Java ints are 64 bits, on a 32bit
implementation. Just like Java strings are all unicode.
DaveA
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor