[LLVMdev] Generating Floating point constants

Stéphane Letz letz at grame.fr
Thu Jun 3 12:40:39 PDT 2010


Le 3 juin 2010 à 19:41, Dale Johannesen a écrit :

> On Jun 3, 2010, at 7:05 AMPDT, Stéphane Letz wrote:
>> Le 3 juin 2010 à 16:00, Martin Guy a écrit :
>> 
>>> [off list]
>>> 
>>>> 0.8f get converted in 0x3FE99999A0000000 by LLVM
>>> 
>>> single precision
>>> 
>>>> http://babbage.cs.qc.edu/IEEE-754/Decimal.html  gives:
>>>> 
>>>> 0x3FE999999999999A  instead and this value cannot be read back by "llc"...
>>> 
>>> double precision
> 
> Martin is right.  Floats have only 36 significant bits  (sign + 11 exponent + 24 mantissa) and are stored that way.  (The exponent is in double format for some reason I've forgotten, probably because it was easier somewhere.)  Any resemblance to IEEE-754/Decimal is coincidental.  And no, I don't know of anybody else having trouble with this.  Why can't you connect to the AsmWriter in your code?
> 

Because this seems like a very big dependency constraint to be able to do something as simple as using "floats" in a textual format. I would have been happy to be able to copy a 10 lines function in my own code to do that conversion.

Stéphane Letz



More information about the llvm-dev mailing list