[erlang-questions] constant floating point values

Tony Rogvall tony@REDACTED
Mon Oct 25 09:25:16 CEST 2010

You have to look a bit harder ;-)

The beam loader is doing a lot of work under the hood.

Have a look in emulator/<machine>/opt/smp/beam_opcodes.c

This file is generated by emulator/utils/beam_makeops  (perl script) using
the file emulator/beam/ops.tab as input.

The beam_opcodes.c contains load scripts (transforms) that are emulated by
emulator/beam/beam_load.c during the beam file loading.

From what I understand most constants are today associated with the module
in a constant pool. And operations that use them are transformed during
load time.


On 25 okt 2010, at 02.12, James Hague wrote:

> Let's say I call an external function like this:
>   my_module:add(1.0, 2.0)
> I think what happens right now--from looking at the BEAM code--is that 1.0
> is created on the heap (12 bytes in the 32-bit emulator) and 2.0 is created
> on the heap (another 12 bytes). Then pointers to those two floats are passed
> as parameters to the external function.
> What's the technical reason that BEAM doesn't support constant floats, the
> same way as constant tuples and lists?
> (Note that in expressions where floating point math can be determined at
> compile time, such as "A * 2.5", then the value 2.5 is treated as a constant
> value and loaded directly into a virtual floating point register. Nice!)

"Have run Make so many times I dunno what's installed anymore"

More information about the erlang-questions mailing list