1

I am trying to use a third party automatic differentiation module, ADF95, which uses the expression -sqrt(asin(-1.0_dpr)) to return a Not-a-Number (NaN) in specific cases, where dpr is defined using integer, parameter :: dpr = KIND(1.D0).

Upon attempting to compile a simple test program which uses the mod_adf95 module, with the command gfortran mod_adf95.f90 main.f90 -o test.exe, I get several errors, such as:

mod_adf95.f90:2511:36:

             f%deriv(1:lena) = -sqrt(asin(-1.0_dpr))*sign(1.0_dpr,a%value)
                                    1
Error: Argument of SQRT at (1) has a negative value

Clearly the square root of a negative real is undefined, and so I see why they would try to use this expression to get a NaN. So is there a way to tell the compiler to ignore these errors?

D. de Vries
  • 417
  • 3
  • 12
  • Please use the [tag:fortran] tag for all Fortran questions. Your question is not even Fortran 95 specific to add the version tag. – Vladimir F Героям слава Feb 06 '19 at 16:09
  • Related https://stackoverflow.com/questions/31971836/having-parameter-constant-variable-with-nan-value-in-fortran/31972432 https://stackoverflow.com/questions/45744321/division-by-zero-doesnt-work-with-ieee-arithmetic-in-gfortran-5-4?noredirect=1&lq=1 https://stackoverflow.com/questions/50611059/positive-negative-infinity-constants-in-fortran?noredirect=1&lq=1 – Vladimir F Героям слава Feb 06 '19 at 16:11
  • 2
    It's also worth noting that this use of `sqrt` explicitly violates the requirements placed on a Fortran program by the Fortran standard. – francescalus Feb 06 '19 at 16:15
  • I do not know of any such option for gfortran. It should not be that difficult to fix the code with IEEE intrinsics. – Vladimir F Героям слава Feb 06 '19 at 16:16
  • 1
    Modify the code to the `IEEE_ARITHMETIC` intrinsic module. You can then use `IEEE_VALUE(X,IEEE_QUIET_NAN)` to obtain an NaN. CHeck the standard, I may have the details slightly wrong here. – evets Feb 06 '19 at 16:21
  • 2
    @evets the details are in the linked questions and answers, like https://stackoverflow.com/a/31972432/721644 – Vladimir F Героям слава Feb 06 '19 at 16:24
  • Possible duplicate of [Having parameter (constant) variable with NaN value in FORTRAN](https://stackoverflow.com/questions/31971836/having-parameter-constant-variable-with-nan-value-in-fortran) – Rodrigo Rodrigues Feb 12 '19 at 23:47

0 Answers0