basic_m Module

This module contains constants and functions for doing low-level numerics in Fortran. This includes standard real and complex precisions (sp, dp, qp), a "working precision" (wp) that is used as the default precision in GENEUS; some common numerical constants (like pi and the machine epsilon); as well as basic functions for e.g. constructing and deconstructing complex numbers.



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: sp = real32

Single precision

integer, public, parameter :: dp = real64

Double precision

integer, public, parameter :: qp = real128

Quadruple precision

integer, public, parameter :: wp = dp

Working precision

real(kind=wp), public, parameter :: inf = huge(1.0_wp)

Infinity

real(kind=wp), public, parameter :: eps = epsilon(1.0_wp)

Infinitesimal

real(kind=wp), public, parameter :: pi = atan(1.0_wp)*4.0_wp

Circle constant


Functions

public elemental function re(z) result(x)

Returns the real part of a complex number z=x+iy.

Read more…

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in) :: z

Complex number

Return Value real(kind=wp)

Real part

public elemental function im(z) result(y)

Returns the imaginary part of a complex number z=x+iy.

Read more…

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in) :: z

Complex number

Return Value real(kind=wp)

Imaginary part

public elemental function cx(x, y) result(z)

Returns the complex number z=x+iy.

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x

Real part

real(kind=wp), intent(in), optional :: y

Imaginary part

Return Value complex(kind=wp)

Complex number

public elemental function arg(z) result(t)

Returns the complex argument θ of a complex number z=r·exp(iθ).

Read more…

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in) :: z

Complex number

Return Value real(kind=wp)

Complex argument

public pure function unitvector(v) result(r)

If the argument has a finite norm, then it will be rescaled to a unit vector. If that norm is zero, then a zero vector is returned instead.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(3) :: v

Input vector

Return Value real(kind=wp), dimension(3)

Unit vector

public pure function nonzero(v) result(r)

Checks whether or not the argument has a finite norm.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: v

Input vector

Return Value logical

Conclusion