Sun Studio 12: Fortran Library Reference

1.3 Fortran Math Functions

The following functions and subroutines are part of the Fortran math libraries. They are available to all programs compiled with f95. These routines are non-intrinsics that take a specific data type as an argument and return the same. Non-intrinsics do have to be declared in the routine referencing them.

Many of these routines are "wrappers", Fortran interfaces to routines in the C language library, and as such are non-standard Fortran. They include IEEE recommended support functions, and specialized random number generators. See the Numerical Computation Guide and the man pages libm_single(3F), libm_double(3F), libm_quadruple(3F), for more information about these libraries.

1.3.1 Single-Precision Functions

These subprograms are single-precision math functions and subroutines.

In general, the functions below provide access to single-precision math functions that do not correspond to standard Fortran generic intrinsic functions—data types are determined by the usual data typing rules.

These functions need not be explicitly typed with a REAL statement as long as default typing holds. (Names beginning with “r” are REAL, with “i” are INTEGER.)

For details on these routines, see the C math library man pages (3M). For example, for r_acos(x) see the acos(3M) man page.

Table 1–2 Single-Precision Math Functions

Function Name  

Return Type  

Description  

r_acos( x )

r_acosd( x )

r_acosh( x )

r_acosp( x )

r_acospi( x )

REAL

REAL

REAL

REAL

REAL

arc cosine

--

arc cosh

--

--

r_atan( x )

r_atand( x )

r_atanh( x )

r_atanp( x )

r_atanpi( x )

REAL

REAL

REAL

REAL

REAL

arc tangent

--

arc tanh

--

--

r_asin( x )

r_asind( x )

r_asinh( x )

r_asinp( x )

r_asinpi( x )

REAL

REAL

REAL

REAL

REAL

arc sine

--

arc sinh

--

--

r_atan2( y, x )

r_atan2d( y, x )

r_atan2pi( y, x )

REAL

REAL

REAL

arc tangent

--

--

r_cbrt( x )

r_ceil( x )

r_copysign( x, y )

REAL

REAL

REAL

cube root

ceiling

--

r_cos( x )

r_cosd( x )

r_cosh( x )

r_cosp( x )

r_cospi( x )

REAL

REAL

REAL

REAL

REAL

cosine

--

hyperb cos

--

--

r_erf( x )

r_erfc( x )

REAL

REAL

err function

--

r_expm1( x )

r_floor( x )

r_hypot( x, y )

r_infinity( )

REAL

REAL

REAL

REAL

(e**x)-1

floor

hypotenuse

--

r_j0( x )

r_j1( x )

r_jn(n, x )

REAL

REAL

REAL

Bessel--

--

ir_finite( x )

ir_fp_class( x )

ir_ilogb( x )

ir_irint( x )

ir_isinf( x )

ir_isnan( x )

ir_isnormal( x )

ir_issubnormal( x )

ir_iszero( x )

ir_signbit( x )

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

--

--

--

--

--

--

--

--

--

--

r_addran()

r_addrans( x, p, l, u )

r_lcran()

r_lcrans( x, p, l, u )

r_shufrans(x, p, l, u)

REAL

subroutineREAL

subroutine

subroutine

randomnumbergenerators

r_lgamma( x )

r_logb( x )

r_log1p( x )

r_log2( x )

REAL

REAL

REAL

REAL

log gamma

--

--

--

r_max_normal()

r_max_subnormal()

r_min_normal()

r_min_subnormal()

r_nextafter( x, y )

r_quiet_nan( n )

r_remainder( x, y )

r_rint( x )

r_scalb( x, y )

r_scalbn( x, n )

r_signaling_nan( n )

r_significand( x )

REAL

REAL

REAL

REAL

REAL

REAL

REAL

REAL

REAL

REAL

REAL

REAL

 

r_sin( x )

r_sind( x )

r_sinh( x )

r_sinp( x )

r_sinpi( x )

REAL

REAL

REAL

REAL

REAL

sine

--

hyperb sin

--

--

r_sincos( x, s, c )

r_sincosd( x, s, c )

r_sincosp( x, s, c )

r_sincospi( x, s, c )

subroutine

subroutine

subroutine

subroutine

sine & cosine

--

--

--

r_tan( x )

r_tand( x )

r_tanh( x )

r_tanp( x )

r_tanpi( x )

REAL

REAL

REAL

REAL

REAL

tangent

--

hyperb tan

--

--

r_y0( x )

r_y1( x )

r_yn( n, x )

REAL

REAL

