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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Missing complex exponentiation function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          kiranchandramohan
      </td>
    </tr>
</table>

<pre>
    For a complex exponentiation function, Flang currently generates a call to `fc_exp_1` in the pgmath library. This function does not seem to have an implementation in the pgmath runtime. We have to either add an implementation for complex exponentiation using functions from https://en.cppreference.com/w/c/numeric/c or use the exponentiation that works on floats (`mth_i_cexp`) like in classic flang.
Location of pgmath: https://github.com/flang-compiler/flang/tree/master/runtime/libpgmath

An alternative way would be to do custom handling for complex exponentiation inside the file which handles lowering of intrinsic functions (flang/lib/Lower/IntrinsicCall.cpp). Custom handling can be generating an MLIR dialect complex operation, and adding calls to the conversion pass that lowers to libm calls. Handling could also be to extract the parts (complex, imaginary) and then call the non-complex exponentiation function in pgmath.

Simple reproducer
```
  complex :: i
  i = (0.0, 1.0)
  print *, exp(i)
end
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyFVMtu2zAQ_Br5soggy4_EBx3SBEEDJJe2QI8BRa4sNhQpkFSc_H2HlO2mQR-ALFLc18zs0q1Tb82d8yRIumE0_Er8OjrLNmoRtbPUTVamTVHf0J0Rdk9y8h5280Z7tuxF5JDChTEUHRXbqpNPSPK0xJa0pdgzjftBxJ6Mbr3wbyV963U4pyblkMK6SIF5SEl68cIkLOkEaUCxGcvvyfwEkAOX9J3nAASyhgPYKPWH8A48_8JyChrMToAAzbuB-hjHUKyui_oOD9tSjqPnjsFecolMOD3gJ_Gz08Bep50klJkCZ6gfysReRDo4_xwo4TFOxEBFfQWlhtg_6SeJAHwU9Q5aPXNiLI0IQUt4Q_yyqG6L6vrByTmh645qAOYHvHtIMbVHmDn4IpHXhv3pAGv0zFgGEWI-P4qKHXp1TJ1Lzu9rS8LA06I8FD-IN9CZjKI2y68cpiPEpJ2wymRN_y66tkGrWacOsOjQa9nPkZgH4w5QFBnAUdvok7d81yLIdiIBqHg_pACs9yfnG4xk6hnULOnmAy6J-QDo4winExw8Ptx_IaWFYRnPqN2YPeYrgPA0XXMGY0JinQhIZ1_Yh0RrRL_mTmcK2QUIhzmgpM9nCFk5YYI7ysev0QtUzkMu_DwbRxipuB7EXltcoDQfCQkc7fHmIcQ6e_GfW5wGau5q-b6tX_NNIc-jd2qSkHE2YhLnJ3_SWZI0ZBg4fTrXOLlNYKuySkCXadmdrCPaEWG9TqY04PWVPpvZqg_FFqpZqd1qJxZRR8NNsfmU_3iKzS096hBm6f5JczF50_zjOhjzclouQPkH2o1P5J44YLPZXK02i77pttslOPGqbeX6sl3uunqzq5bVdtOt63YrFka0bEJCWNS15QPlFNgD60I3dVXX1baql-v6cr0rW1bdSq3rpbrc7NaqKtYVD0KbMuEond8vfJMhtdM-wGh0iOGXMf0N7C1nQVJ-McXe-eZZe2FlmmsvBod1kUE0mcRPRf__oQ">