[docs] Problem With Python Arithmetic
John Hulbert
compute at hulbert-web.org.uk
Sat Apr 5 12:09:16 CEST 2014
Hello.
I don't know if this is a bug in Python, or my own misuse of the language.
I have the following code:
p=3470494144279007
p=(p*3+1)/2
print(p)
p=3470494144279007.0
p=(p*3+1)/2
print(p)
These should give the same answer, but I get the following 2 answers,
with the first one correct, and the second one wrong. (They differ in
the last integer digit):
5205741216418511.0
5205741216418510.0
Also, can you tell me (a Python beginner), how I can force Python to use
long integer arithmetic throughout an algorithm?
Regards
John Hulbert,
(Reading, UK)
More information about the docs
mailing list