machar, an Octave 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.

The default variable type in MATLAB is similar to a double precision complex variable. When doing real arithmetic, this means that calculations are done in double precision. MATLAB also offers a function called single that can be used to convert a value to a single precision real value. When used to initialize a variable, single effectively "declares" that variable to be a single precision real variable.

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. (This should not be a problem with MATLAB.)


The computer code and data files described and made available on this web page are distributed under the MIT license.


machar is available in a C version and a C++ version and a Fortran77 version and a Fortran90 version and a MATLAB version and an Octave version and a Python version.

Related Data and Programs:


machine, an Octave code which stores the appropriate values of machine constants for a given machine.


Original Fortran77 version by William Cody. This version by John Burkardt.


  1. William Cody,
    Algorithm 665: MACHAR, a subroutine to dynamically determine machine parameters,
    ACM Transactions on Mathematical Software,
    Volume 14, Number 4, December 1988, pages 303-311.
  2. William Cody, William Waite,
    Software Manual for the Elementary Functions,
    Prentice Hall, 1980,
    ISBN: 0138220646,
    LC: QA331.C635.
  3. Morven Gentleman, Scott Marovich,
    More on Algorithms that Reveal Properties of Floating Point Arithmetic Units,
    Communications of the ACM,
    Volume 17, Number 5, May 1974, pages 276-277.
  4. Michael Malcolm,
    Algorithms to Reveal Properties of Floating Point Arithmetic,
    Communications of the ACM,
    Volume 15, Number 11, November 1972, pages 949-951.

Source Code:

Last revised on 29 December 2023.