REAL

bessel

--

--

See also: intro(3M) and the Numerical Computation Guide.

1.3.2 Double-Precision Functions

The following subprograms are double-precision math functions and subroutines.

In general, these functions do not correspond to standard Fortran generic intrinsic functions—data types are determined by the usual data typing rules.

These DOUBLE PRECISION functions need to appear in a DOUBLE PRECISION statement.

Refer to the C library man pages for details: the man page for d_acos(x) is acos(3M)

Table 1–3 Double Precision Math Functions

Function Name  

Return Type  

Description  

d_acos( x )

d_acosd( x )

d_acosh( x )

d_acosp( x )

d_acospi( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

arc cosine

--

arc cosh

--

--

d_atan( x )

d_atand( x )

d_atanh( x )

d_atanp( x )

d_atanpi( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

arc tangent

--

arc tanh

--

--

d_asin( x )

d_asind( x )

d_asinh( x )

d_asinp( x )

d_asinpi( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

arc sine

--

arc sinh

--

--

d_atan2( y, x )

d_atan2d( y, x )

d_atan2pi( y, x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

arc tangent

--

--

d_cbrt( x )

d_ceil( x )

d_copysign( x, x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

cube root

ceiling

--

d_cos( x )

d_cosd( x )

d_cosh( x )

d_cosp( x )

d_cospi( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

cosine

--

hyperb cos

--

--

d_erf( x )

d_erfc( x )

DOUBLE PRECISION

DOUBLE PRECISION

error func

--

d_expm1( x )

d_floor( x )

d_hypot( x, y )

d_infinity( )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

(e**x)-1

floor

hypotenuse

--

d_j0( x )

d_j1( x )

d_jn(n, x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

Bessel

--

--

id_finite( x )

id_fp_class( x )

id_ilogb( x )

id_irint( x )

id_isinf( x )

id_isnan( x )

id_isnormal( x )

id_issubnormal( x )

id_iszero( x )

id_signbit( x )

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

 

d_addran()

d_addrans(x, p, l, u)

d_lcran()

d_lcrans(x, p, l, u )

d_shufrans(x, p, l,u)

DOUBLE PRECISION

subroutine

DOUBLE PRECISION

subroutine

subroutine

random number generators

d_lgamma( x )

d_logb( x )

d_log1p( x )

d_log2( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

log gamma

--

--

--

d_max_normal()

d_max_subnormal()

d_min_normal()

d_min_subnormal()

d_nextafter( x, y )

d_quiet_nan( n )

d_remainder( x, y )

d_rint( x )

d_scalb( x, y )

d_scalbn( x, n )

d_signaling_nan( n )

d_significand( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

 

d_sin( x )

d_sind( x )

d_sinh( x )

d_sinp( x )

d_sinpi( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

sine

--

hyper sine

--

--

d_sincos( x, s, c )

d_sincosd( x, s, c )

d_sincosp( x, s, c )

d_sincospi( x, s, c )

subroutine

subroutine

subroutine

subroutine

sine & cosine

--

--

d_tan( x )

d_tand( x )

d_tanh( x )

d_tanp( x )

d_tanpi( x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

tangent

--

hyperb tan

--

--

d_y0( x )

d_y1( x )

d_yn( n, x )

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

bessel

--

--

See also: intro(3M) and the Numerical Computation Guide.

1.3.3 Quad-Precision Functions

These subprograms are quadruple-precision (REAL*16) math functions and subroutines.

In general, these do not correspond to standard generic intrinsic functions; data types are determined by the usual data typing rules.

The quadruple precision functions must appear in a REAL*16 statement

Table 1–4 Quadruple-Precision libm Functions

Function Name  

Return Type  

q_copysign( x, y )

q_fabs( x )

q_fmod( x )

q_infinity( )

REAL*16

REAL*16

REAL*16

REAL*16

iq_finite( x )

iq_fp_class( x )

iq_ilogb( x )

iq_isinf( x )

iq_isnan( x )

iq_isnormal( x )

iq_issubnormal( x )

iq_iszero( x )

iq_signbit( x )

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

q_max_normal()

q_max_subnormal()

q_min_normal()

q_min_subnormal()

q_nextafter( x, y )

q_quiet_nan( n )

q_remainder( x, y )

q_scalbn( x, n )

q_signaling_nan( n )

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

If you need to use any other quadruple-precision libm function, you can call it using $PRAGMA C(fcn) before the call. For details, see the chapter on the C–Fortran interface in the Fortran Programming Guide.