Functions to analyze numbers in Fortran programs. Some of these functions (is_nan and is_inf) are now available in the intrinsics module IEEE_ARITHMETIC and are provided here only for compatibility with some old programs that use them.
Counts the number of digits of an integer, including the - sign in case it is a negative value.
n = count_digits_integer(i)
Where:
i
: Integer number whose digits are to be countedIt returns the number of digits of the input number, including the - sign in case it is a negative value.
The following program prints the number of digits of some integer numbers:
PROGRAM count_digits_integerExample
USE FU_Numbers, ONLY: count_digits_integer
IMPLICIT NONE
WRITE(*,*) count_digits_integer(1234)
WRITE(*,*) count_digits_integer(-1234)
END PROGRAM count_digits_integerExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i8), | intent(in) | :: | i |
Integer number whose digits are to be counted. |
The number of digits of the input number.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i16), | intent(in) | :: | i |
Integer number whose digits are to be counted. |
The number of digits of the input number.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(in) | :: | i |
Integer number whose digits are to be counted. |
The number of digits of the input number.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(in) | :: | i |
Integer number whose digits are to be counted. |
The number of digits of the input number.
Determines if the value of the input variable is NaN.
n = is_nan(f)
Where:
f
: Real number to check if it is NaN.It returns True if the number is NaN and False otherwise.
The following program checks some real numbers to see if they are NaN:
PROGRAM is_nanExample
USE FU_Numbers, ONLY: is_nan
IMPLICIT NONE
REAL :: f
WRITE(*,*) is_nan(5.)
f = 0.
WRITE(*,*) is_nan(1/f)
WRITE(*,*) is_nan(f/f)
END PROGRAM is_nanExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | val |
Value to analize. It can have any rank and dimension |
True if the variable is NaN. False otherwise. It will have the same rank and dimension as the input value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | val |
Value to analize. It can have any rank and dimension |
True if the variable is NaN. False otherwise. It will have the same rank and dimension as the input value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=qp), | intent(in) | :: | val |
Value to analize. It can have any rank and dimension |
True if the variable is NaN. False otherwise. It will have the same rank and dimension as the input value.
Determines if the value of the input variable is Infinity.
n = is_inf(f)
Where:
f
: Real number to check if it is Infinity.It returns True if the number is Infinity and False otherwise.
The following program checks some real numbers to see if they are Infinity:
PROGRAM is_infExample
USE FU_Numbers, ONLY: is_inf
IMPLICIT NONE
REAL :: f
WRITE(*,*) is_inf(5.)
f = 0.
WRITE(*,*) is_inf(1./f)
WRITE(*,*) is_inf(f/f)
END PROGRAM is_infExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | val |
Value to analize. It can have any rank and dimension |
True if the variable is Inf. False otherwise. It will have the same rank and dimension as the input value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | val |
Value to analize. It can have any rank and dimension |
True if the variable is Inf. False otherwise. It will have the same rank and dimension as the input value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=qp), | intent(in) | :: | val |
Value to analize. It can have any rank and dimension |
True if the variable is Inf. False otherwise. It will have the same rank and dimension as the input value.
Tests two real numberes for equality using a tolerance if provided by the user, or selecting a tolerance automatically otherwise.
n = eq(f1, f2, eps)
Where:
f1
: First real number to compare for equality.f2
: Second real to compare for equality.eps
: User selected tolerance for the comparison. If not provided it
will be selected automatically.It returns True both numbers are equal according to the selected tolerance and False otherwise
The following program tests if two real numbers are equal:
PROGRAM eqExample
USE FU_Numbers, ONLY: eq
IMPLICIT NONE
WRITE(*,*) eq(5., 5.00001, 0.000000001)
WRITE(*,*) eq(5., 5.00001, 0.001)
WRITE(*,*) eq(5., 5.00001)
END PROGRAM eqExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | x1 |
First real value to compare for equality. |
||
real(kind=sp), | intent(in) | :: | x2 |
Second real value to compare for equality. |
||
real(kind=sp), | intent(in), | optional | :: | eps |
User selected tolerance for the comparison. If not provided it will be selected automatically. |
True if both numbers are equal according to the selected tolerance. False otherwise.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | x1 |
First real value to compare for equality. |
||
real(kind=dp), | intent(in) | :: | x2 |
Second real value to compare for equality. |
||
real(kind=dp), | intent(in), | optional | :: | eps |
User selected tolerance for the comparison. If not provided it will be selected automatically. |
True if both numbers are equal according to the selected tolerance. False otherwise.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=qp), | intent(in) | :: | x1 |
First real value to compare for equality. |
||
real(kind=qp), | intent(in) | :: | x2 |
Second real value to compare for equality. |
||
real(kind=qp), | intent(in), | optional | :: | eps |
User selected tolerance for the comparison. If not provided it will be selected automatically. |
True if both numbers are equal according to the selected tolerance. False otherwise.
Tests two real numberes for inequality using a tolerance if provided by the user, or selecting a tolerance automatically otherwise.
n = ne(f1, f2, eps)
Where:
f1
: First real number to compare for inequality.f2
: Second real to compare for inequality.eps
: User selected tolerance for the comparison. If not provided it
will be selected automatically.It returns True both numbers are not equal according to the selected tolerance and False otherwise
The following program tests if two real numbers are not equal:
PROGRAM neExample
USE FU_Numbers, ONLY: ne
IMPLICIT NONE
WRITE(*,*) ne(5., 5.00001, 0.000000001)
WRITE(*,*) ne(5., 5.00001, 0.001)
WRITE(*,*) ne(5., 5.00001)
END PROGRAM neExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | x1 |
First real value to compare for inequality. |
||
real(kind=sp), | intent(in) | :: | x2 |
Second real value to compare for inequality. |
||
real(kind=sp), | intent(in), | optional | :: | eps |
User selected tolerance for the comparison. If not provided it will be selected automatically. |
True if the numbers are not equal according to the selected tolerance. False otherwise.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | x1 |
First real value to compare for inequality. |
||
real(kind=dp), | intent(in) | :: | x2 |
Second real value to compare for inequality. |
||
real(kind=dp), | intent(in), | optional | :: | eps |
User selected tolerance for the comparison. If not provided it will be selected automatically. |
True if the numbers are not equal according to the selected tolerance. False otherwise.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=qp), | intent(in) | :: | x1 |
First real value to compare for inequality. |
||
real(kind=qp), | intent(in) | :: | x2 |
Second real value to compare for inequality. |
||
real(kind=qp), | intent(in), | optional | :: | eps |
User selected tolerance for the comparison. If not provided it will be selected automatically. |
True if the numbers are not equal according to the selected tolerance. False otherwise.