What is the Floating Point Error on Calculation?

Shanira Perera
2 min readAug 21, 2022

Computer has a standard method to represent the floating points its called IEEE-754 This divide in to 3 parts like this,

Image by Author via www.lucidchart.com

We use 3 steps to convert the numbers to IEEE 754 format.

  • First we need to convert the value to Binary format.
  • Then convert it to scientific notation.
  • Finally, we setup our scientific notation to IEEE 754 format according to Sign bit, Exponent and Mantissa.

Lets take an Example value for understand,

Ex : 9.1 (Number)

Convert Value to Binary Format

we cant convert hole number to binary as a one unit for that we separate integer and decimal part and convert it as separate.

9 → 1001

0.1 → 00011001100110011001100…(no end)

Therefore 9.1 binary number is → 1001.0001100110011001100…

Convert binary number to scientific notation.

first we need to move the decimal point to 3 places for create this number as first point binary number

9.1 → 1.0010001100110011001100… x 2³

2³ → places that we move and this is called exponent value as well.

Convert scientific notation in to IEEE 754 format.

first we look in to the 1st bit, in this format it was the Sign bit and if its a negative value we take it as 1 and if positive we take it as 0.

(-) → 1

(0) →0

And there had another thing called exponent bias which means the maximum amount and hold in the exponent it is 2⁸ → 128 but its going as circle way so that we take the range as (-128 to +127 )

Finally we need to add our exponent value and the bias together.

  • +127 + 3 (power) = 130

Lets convert this 130 to bianry

130 → 10000010

ok lets combined all together and see how the computer identify it

  • our value was positive so first bit / sign bit is 0
  • then exponent 130 → 10000010
  • Finally Mantissa (in scientific notation we start to write with 1 so we do not include the 1 to the mantissa and get other 23 values) → 00100011001100110011001

Finally 9.1 IEEE-754 format is = 0 10000010 00100011001100110011001

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Shanira Perera
Shanira Perera

Written by Shanira Perera

Hello, I’m Shanira, welcome to the world of technology. I am an Associate software engineer at virtusa. So let’s begin!

No responses yet

Write a response