off topic but please forgive me me and answer

Stefan Behnel stefan_ml at behnel.de
Fri Apr 2 11:11:00 EDT 2010


Patrick Maupin, 02.04.2010 07:25:
> On Apr 1, 11:52 pm, Dennis Lee Bieber wrote:
>> On Thu, 01 Apr 2010 22:44:51 +0200, superpollo
>> declaimed the following in gmane.comp.python.general:
>>
>>> how much is one half times one half?
>>
>> import math
>> print math.exp((math.log(1) - math.log(2))
>>                                   + (math.log(1) - math.log(2)))
>
> That's all well and good, but base 'e' is kind of complicated.  Some
> of us were using base 10, and others took Tim's lead and were using
> base 2:
>
> >>> print math.exp(((math.log(1)/math.log(2) - math.log(2)/math.log(2)) + (math.log(1)/math.log(2) - math.log(2)/math.log(2)))*math.log(2))
> 0.25

The above can be rewritten as

     print('0.25')

which is much faster and also a lot more readable.

Stefan




More information about the Python-list mailing list