DEV Community

Hafid Saadi
Hafid Saadi

Posted on

The Fundamentals of Floating Point Numbers in Computer Systems

As a programmer, you may have heard the term "floating point number" thrown around, but may not fully understand what it means or how it is represented in a computer system. In this post, we'll explore floating point numbers and how they are represented in computer systems.

Binary

A floating point number is a type of numerical representation that allows us to represent a wide range of values with a fixed number of digits. It is called a "floating point" number because the decimal point can "float" and represent values with a fractional component.

In computer systems, floating point numbers are usually represented in a format known as IEEE 754. This standard defines how floating point numbers should be represented in a computer system in order to ensure consistent behavior across different hardware and software platforms.

The IEEE 754 standard uses a "scientific notation" approach to represent floating point numbers. Essentially, a floating point number is represented as a mantissa and an exponent. The mantissa represents the significant digits of the number, and the exponent determines where the decimal point should be placed.

For example, consider the number 123.45. In scientific
notation, this can be written as 1.2345 x 10^2. In this
representation, the mantissa is 1.2345 and the exponent is 2.
Enter fullscreen mode Exit fullscreen mode

In IEEE 754 representation, the mantissa and exponent are stored as binary numbers. The mantissa is typically stored using a fixed number of bits (such as 23 bits), and the exponent is stored using a larger number of bits (such as 8 bits).

IEEE 754 representation of float

Note that it may be stored using a fixed number of bits (such as 52 bits), and the exponent is stored using a larger number of bits (such as 11 bits).

IEEE 754 representation of float

One important aspect of floating point numbers is that they have a limited precision. This means that they can only represent a certain number of significant digits, and numbers with more digits will be rounded off. This can lead to some loss of accuracy when working with floating point numbers.

In summary, floating point numbers are a type of numerical representation that allows us to represent a wide range of values with a fixed number of digits. They are represented in computer systems using the IEEE 754 standard, which stores the mantissa and exponent as binary numbers. While they offer a lot of flexibility, they do have a limited precision and can introduce some loss of accuracy.

Learn more on cprogramming.c

From Berkeley university

Top comments (0)