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

    <tr>
        <th>Summary</th>
        <td>
            Addressing `-Wimplicit-float-conversion` warning might lead to precision loss
        </td>
    </tr>

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

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

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

<pre>
    Disclaimer: My knowledge about floating-point precision is quite limited and I based most of my interpretations on the linked discussion. I came across this by accident and was wondering if there was something of the short-coming that could be detected by tooling. While looking into this I encountered this apparent issue.

This is based on the discussion in https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28336.

According to that discussion the floating-point result of `48 * (1 / 255)` should be `0.18823529779911041259765625`. But if you simply write that it will lead to a compiler warning.

```cpp
float f = 48 * (1.0 / 255.0);
```
```
warning: implicit conversion loses floating-point precision: 'double' to 'float' [-Wimplicit-float-conversion]
   12 | float f = 48 * (1.0 / 255.0);
```

The obvious fix looks like adding the `f` suffix to the literals.

```cpp
float f = 48 * (1.0f / 255.0f);
```

That fixes the warning but it changes the result to `0.1882353127002716064453125` which is supposedly less precise.

It took me quite a while until I finally came up with a solution which did not produce any warnings as well as the expected result.

```cpp
float f = (float)(48 * (1.0 / 255.0));
```

As there are several ways to suppress (I do not consider it a fix when it changes the result/behavior) this warning seems likely to cause more harm than good so I thought it might be worth raising this issue.

See https://godbolt.org/z/crnKhzsec for all my attempts to mitigate this warning.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVcuO4zgS_Br6krAh0dbDBx-qtmCgsNjTLtDHBUWmLE5RTDVJ2e3--kFSKri7pqfnBRiWRInJiIxgUMVoLx7xJKpnUb1s1JwGCqfeBrypK246MvfTi43aKTtiEPsn-M8d3jzdHJoLgupoTtA7Usn6y3Yi6xNMAbWNljzYCJ9nmxCcHW1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