开发者

Floating point limits

I've been given these two questions, and I can't wrap my head around floating point properly, so if someone could offer some pointers as to how I should work these questions out, I'd be very grateful.

  1. What is the smallest and largest number that can be represented in 2s compliment normalised floating point notation with 10 bit mantissa and 6 bit exponent?

  2. What are the two closest values to 0 possible with the above mantissa 开发者_StackOverflow社区and exponent. Think where underflow and overflow occurs.


(I would add this as a comment, but at some point I lost the ability to comment. Perhaps by reputation degraded somehow at some point.)

Make sure you make a distinction between what "smallest number" means, versus what "most negative number" means. These are different and you could lose credit based on which way you answer this on your assignment. Given that the second questions is asking for the smallest numbers representable in this format, I think the first question is actually supposed to be asking for the most negative number (the negative number farthest from zero - the negative number with highest magnitude).

As stated in an earlier answer, I suggest you work these out by hand.

Ask yourself: What combination of sign, exponent, and mantissa would create the largest/smallest numbers? If you know how the conversion from binary to decimal, I think you should be able to easily solve this problem. If you don't know, then I suggest you start there and work your way up.


If you're talking about an IEE754 variant, you can examine Wikipedia IEEE754-1985 and work out the calculations for fully normalised number yourself, given the different sizes for the fraction and exponent.

Forget the sign for now, that's just a simple bit-flip.

The biggest fraction is all one-bits which, for a ten-bit mantissa, is:

      1   1   1    1    1    1    1     1     1      1
  1 + - + - + - + -- + -- + -- + --- + --- + --- + ----
      2   4   8   16   32   64   128   256   512   1024

= 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
  -----------------------------------------------------
                           1024

(the implicit 1 plus ten bits of ever-halving fractions). That's 2047/1024.

Regarding the exponent, the highest non-special value (special values are things like NaN or ±Inf) for a 6-bit exponent is 26-2 or 62 (the range is 0 thru 62).

But, because you need positive and negative exponents, you subtract 31 (the bias, half the maximum non-special value). This gives you the range -30 thru 31 (-31 can be discounted here since it's not normalised).

So the largest and smallest (most negative) values are ±(2047/1024)x231 or ±4292870144.

Similarly, the two values closest to zero have an exponent field of -30 (the minimum normalised) and a mantissa field of all zeroes which, with the implicit 1, gives you 1.

Those values are ±(1)x2-30 or ±0.000000000931322574615478515625.

You should print out that Wikipedia page and this answer and sit down with both until you understand them. I don't mind helping you out here but, if you regurgitate my answer for your homework, you will almost certainly be caught out (if your educators have any intelligence, though there's no guarantee of that).

In order to put this answer into your own words (and hence not get caught out for plagiarism), you'll have to understand it.


Perhaps you should take a look at these pages: 1, 2, 3, 4, 5, 6, 7

I hope that helps without just giving the answers directly. :)

Btw. have you tried doing the calculations by hand?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