From: Tim Wintle on
On Thu, 2010-06-24 at 09:33 -0700, ilovesss2004 wrote:
> On Jun 24, 5:50 pm, Tim Harig <user...(a)ilthio.net> wrote:
> > On 2010-06-24, ilovesss2004 <yyiillu...(a)gmail.com> wrote:
> >
> > > If I run
> > > 1.0/10**10
> > > python will return 0
> >
> > Python 2.6.4 (r264:75706, Dec 11 2009, 23:02:59)
> > [GCC 3.4.6] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >
> > >>> 1.0/10**10
> > 1e-10
> >
> > What version are you using?
> >
> > > How can I make python return 1e-10?
> >
> > If necessary, cast everything to a float:
> >
> >
> >
> >
> >
> > >>> 1.0/float(10**10)
> > 1e-10
>
> I use python 2.5
> Must change version? Is there any other solution?

Are you sure you're doing the above?

Testing on 2.5:

>>> 1.0/10**10
1e-10

.... but if you leave off the ".0" it'll think you want integer
arithmatic, so return 0.

>>> 1/10**10
0

Tim

From: Etienne Rousee on
Le 24/06/2010 18:33, ilovesss2004 a �crit :

> I use python 2.5
> Must change version? Is there any other solution?

With python 2.6.5, I obtain 1e-10.

--

Etienne

From: Peter Otten on
ilovesss2004 wrote:

> If I run
> 1.0/10**10
> python will return 0
>
> How can I make python return 1e-10?

If you meant 1/10**10, by default this returns an integer in Python 2.x.
With "from __future__ import division" you can opt for the division of
integers to return a float:

>>> 1/10**10
0
>>> from __future__ import division
>>> 1/10**10
1e-10

Python 3.x will return a float by default.

Peter

From: Ian Kelly on
On Thu, Jun 24, 2010 at 10:33 AM, ilovesss2004 <yyiilluuoo(a)gmail.com> wrote:
> I use python 2.5
> Must change version? Is there any other solution?

It works for me:

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.0/10**10
1e-010

Perhaps you're doing integer division by mistake?

>>> 1/10**10
0L

Cheers,
Ian