Lahey/Fujitsu Fortran

RANGE Function

Description

The RANGE function returns the decimal range of any numeric data type.

Syntax

RANGE (x)

Arguments

x is an INTENT(IN) scalar or array of any numeric type.

Result

The result is a scalar default INTEGER.

If x is of type INTEGER, the result value is INT(LOG10(HUGE(x))).

If x is of type REAL or COMPLEX, the result value is INT(MIN(LOG10(HUGE(x)),-LOG10(TINY(x)))).

Example

real(kind(1.e0)) :: r10 real(kind(1.d0)) :: r100 real(kind(1.q0)) :: r1000 integer(selected_int_kind(r=1)) :: i1 integer(selected_int_kind(r=4)) :: i4 integer(selected_int_kind(r=7)) :: i7 integer(selected_int_kind(r=12)) :: i12 write(*,*) range(r10) ! writes 37 write(*,*) range(r100) ! writes 307 write(*,*) range(r1000) ! writes 4931 write(*,*) range(i1) ! writes 2 write(*,*) range(i4) ! writes 4 write(*,*) range(i7) ! writes 9 write(*,*) range(i12) ! writes 18