[erlang-questions] Arithmetic expressions [WAS: Re: Binaries problem]

Kostis Sagonas kostis@REDACTED
Wed May 2 23:30:31 CEST 2007

Jim Thompson wrote:
> Kostis Sagonas wrote:
>> Jim Thompson wrote:
>>> Eshell V5.5.2  (abort with ^G)
>>> 1> round(math:pow(2,21))-3.
>>> 2097149
>> Unrelated to the topic, but we had weird cases where the HiPE compiler 
>> was crashing when compiling binaries in R11B-3.  They were all related 
>> to use of an expression that was similar to the one Jim is using:
>>     round(math:pow(2,N)) - K.
>> In examining the problem, we realized that this was a very stupid way of
>> denoting this quantity.  We solved the problem (in R11B-4) by adopting 
>> a much better (and significantly faster) way of writing the same 
>> expression in Erlang:
>>     (2 bsl (N-1)) - K
>> I suspect this "round + math:pow(2)" combination is not so uncommon 
>> after all ... although there is really no reason to use it.
> I am an Erlang newbie, and therefore stupid.   Ignore what I say, or type.

But this is exactly the opposite of my point!

My point was that even very seasoned Erlang programmers instinctively 
write the expression "round + math:pow(2)" instead of that with 'bsl' 
first.  No idea why this is so, but I found it extremely interesting 
that I've run across this expression twice in such a short period of 
time.  I am sure you and us (the HiPE group) are not its only users.


More information about the erlang-questions mailing list