Issue 91224
Summary When combined with Arm, floating point calculation results may be incorrect.
Labels new issue
Assignees
Reporter SakiTakamachi
    Hi, I'm from php-src.

The following code:
```
// double.c
int main(void)
{
    int i = 3;
 double v = 0.03;
    double v2 = 0.01;

    double ret = v - (i * v2);

    return 0;
}
```

compile:
```
clang -o double -g double.c
```

debug:
```
# gdb ./double

....

(gdb) b main
Breakpoint 1 at 0x724: file double.c, line 4.
(gdb) run

....

Breakpoint 1, main () at double.c:4
4           int i = 3;
(gdb) n
5           double v = 0.03;
(gdb) 
6           double v2 = 0.01;
(gdb) 
8 double ret = v - (i * v2);
(gdb) 
10          return 0;
(gdb) p ret
$1 = -1.7347234759768071e-18
(gdb) p v
$2 = 0.029999999999999999
(gdb) p v2
$3 = 0.01
(gdb) p i
$4 = 3
(gdb) p i * v2
$5 = 0.029999999999999999
(gdb) p v - (i * v2)
$6 = 0
```

It is known that this phenomenon only occurs when using clang as the compiler and in an Arm environment.
(Sorry if the repository for the issue report is not appropriate)

version:
```
# clang -v
Ubuntu clang version 14.0.0-1ubuntu1.1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/11
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
```

Regards
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to