Issue 118936
Summary [clang++][precision] Cannot use float sqrt with cmath
Labels clang
Assignees
Reporter whokeke
    hey guys, I found a confusing case, can anyone explain it?

Case 1 with camth :
```c++
#include <cmath>
float test(float a)
{
    return a + sqrt(a);
}
```

With the command  `clang++ -O3 -ffast-math -S`, we get 

```asm
test(float):
        fcvt    d0, s0
        fsqrt   d1, d0
 fadd    d0, d1, d0
        fcvt    s0, d0
        ret
```


But Case 2 with math.h

```c++
#include <math.h>
float test(float a)
{
 return a + sqrt(a);
}
```

With the same command  `clang++ -O3 -ffast-math -S`, we get 

```asm
test(float):
        fsqrt   s1, s0
 fadd    s0, s1, s0
        ret
```

I'm not familiar with the difference between math.h and cmath. Can anyone figure me out?

And can we just use float sqrt even with cmath ?


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to