Issue |
122851
|
Summary |
Convert double to ConstantFP
|
Labels |
new issue
|
Assignees |
|
Reporter |
tianboh
|
I want to generate ConstantFP using C++ double. For some reasons, the double is obtained in runtime, and it may not suits “simple constant value”
> /// This returns a ConstantFP, or a vector containing a splat of a ConstantFP,
/// for the specified value in the specified type. This should only be used
/// for simple constant values like 2.0/1.0 etc, that are known-valid both as
/// host double and as the target format.
static Constant *get(Type *Ty, double V);
For example, i have a double 233.33, in runtime, the IEEE 754 representation is 0x406D2A8F60000000, if I print it, it is 233.33000183105469. Check [IEEE 754 calculator](https://weitz.de/ieee/) for fun. I know floating point is not continuous, so some values may not have exact representation in IEEE 754 standard. They are encoded to nearest valid doubles instead.
I want to keep some fractional part, so rounding is not enough. But by sacrificing some precision, can I convert my double to ```ConstantFP```?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs