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

Kostis Sagonas kostis@REDACTED
Wed May 2 22:52:19 CEST 2007


Jim Thompson wrote:
> Francesco Pierfederici wrote:
>  > > Hi,
>  > >
>  > > I have encountered a problem with handling binaries and I do not know
>  > > what the cause might be. In a nutshell, I seem to be unable to
>  > > assemble binaries larger than 2097149 bytes:
>  > >
> 
> Per Gustafsson wrote:
> 
>> I think that the problem you are running in to is that you are creating 
>> an integer that is too big for the erlang runtime system. I'm not sure 
>> exactly where this limit is but it should be in the order of what you 
>> are creating.
> 
> jim@REDACTED:~$ erl
> Erlang (BEAM) emulator version 5.5.2 [source] [async-threads:0] 
> [kernel-poll:false]
> 
> 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.

Kostis



More information about the erlang-questions mailing list