On 01/07/2010 20:18, Eike Welk wrote:
Hello Richard!

On Thursday July 1 2010 15:11:21 Richard D. Moores wrote:
Thanks to yours and others responses, I've learned some things I
didn't know, but remember, I'm starting with long ints such as

Also note that in Python 3 the "/" (division) operator returns a floating
point number when you divide integers. This is one of the changes that Python
3 introduces.

As you are using long integers (and you were previously writing about prime
numbers) the precision of floating point numbers might not be enough for your
purposes.

Therefore you should probably use the integer division operator: "//"


The following (edited) snippet from IPython demonstrates "//" and the loss of
precision when using "/":


...
Python 2.6.2 (r262:71600, Mar 29 2010, 15:30:01)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
...

In [1]: from __future__ import  division

In [2]: a = 1000000000000000000000000000000000000000000000000000000002

In [3]: a
Out[3]: 1000000000000000000000000000000000000000000000000000000002L

In [4]: a//2
Out[4]: 500000000000000000000000000000000000000000000000000000001L

In [5]: a/2
Out[5]: 4.9999999999999994e+56

In [6]: long(a/2)
Out[6]: 499999999999999937061060126016582882140297920412594995200L


Eike.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Drat, drat and double drat, I believe Dick Dastardly from the Wacky Races cartoons. I meant to mention this, got side-tracked and completely forgot, sorry.

Kindest regards.

Mark Lawrence.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to