Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

floating point numbers - closest number to 1.7

I'm preparing for some exams and one of the questions given in the past is to find the closest number to 1.7 given an imaginary floating point format that has a total of 8 bits (1 for sign, 3 for exponent, 4 for significand).

Anyway I put down 1.1011 since I can play with four significand digits and the 1 is implied by the IEEE standard. However, setting the exponent to 000 would make it a denormalised number. Does this mean the value 1.7 would be 1.1100 in floating point?

thx

like image 727
ddriver1 Avatar asked May 03 '11 18:05

ddriver1


People also ask

Is 2.0 a floating-point number?

A Floating Point number usually has a decimal point. This means that 0, 3.14, 6.5, and -125.5 are Floating Point numbers.

How do you represent a decimal number in a floating-point?

Like scientific notation, floating-point numbers have a sign, mantissa (M), base (B), and exponent (E), as shown in Figure 5.27. For example, the number 4.1 × 103 is the decimal scientific notation for 4100. It has a mantissa of 4.1, a base of 10, and an exponent of 3.

What is the range of the floating-point numbers?

A single-precision, floating-point number is a 32-bit approximation of a real number. The number can be zero or can range from -3.40282347E+38 to -1.17549435E-38, or from 1.17549435E-38 to 3.40282347E+38.

How many floats are there between 0 and 1?

So how many “normal” non-zero numbers are there between 0 and 1? The negative exponents range from -1 all the way to -126. In each case, we have 223 distinct floating-point numbers because the mantissa is made of 23 bits. So we have 126 x 223 normal floating-point numbers in [0,1).


1 Answers

The questioner posted an answer that was deleted by a moderator. I've flagged it for attention, but I'll add a few notes here as well.

The key is that IEEE-754-style floating-point formats store the exponent in a "biased" (also called "excess-n") integer format. With 3 exponent bits, the bias is 3, so the set of encodeable exponents is:

encoding    meaning
  000       exponent for zeros and denormals
  001       2^-2
  010       2^-1
  011       2^0
  100       2^1
  101       2^2
  110       2^3
  111       exponent for infinities and NaNs

Thus, the questioners value 1.7 would have an exponent field of 3 (b011), and a significand field of b1011 as he stated, which makes the full value b00111011.

like image 78
Stephen Canon Avatar answered Sep 29 '22 05:09

Stephen Canon