[erlang-questions] inlining math:pi()

Michael Truog <>
Sat Dec 12 06:44:15 CET 2009


Yes, you would want these links to solutions:
http://forum.trapexit.org/viewtopic.php?p=20260
(patch here: 
http://dukesoferl.blogspot.com/2009/09/removing-warnings-from-ctexpand.html)
(other usage here:
http://dukesoferl.blogspot.com/2009/08/metaprogramming-with-ctexpand.html)

Zoltan Lajos Kis wrote:
> 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
>>>
>>>
>>>     
>>
>>
>>   
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>



More information about the erlang-questions mailing list