问题
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