python log()
Richard Jones
richard at bizarsoftware.com.au
Mon Dec 10 17:55:43 EST 2001
On Tuesday 11 December 2001 9:37 am, Ian wrote:
> Hello I am new to python and am trying to use it to work out a sum
> log(20/7) / log(2)
> which gives result
> 1.0
>
> I am expecting to get 1.51 as a result, and using different langs such as
> perl or php, I get the desired result of 1.51
>
> It seems to me that python only goes to a certain decimal place, not as
> much as the other compilers, can this be altered in anyway?
>
> Ta.
Python does not currently convert the results of division to a non-integer
number....
>>> 20/7
2
>>> 20.0/7
2.8571428571428572
>>> log(20/7) / log(2)
1.0
>>> log(20.0/7) / log(2)
1.5145731728297582
This has been changed in python 2.2, see:
"Changing the Division Operator"
http://python.sourceforge.net/peps/pep-0238.html
Richard
More information about the Python-list
mailing list