Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Next answer with a bit of theory.</p> <p><em><strong>Explanation below does not explain IEEE Floating Point standard only general ideas concerning representation of floating point numbers</em></strong></p> <p>Every float number is represented as a fractional part multiplied by an exponent multiplied by a sign. Additionally there is so called bias for exponent, which will be explained bellow.</p> <p>So we have</p> <ol> <li>Sign bit</li> <li>Fractional part digits</li> <li>Exponent part digits</li> </ol> <p><strong>Example for base 2 with 8 bit fraction and 8 bit exponent</strong></p> <p>Bits in fraction part tell us which summands (numbers to be added) from sequence below are to be included in represented number value</p> <p>2^-1 + 2^-2 + 2^-3 + 2^-4 + 2^-5 + 2^-6 + 2^-7 + 2^-8</p> <p>So if you have say 01101101 in fractional part it gives</p> <p>0*2^-1 + 1*2^-2 + 1*2^-3 + 0*2^-4 + 1*2^-5 + 1*2^-6 + 0*2^-7 + 1*2^-8 = 0.42578125</p> <p>Now non-zero numbers that are representable that way fall between 2 ** -8 = 0.00390625 and 1 - 2**-8 = 0.99609375</p> <p>Here the exponent part comes in. Exponent allows us to represent very big numbers by multiplying the fraction part by exponent. So if we have an 8bit exponent we can multiply the resulting fraction by numbers between 0 and 2^255.</p> <p>So going back to example above let's take exponent of 11000011 = 195.</p> <p>We have fractional part of 01101101 = 0.42578125 and exponent part 11000011 = 195. It gives us the number 0.42578125 * 2^195, this is really big number.</p> <p>So far we can represent non-zero numbers between 2^-8 * 2^0 and (1-2^-8) * 2^255. This allows for very big numbers but not for very small numbers. In order to be able to represent small numbers we have to include so called bias in our exponent. It is a number that will be always subtracted from exponent in order to allow for representation of small numbers.</p> <p>Let's take a bias of 127. Now all exponents are subtracted 127. So numbers that can be represented are between 2^-8 * 2^(0 - 127) and (1-2^-8) * 2^(255 - 127 = 128)</p> <p>Example number is now 0.42578125 * 2^(195-127 = 68) which is still pretty big.</p> <p><strong>Example ends</strong></p> <p>In order to understand this better try to experiment with different bases and sizes for fractional and exponential part. At beginning don't try with odd bases because it only complicates things necessary.</p> <p>Once you grasp how this representation works you should be able to write code to obtain representation of any number in any base, fractional/exponential part combination. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload