[erlang-questions] inlining math:pi()

Zoltan Lajos Kis <>
Fri Dec 11 20:54:18 CET 2009


Or a parse transform? :)

Tony Arcieri wrote:
> Use a macro?
>
> On Fri, Dec 11, 2009 at 8:31 AM, James Hague <> wrote:
>
>   
>> I tend to use math:pi/0 a lot in code I'm writing. The math module is
>> essentially all BIFs, except math:pi/0, which is simple:
>>
>>   pi() -> 3.1415926535897932.
>>
>> If this constant could simply be inlined at compile time, it would
>> improve the generated code quite a bit. Two examples:
>>
>> 1. "math:pi() * 2" could be a constant, instead of a call to an
>> external function and causing a float to be heap allocated.
>> 2. "{100.0, 50.0, math:pi()}" could be a constant term, instead of
>> having to be constructed at runtime.
>>
>> Perhaps there's a more general need for what are essentially "constant
>> BIFs"?
>>
>> James
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>>
>>     
>
>
>   



More information about the erlang-questions mailing list