Skip to content
Search

IEEE floating point

lastmod 2015-05-13created 2015-05-132 edits

IEEE 754 is the most widely used standard for representing floating-point numbers in computers, developed by the Institute of Electrical and Electronics Engineers (IEEE). It defines how to represent numbers such as ±0 and symbols such as infinity and NaN, as well as operations on these numbers. The latest version, IEEE 754-2008, mostly includes IEEE 754-1985 and IEEE 754-1997.

IEEE 754 defines formats for 32-bit single-precision, 64-bit double-precision, extended single-precision of 43 bits or more (rarely used), and extended double-precision of 79 bits or more (usually implemented as 80 bits). Of these, 32-bit single-precision must be implemented, and the other formats are optional. Many programming languages are defined to follow the IEEE standard. For example, in C, float corresponds to single-precision and double to double-precision.

Definitions

The IEEE 754 floating-point standard defines the following.

  • Arithmetic formats: sets of binary and decimal floating-point data consisting of finite numbers (including 0), infinities, and NaN (Not a number) values
  • Interchange formats: encodings that can be used to convert floating-point data efficiently and compactly
  • Rounding rules: properties for rounding during arithmetic and conversion
  • Operations: methods for arithmetic and for handling arithmetic formats
  • Exception handling: indications of exceptional conditions (division by zero, overflow, etc.)

Beyond these, IEEE 754 also includes more complex exception handling, additional operations (trigonometric functions, etc.), expression evaluation, and various methods for achieving producible results.

compare floating point

#include <math.h>

int CompareDoubleAbsoulte(double x, double y, double absTolerance = (1.0e-8))
{
    double diff = x - y;
    if (fabs(diff) <= absTolerance)
        return 0;

    return (diff > 0) ? 1 : -1;
}

Favorite site