Floating Point Numbers
- In this section, we would like to examine floating point numbers
- What is a floating point number?
- What do numbers do they represent?
- What numbers do they NOT represent?
- What is possible and not possible?
- How are they represented?
- How can you perform math on these numbers
- How is this mathematics implemented in a computer.
- Fixed point numbers
- What if I represent a number (in 32 bits) as i.f
- Where i is the integer part
- And f is the fractional part.
- I could devote 16 bits to the integer part
- I could devote 15 bits to the fractional part
- I could use 1 bit as the sign.
- This is called fixed point representation since the location of the
decimal point is fixed, or in the same place.
-
- 0 0000000000000000 000000000000000 represents 0
- 1 0000000000000101 000000000000000 represents -5
- 0 0000000000000001 110000000000000 represents 1.75
- What is the number closest to zero that we can represent?
- 0 0000000000000000 000000000000001
- 2-15 = .0000305175
- What is the largest number we can represent ?
- 0 1111111111111111 1111111111111111
- 131,071.9999847413
- What number follows .5?
- 0 1111111111111111 1111111111111111
- 0 0000000000000000 1000000000000001
- .5 + .0000305175 = .5000305175
- Can we represent any numbers in between them?
- This is called the gap
- the gap is the distance between successive values that can be represented.
- In our scheme it is 2-15
- In general, we talk about
- A radix - the base we are representing the numbers in
- A radix point - not decimal point
- A scale factor. This is built in to the represented number.
- If the scale factor is less than 1, we represent large numbers
- If the scale factor is more than 1, we represent fractional
numbers.
- n x s
- In 5 bits, radix = 2, scale factor 1
- 01001 = 01001. = 9
- Scale factor 2-3
- 01001 = 01001000. = 9 * 23 = 72
- scale factor 2 3
- 01001 x 2-3 = 01.001 = 2.125
- A number is n x s
- a x s + b x s = (a x b ) x s
- a x s * b x s = (a x b ) x s x s
- Rounding is the process of representing a number that is in
the gap, in the representation.
- Precision is a measurement of how accurately values can be
represented.
- Floating point numbers
- What is missing here?
- Really big numbers
- Really small numbers
- IEEE 754
- 1 sign bit
- 8 bits to represent the exponent
- 23 bits to represent the significand
- (-1)sx 1.f x 2e-127
-
- Notice here, we do everything to pack the number in.
- We assume that the significand will start with a 1, so it is not
represented.
- 1 10000000 00000->0
- e = 128
- f = 0
- s = 1
- n = (-1) 1 1.0->0 X 2 128-127
- = -1 x 1x21 = -2
- 12.125
- 1100.001
- 1.100000 x 23
- f = 10000->0
- e = 10000010
- 1 10000010 1000->0
- Just to make things a bit more complex (or flexable)
- Denormails
- These are used to represent very small numbers
- Sign bit 0 or 1
- All digits in the exponent are 0
- The value is (-1)sx0.fx2-126
- 0 00000000 00000000000000000000001 is the smallest number
- 0.00000000000000000000001 x 2-126
- 1.0 x 2 -126-23 = 1.0 x 2-139
- One last point:
- If the exponent is 11111111, then this is an error condition.
- It is NAN if the f is other than 1111->1
- If f is 111->1 then it is infinity or negative infinity.
- I am sure that there is an error on table 8.2 page 291
- The double standard usees 11 bits for e (excess 1023) and
57 bits for f.