use python as a calculator

T

Tim Harig

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.
What version are you using?
How can I make python return 1e-10?

If necessary, cast everything to a float:
 
D

D'Arcy J.M. Cain

If I run
1.0/10**10
python will return 0

How can I make python return 1e-10?

What version of Python are you using?

Python 2.6.4 (r264:75706, Jan 28 2010, 11:26:00)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd7
Type "help", "copyright", "credits" or "license" for more information.1e-10
 
I

ilovesss2004

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.
1e-10

What version are you using?
How can I make python return 1e-10?

If necessary, cast everything to a float:




1e-10

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

Tim Wintle

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:
1e-10

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

Tim
 
P

Peter Otten

ilovesss2004 said:
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:
1e-10

Python 3.x will return a float by default.

Peter
 
I

Ian Kelly

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.1e-010

Perhaps you're doing integer division by mistake?
0L

Cheers,
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top