<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/122851>122851</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Convert double to ConstantFP
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tianboh
      </td>
    </tr>
</table>

<pre>
    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```?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVMGO6jgQ_BpzaU3kOISBQw7AgMRtD6O9d-IO8Y6xI7vNDPv1KyfwmHn7UCQUu11dVV0OxmjOjqgR9U7UbwtMPPjQsEHX-mHRen1rTvCJjoE9nMlRQCbYexcZHR__ghSNO8NeqJ1QO9A-tZYKOPoA0V8IAmH0Lgq1Bx7ovg8mgm8ZjSMNxkFIjs2FchE6DYbhgjdwniEmwxHEQYm1FJt9NJfREnT39nBFm-ix-ybkVlQHEOo4P_A-mAiBOAUXAb-xzp18AIQrdexDBsxsshKEOFpk8P3vJ4Tcwjfw3odJUhypM70hPbPJen4u822kYuYSB5-sBu_sDVqCFEn_AfWPKiNY80GgCinUsSwkEHezq8iAgeDD-U_3ckVrNLSeB8D4G_bgIz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