[LLVMdev] Floating point constants (bug?)

Ben Chambers bjchambers at gmail.com
Sun Jul 15 14:48:59 PDT 2007


>From the language guide:

"The one non-intuitive notation for constants is the optional
hexadecimal form of floating point constants. For example, the form
'double 0x432ff973cafa8000' is equivalent to (but harder to read than)
'double 4.5e+15'. The only time hexadecimal floating point constants
are required (and the only time that they are generated by the
disassembler) is when a floating point constant must be emitted but it
cannot be represented as a decimal floating point number. For example,
NaN's, infinities, and other special values are represented in their
IEEE hexadecimal format so that assembly and disassembly do not cause
any bits to change in the constants."

When I compile the following simple program with llvm-gcc -O0 -c
--emit-llvm, run it through opt --raiseallocs --lowerconstexps and
llvm-dis, I get a floating point number in hexadecimal that is not one
of the above mentioned special forms.

#include <stdlib.h>
#include <stdio.h>

int main() {
   float f = 5.66;
   return (int)(f + 1.33);
}

It will emit:

...
  store float 0x4016A3D700000000, float* %f
...

Which is correct, but is a pain to have to parse.  Ideally, floating
point would be printed like it says in the language guide, only using
the hexadecimal representation when decimal representation is
impossible.  In this case, however, 5.66e+00 seems pretty reasonable
(and easier to write down/read).  Is this a bug?  Am I running things
wrong to get these printed out in decimal?  I don't think I am because
the 1.33 for the addition is printed out correctly.

Thanks,
Ben Chambers



More information about the llvm-dev mailing list