<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/128501>128501</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
A problem about the precision of float variable printed by lldb.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
IOVOVHS
</td>
</tr>
</table>
<pre>
func0 is a function template, and the parameter types passed in are all float.
There is a problem with the precision of the result output by variable var4.
The result printed by lldb is 2030314.63, and the correct value should be 2030314.625, which is the value of var4 in memory.This doesn't look like rounding is the cause.
```
(lldb) b func0
Breakpoint 1: where = test_case4`double func0<float, float>(float, float) + 20 at test_case4.cpp:44:12, address = 0x00000001000034d8
(lldb) r
...
(lldb)
Process 66813 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x0000000100003508 test_case4`double func0<float, float>(p_0=100015.5, p_1=3.1400001) at test_case4.cpp:47:15
44 double var1 = 10.5, var2 = 20.3;
45
46 double var3 = var1 + var2;
-> 47 T1 var4 = p_0 * var2;
(lldb)
Process 66813 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x0000000100003520 test_case4`double func0<float, float>(p_0=100015.5, p_1=3.1400001) at test_case4.cpp:48:15
45
46 double var3 = var1 + var2;
47 T1 var4 = p_0 * var2;
-> 48 std::cout << std::fixed << std::setprecision(10) << var4 << std::endl;
49 var2 = var1 * var3;
50 var3 = var1 * var2 + var3;
51 var1 = var2 * var3 + var1;
(lldb) p var4
(float) 2030314.63
(lldb) n
2030314.6250000000
(lldb) p p_0 * var2
(double) 2030314.6500000001
```
So is this a bug or normal precision error?
clang++ test_case4.cpp -o test_case4 -g
clang++ --version
Homebrew clang version 19.1.6
Target: arm64-apple-darwin24.1.0
lldb : 19.1.6
[test_case4.zip](https://github.com/user-attachments/files/18941575/test_case4.zip)
</pre>
<img width="1" height="1" alt="" src="http://email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