Why do we have sin/dsin/csin/zsin, but not e.g. zsinh or csinh ?

Steve Kargl sgk@troutmask.apl.washington.edu
Sun Sep 20 18:15:00 GMT 2009


On Sun, Sep 20, 2009 at 01:25:39PM -0400, Kaveh R. GHAZI wrote:
> I noticed that gfortran has builtins for sin, dsin, csin and zsin in
> intrinsic.c. But we only have sinh and dsinh for the hyperbolic variant,
> no zsinh or csinh.  The cosh, tanh and tan functions follow a similar
> pattern.
> 
> I'm not sure what all the variations are for, but why the difference?
> Should I fill in the missing bits?
> 

Kaveh,

This is related to fortran's backwards compatibity of its standards.
sin is the generic name while dsin and csin are the specific names.
zsin was a popular extension dating back to the F77 days.  If you 
have the Fortran 2003 standard, you see Section 13.6.  For example,
the following is a valid program

program testsin
  integer, parameter :: sp = kind(1.e0), dp = kind(1.d0)
  real(sp) r
  real(dp) d
  complex(sp) c
  complex(dp) z
  r = 1.e0
  d = r
  c = r
  z = r
  ! Print with the specific names where zsin is an extension.
  print *, sin(r), dsin(d), csin(c), zsin(z)
  ! Print with the generic name
  print *, sin(r), sin(r), sin(c), sin(z)
end program testsin
  
The following lines are invalid and gfortran should report an error.

  print *, dsin(r)  ! type of arg is wrong.
  print *, csin(z)  ! ditto
  print *, zsin(c)  ! ditto

Now, moving to [d]sinh, back in F77 only the real versions of these
intrinsics were included in the standard.  When F90 (or later ?) was
standardized, sinh was declared a generic, and the arguments were
permitted to be complex.  J3, the standardization committee, probably
recognized that adding csinh (and maybe zsinh) could cause runtime
libraries to substantially increase in size, and more importantly
the specific names would be redundant.  Adding csinh also could 
suddenly conflict with a csinh that was provided by a program.

It is now considered good practice by proficient Fortran programmers
to use generic names in preference to specific names.  If you need to
change an algorithm from one precision to another, the use of generic
names avoids having to audit the code to make changes.

HTH

-- 
Steve



More information about the Fortran mailing list