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

    <tr>
        <th>Summary</th>
        <td>
            [flang] complex arithmetic (underflow occurred in absolute value calculation)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Test program:
```console
$ cat check.f90
program complex_arithmetic
 implicit none

  integer, parameter :: dp = selected_real_kind(15, 307)
  complex(dp) :: z1, z2, z3
  real(dp) :: abs_z1, abs_z2

 z1 = (1.0_dp, 1.0_dp)
  z2 = (1.0e-300_dp, 1.0e-300_dp)

  ! Divide z1 by z2
  z3 = z1 / z2
  write(*,*) "Result of z1 / z2: ", z3

  ! Calculate absolute values of z1 and z2
  abs_z1 = abs(z1)
  abs_z2 = abs(z2)
  write(*,*) "Absolute value of z1: ", abs_z1
  write(*,*) "Absolute value of z2: ", abs_z2

  ! Check for overflow or underflow in absolute value calculation
  if (abs_z1 == huge(abs_z1)) then
    write(*,*) "Overflow occurred in absolute value calculation of z1"
  endif

  if (abs_z2 == 0.0_dp) then
 write(*,*) "Underflow occurred in absolute value calculation of z2"
 endif

end program complex_arithmetic
```

flang-new vs gfortran (see the result of "Absolute value of z2")
```console
$ flang-new -flang-experimental-exec check.f90
$ ./a.out
 Result of z1 / z2:  (9.999999999999999E+299,0.)
 Absolute value of z1: 1.4142135623730951
 Absolute value of z2:  0.
 Underflow occurred in absolute value calculation of z2
$ gfortran check.f90
$ ./a.out
 Result of z1 / z2:          (9.99999999999999904E+299,0.0000000000000000)
 Absolute value of z1:    1.4142135623730951
 Absolute value of z2: 1.4142135623730950E-300
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVUuP4jgQ_jXmYhHZlfDwIQcGhutKq90zcpwKeNvEyH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