PROGRAM arith4 ! ! Author: Br. David Carlson ! ! Date: January 21, 2010 ! ! This program reports on integer and real capabilities for various kinds of ! integers and reals with the current Fortran compiler on the current computer. IMPLICIT NONE INTEGER(KIND=2)::k2 INTEGER(KIND=4)::k4 INTEGER(KIND=8)::k8 INTEGER(KIND=16)::k16 REAL(KIND=4)::x4 REAL(KIND=8)::x8 REAL(KIND=10)::x10 WRITE (*,*) 'Integer-related items:' WRITE (*,*) 'BIT_SIZE(k2) gives number of bits used to represent a kind 2 integer: ', BIT_SIZE(k2) WRITE (*,*) 'BIT_SIZE(k4) gives number of bits used to represent a kind 4 integer: ', BIT_SIZE(k4) WRITE (*,*) 'BIT_SIZE(k8) gives number of bits used to represent a kind 8 integer: ', BIT_SIZE(k8) WRITE (*,*) 'BIT_SIZE(k16) gives number of bits used to represent a kind 16 integer: ', BIT_SIZE(k16) WRITE (*,*) 'DIGITS(k2) gives number of significant bits in a kind 2 integer: ', DIGITS(k2) WRITE (*,*) 'DIGITS(k4) gives number of significant bits in a kind 4 integer: ', DIGITS(k4) WRITE (*,*) 'DIGITS(k8) gives number of significant bits in a kind 8 integer: ', DIGITS(k8) WRITE (*,*) 'DIGITS(k16) gives number of significant bits in a kind 16 integer: ', DIGITS(k16) WRITE (*,*) 'HUGE(k2) gives largest kind 2 integer: ', HUGE(k2) WRITE (*,*) 'HUGE(k4) gives largest kind 4 integer: ', HUGE(k4) WRITE (*,*) 'HUGE(k8) gives largest kind 8 integer: ', HUGE(k8) WRITE (*,*) 'HUGE(k16) gives largest kind 16 integer: ', HUGE(k16) WRITE (*,*) 'RANGE(k2) gives the decimal exponent range for kind 2 integers: ', RANGE(k2) WRITE (*,*) 'RANGE(k4) gives the decimal exponent range for kind 4 integers: ', RANGE(k4) WRITE (*,*) 'RANGE(k8) gives the decimal exponent range for kind 8 integers: ', RANGE(k8) WRITE (*,*) 'RANGE(k16) gives the decimal exponent range for kind 16 integers: ', RANGE(k16) WRITE (*,*) WRITE (*,*) 'Real-related items:' WRITE (*,*) 'DIGITS(x4) gives number of significant bits in the mantissa of a kind 4 real: ', DIGITS(x4) WRITE (*,*) 'DIGITS(x8) gives number of significant bits in the mantissa of a kind 8 real: ', DIGITS(x8) WRITE (*,*) 'DIGITS(x10) gives number of significant bits in the mantissa of a kind 10 real: ', DIGITS(x10) WRITE (*,*) 'EPSILON(x4) gives the machine epsilon (distance between 1.0 and next kind 4 real): ', EPSILON(x4) WRITE (*,*) 'EPSILON(x8) gives the machine epsilon (distance between 1.0 and next kind 8 real): ', EPSILON(x8) WRITE (*,*) 'EPSILON(x10) gives the machine epsilon (distance between 1.0 and next kind 10 real): ', EPSILON(x10) WRITE (*,*) 'MAXEXPONENT(x4) gives the max exponent (on a base of 2) for a kind 4 real: ', MAXEXPONENT(x4) WRITE (*,*) 'MAXEXPONENT(x8) gives the max exponent (on a base of 2) for a kind 8 real: ', MAXEXPONENT(x8) WRITE (*,*) 'MAXEXPONENT(x10) gives the max exponent (on a base of 2) for a kind 10 real: ', MAXEXPONENT(x10) WRITE (*,*) 'MINEXPONENT(x4) gives the min exponent (on a base of 2) for a kind 4 real: ', MINEXPONENT(x4) WRITE (*,*) 'MINEXPONENT(x8) gives the min exponent (on a base of 2) for a kind 8 real: ', MINEXPONENT(x8) WRITE (*,*) 'MINEXPONENT(x10) gives the min exponent (on a base of 2) for a kind 10 real: ', MINEXPONENT(x10) WRITE (*,*) 'PRECISION(x4) gives the number of decimal digits of precision for a kind 4 real: ', PRECISION(x4) WRITE (*,*) 'PRECISION(x8) gives the number of decimal digits of precision for a kind 8 real: ', PRECISION(x8) WRITE (*,*) 'PRECISION(x10) gives the number of decimal digits of precision for a kind 10 real: ', PRECISION(x10) WRITE (*,*) 'HUGE(x4) gives largest kind 4 real: ', HUGE(x4) WRITE (*,*) 'HUGE(x8) gives largest kind 8 real: ', HUGE(x8) WRITE (*,*) 'HUGE(x10) gives largest kind 10 real: ', HUGE(x10) WRITE (*,*) 'RANGE(x4) gives the decimal exponent range for kind 4 reals: ', RANGE(x4) WRITE (*,*) 'RANGE(x8) gives the decimal exponent range for kind 8 reals: ', RANGE(x8) WRITE (*,*) 'RANGE(x10) gives the decimal exponent range for kind 10 reals: ', RANGE(x10) WRITE (*,*) 'SPACING(x4) gives the minimum spacing between kind 4 reals: ', SPACING(x4) WRITE (*,*) 'SPACING(x8) gives the minimum spacing between kind 8 reals: ', SPACING(x8) !WRITE (*,*) 'SPACING(x10) gives the minimum spacing between kind 10 reals: ', SPACING(x10) WRITE (*,*) 'SPACING(x10) would not compile, so it has been commented off' WRITE (*,*) 'TINY(x4) gives the smallest positive kind 4 real: ', TINY(x4) WRITE (*,*) 'TINY(x8) gives the smallest positive kind 8 real: ', TINY(x8) WRITE (*,*) 'TINY(x10) gives the smallest positive kind 10 real: ', TINY(x10) END PROGRAM