-3

Please explain this paragraph:

Floating point numbers in C use IEEE 754 encoding.

This type of encoding uses a sign, a significant, and an exponent.

Because of this encoding, many numbers will have small changes to allow them to be stored.

Also, the number of significant digits can change slightly since it is a binary representation, not a decimal one.

Single precision (float) gives you 23 bits of significant, 8 bits of exponent, and 1 sign bit.

Double precision (double) gives you 52 bits of significant, 11 bits of exponent, and 1 sign bit.

I started coding in "C" recently i learned all the data structures how programs work and all.But when i saw this paragraph i didn't understand a word.

What is significant,exponent,bits.?

How does a variable,float,double store the values,how much space is required and where are they stored.

Community
  • 1
  • 1
Vishnu AJ
  • 11
  • 2
  • 4
  • 1
    https://en.wikipedia.org/wiki/IEEE_754 – Robby Cornelissen Jan 26 '19 at 04:51
  • In memory you have *sign-bit* (`0/1`) 1-bit, *normalized exponent* (`01010101`) 8-bits, and finally the *mantissa* (or significand) (`01010101010101010101010`) 23-bits that would make up the *single-precision floating point number* in memory (total 32-bits) in IEEE-754 format. – David C. Rankin Jan 26 '19 at 04:58
  • You may find [Obtaining bit representation of a float in C](https://stackoverflow.com/questions/44609743/obtaining-bit-representation-of-a-float-in-c/44611722?r=SearchResults&s=9|44.5751#44611722) helpful. – David C. Rankin Jan 26 '19 at 05:03
  • @DavidC.Rankin Thank you very much for detailed explanation – Vishnu AJ Jan 26 '19 at 05:08
  • The correct term for the significant bits in a floating point number is *significand*, with a *d*, not *significant*. – Caleb Jan 26 '19 at 05:10
  • @Caleb My bad thanks for correcting. – Vishnu AJ Jan 26 '19 at 05:13

1 Answers1

0

A bit is an "on/off" switch, encoded as 0 or 1. You can also think of it as a boolean, True or False.

The sign bit tells you if the float is positive or negitive.

The significant, also known as the Mantissa, gives you negative powers of two. For a float, you have 23 bits, so you can represent anything from 2^-23 up to 1-2^-23.

The exponent also gives you powers of 2 ranging from (2^-126,2^127).

Put everything together to get your float: (sign)(1+significant)2^(exponent)

Not all numbers can be exactly represented with powers of 2. Hence your machine approximates numbers like 0.1.

floats require 32 bits while doubles require 64 bits.

Below is a concise article on IEEE floating points which should make things clearer: https://www.doc.ic.ac.uk/~eedwards/compsys/float/