inlining math:pi()

James Hague <>
Fri Dec 11 16:31:19 CET 2009


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


More information about the erlang-questions mailing list