rat Module


ISDIGIT

Determines whether the input character is a digit (0-9).



ISPM

Determines whether the input character is a + or - sign.



ISHEX

Determines whether the input character is a valid hexadecimal digit



ISREAL

Determines whether the input string is a number. If it is, it will also return its value.

In decimal mode, the input string is a number if it satisfies all of these criteria:

 1.  The first non-blank character is a digit, +, -, or decimal point (.).
 2.  It contains, at most, one decimal point.
 3.  It contains, at most, one occurrence of E.
 4.  Any decimal point occurs before any E.
 5.  The E may be followed by an optional + or -.
 6.  A letter E must be followed by at least one digit (after the optional + or -).
 7.  + or - may only be the first non-blank character, or the character immediately following E.
 8.  It contains no other characters besides: digits, +, -, decimal point (.), and E.

If not in decimal mode, the input string is a number if it satisfies these criteria:

 1.  BIN:  digits 0 and 1 only
 2.  OCT:  digits 0-7 only
 3.  HEX:  digits 0-9 and A-F only

Uses functions: ISDIGIT, ISPM, ISHEX



ISCOMPLEX

Determines whether the input string is a complex number. If it is, it will also return its value. A complex number consists of two real numbers separated by a comma (no space). For example: 2.0,5.0E2

In decimal mode, the input string is a number if it satisfies all of these criteria:

 1.  The first non-blank character is a digit, +, -, or decimal point (.).
 2.  It contains, at most, one decimal point.
 3.  It contains, at most, one occurrence of E.
 4.  Any decimal point occurs before any E.
 5.  The E may be followed by an optional + or -.
 6.  A letter E must be followed by at least one digit (after the optional + or -).
 7.  + or - may only be the first non-blank character, or the character immediately following E.
 8.  It contains no other characters besides: digits, +, -, decimal point (.), and E.

If not in decimal mode, the input string is a number if it satisfies these criteria:

 1.  BIN:  digits 0 and 1 only
 2.  OCT:  digits 0-7 only
 3.  HEX:  digits 0-9 and A-F only

Uses functions: ISDIGIT, ISPM, ISHEX



ISRATIONAL

Determines whether the input string is a rational number. If it is, it will also return its value. A rational number consists of two integers separated by a slash (no space). For example: 2/5

In decimal mode, the input string is a number if it satisfies all of these criteria:

 1.  The first non-blank character is a digit, +, or -.
 2.  It contains no other characters besides: digits, +, and -.

If not in decimal mode, the input string is a number if it satisfies these criteria:

 1.  BIN:  digits 0 and 1 only
 2.  OCT:  digits 0-7 only
 3.  HEX:  digits 0-9 and A-F only

Uses functions: ISDIGIT, ISPM, ISHEX



SWITCH_RAT_TO_REAL



ISFRAC

Returns .TRUE. if X has a fractional part (i.e. if X is not an integer)



ISINT

Returns .TRUE. if X has no fractional part (i.e. if X is an integer)



FRAC_TO_MIXED

Convert a fraction from improper format to mixed format.



MATHEMATICAL FUNCTIONS



GCD

Greatest common divisor. Find the greatest common divisor of two integers using Euclid's algorithm.



LCM

Least common multiple. Find the least common multiple of two integers.



RATNORM

Normalize a rational number Check for a denominator or numerator of 0; make the denominator positive; and reduce the fraction.



RADD

Add two rational numbers.



RSUB

Subtract two rational numbers.



RMUL

Multiply two rational numbers.



RDIV

Multiply two rational numbers.



DEC_TO_FRAC

Converts a decimal number to a fraction. Algorithm from "An Atlas of Functions" by Spanier and Oldham, Springer-Verlag, 1987, pp. 665-667.



Uses

  • module~~rat~~UsesGraph module~rat rat iso_fortran_env iso_fortran_env module~rat->iso_fortran_env assert assert module~rat->assert

Used by

  • module~~rat~~UsedByGraph module~rat rat proc~rlinreg RLINREG proc~rlinreg->module~rat module~hyper hyper module~hyper->module~rat proc~rbeta RBETA proc~rbeta->module~rat module~funcs funcs module~funcs->module~rat module~funcs->module~hyper program~rpn RPN program~rpn->module~funcs module~stackops stackops program~rpn->module~stackops module~evals evals program~rpn->module~evals proc~cgamma CGAMMA proc~cgamma->module~hyper module~stackops->module~funcs module~evals->module~funcs module~evals->module~stackops

Contents


Functions

public elemental function ISDIGIT(CH)

Arguments

Type IntentOptional AttributesName
character, intent(in) :: CH

Return Value logical

public elemental function ISPM(CH)

Arguments

Type IntentOptional AttributesName
character, intent(in) :: CH

Return Value logical

public elemental function ISHEX(CH)

Arguments

Type IntentOptional AttributesName
character, intent(in) :: CH

Return Value logical

public function ISREAL(STR, X) result(NUM_FLAG)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: STR
real(kind=wp), intent(out) :: X

Return Value logical

public function ISCOMPLEX(STR, X) result(NUM_FLAG)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: STR
complex(kind=wp), intent(out) :: X

Return Value logical

public function ISRATIONAL(STR, NUM, DEN) result(NUM_FLAG)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: STR
integer, intent(out) :: NUM
integer, intent(out) :: DEN

Return Value logical

public elemental function ISFRAC(X) result(Y)

Arguments

Type IntentOptional AttributesName
real(kind=wp), intent(in) :: X

Return Value logical

public elemental function ISINT(X)

Arguments

Type IntentOptional AttributesName
real(kind=wp), intent(in) :: X

Return Value logical

public elemental function GCD(A, B)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: A
integer, intent(in) :: B

Return Value integer

public elemental function LCM(A, B)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: A
integer, intent(in) :: B

Return Value integer


Subroutines

public subroutine SWITCH_RAT_TO_REAL()

Arguments

None

public elemental subroutine FRAC_TO_MIXED(AN, AD, A1, A2, A3)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: AN
integer, intent(in) :: AD
integer, intent(out) :: A1
integer, intent(out) :: A2
integer, intent(out) :: A3

public elemental subroutine RATNORM(NUM, DEN)

Arguments

Type IntentOptional AttributesName
integer, intent(inout) :: NUM
integer, intent(inout) :: DEN

public elemental subroutine RADD(N1, D1, N2, D2, NR, DR)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: N1
integer, intent(in) :: D1
integer, intent(in) :: N2
integer, intent(in) :: D2
integer, intent(out) :: NR
integer, intent(out) :: DR

public elemental subroutine RSUB(N1, D1, N2, D2, NR, DR)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: N1
integer, intent(in) :: D1
integer, intent(in) :: N2
integer, intent(in) :: D2
integer, intent(out) :: NR
integer, intent(out) :: DR

public elemental subroutine RMUL(N1, D1, N2, D2, NR, DR)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: N1
integer, intent(in) :: D1
integer, intent(in) :: N2
integer, intent(in) :: D2
integer, intent(out) :: NR
integer, intent(out) :: DR

public elemental subroutine RDIV(N1, D1, N2, D2, NR, DR)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: N1
integer, intent(in) :: D1
integer, intent(in) :: N2
integer, intent(in) :: D2
integer, intent(out) :: NR
integer, intent(out) :: DR

public subroutine DEC_TO_FRAC(X, NUM, DEN, TOL)

Arguments

Type IntentOptional AttributesName
real(kind=wp), intent(in) :: X
integer, intent(out) :: NUM
integer, intent(out) :: DEN
real(kind=wp), intent(in), optional :: TOL