expm1 for GNU gfortran [closed]

折月煮酒 提交于 2020-03-26 04:50:31

问题


Is there any way to call a fast implementation of expm1 from GNU Fortran? Ideally, it would be great to have a function to calculate (exp(x)-1)/x directly to avoid extra check for zero argument. Elemental version of expm1 would be especially helpful.


回答1:


This is how it's called from libm:

  use, intrinsic :: iso_c_binding, only: c_double

  implicit none

  interface
     real(c_double) function expm1(x) bind(c, name='expm1')
       import c_double
       real(c_double), intent(in), value :: x
     end function expm1
  end interface

  print*, expm1(3.4d0)

end program

If the glibc source code for the function does not look too discouraging then you might wish to translate it into Fortran in order to make it elemental (if by elemental you meant the Fortran keyword).



来源:https://stackoverflow.com/questions/30393928/expm1-for-gnu-gfortran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!