llvm / llvm/llvm-project

[flang] -fhonor-infinities doesn't honor them for -inf**0.5

Open
#166,602 0 comments 0 reactions 0 assignees View on GitHub
flang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Consider the following program:

```fortran
program test_pow_neginf
use, intrinsic :: ieee_arithmetic
real :: neg_inf, result
neg_inf = ieee_value(neg_inf, ieee_negative_inf)
result = neg_inf ** 0.5
print *, "(-inf) ** 0.5 = ", result
end program test_pow_neginf
```

Compilation and run:

```bash
$ flang t.f90 -O2 -fno-fast-math -fhonor-infinities && ./a.out
(-inf) ** 0.5 = NaN
```

It prints `NaN`. I would expect `inf` (as in C). `gfortran` returns `NaN` or `inf` depending on whether `-ffast-math` is used.

Compiler explorer link: https://fortran.godbolt.org/z/zeEzqGbxf

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.