machar, a FORTRAN90 code which dynamically computes constants that characterize the floating point arithmetic system on a computer, by William Cody.
The constants include the value of the "machine epsilon", the smallest number that can be added to 1 and make a difference. However, it includes many other quantities of interest, including the arithmetic base, the largest and smallest magnitudes, and so on.
Many compilers now do certain kinds of optimization that may cause MACHAR to fail. The most noticeable symptom is that MACHAR may fall into an infinite loop. If you notice this, recompile MACHAR with compiler optimization turned off, or set to the lowest level.
The FORTRAN77 version of these routines was supplied as part of ACM TOMS algorithm 665.
A C version of these routines was supplied as part of ACM TOMS algorithm 722.
In FORTRAN90, there are built-in arithmetic functions that can immediately return the values we are interested in.
If I is an integer value,then:
If X is a single precision real value, or a double precision real value, then:
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
machar is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.
f90_test, FORTRAN90 codes which demonstrate features of the FORTRAN90 language, in particular, epsilon(), huge(), and tiny() which evaluate some machine arithmetic quantities directly.
MACHINE, a FORTRAN90 code which store the appropriate values of machine constants for a given machine.
Original FORTRAN77 version by William Cody. FORTRAN90 version by John Burkardt.