0

For the following Fortran code

Program test

  integer, parameter :: dp = selected_real_kind(15, 307)

  real(dp) :: a, b, c, d, e, f, g, h
  real(dp) :: v

  v = 0.02

  a = dsin(v)
  b = dcos(v)
  c = dtan(v)
  d = dcotan(v)

  write (*,*) a, b, c, d

end program

ifort would work. gfortran 9.3.0 leads to

....text+0x65): undefined reference to `dcotan_'
collect2: error: ld returned 1 exit status

gfortran 11.1.0 would work as well.

From https://gcc.gnu.org/onlinedocs/gfortran/COTAN.html, there is a dcotan in gfortran. I tried to search in https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=dcotan, cannot find any information. Is there any further information about dcotan in gfortran?

AlphaF20
  • 583
  • 6
  • 14
  • 3
    Firstly use the generic functions, `sin`, `cos` etc, the type specific ones shouldn't have been used since 1977 (except in a few very unusual situations). Secondly cotan is not a function defined by any standard of Fortran, so don't use it but it is trivial to roll your own using your own favourite trigonometric identity, so that is what I would do. Similarly sec and cosec. – Ian Bush Jan 23 '22 at 09:27
  • 1
    From the documentation you have linked, `cotan` is a "GNU extension", so don't necessarily expect it to behave in the same way as things from the fortran standard. As a general rule you should avoid compiler-specific extensions, as using them immediately makes your code unportable. – veryreverie Jan 23 '22 at 10:38
  • You aren't using `implicit none` in your program. Also consider adding `intrinsic dcotan`. But you certainly need to compile with `-fdec-math` as the linked documentation says. – francescalus Jan 23 '22 at 12:13
  • Thanks! I should have noticed `This function is for compatibility only and should be avoided in favor of standard constructs wherever possible.` in https://gcc.gnu.org/onlinedocs/gfortran/COTAN.html. And, `-fdec-math` works! – AlphaF20 Jan 23 '22 at 17:30

0 Answers0