-1

Compare the range of representable numbers for 16-bit floating-point word with 7-bit exponent and 9-bit mantissa as (i) fraction and (ii) integer.

I know how to find range for a 16 bit integer but not sure how to find same for floating point and how it changes with exponent and mantissa. Kindly help to share detailed answer with some additional examples.

Sumit Rao
  • 1
  • 1
  • 1
    To determine the range of an unknown 16-bit floating point type you'd also have to know if there's a sign flag, if there's an "implied 1 bit", and what the exponent's bias is; and even that would involve some assumptions (e.g. that exponent isn't a signed integer and has a bias). – Brendan Jun 04 '23 at 03:34
  • 2
    This is math not programming. And if you don't know how to do it, read and understand the Wikipedia page for [32 bit floating point](https://en.wikipedia.org/wiki/Single-precision_floating-point_format) and apply the knowledge to your example. If you can't manage that, update your question with **your attempt at solving the problem** and someone can tell you where you are going wrong ... – Stephen C Jun 04 '23 at 03:48
  • @Sumit Rao, "7-bit exponent and 9-bit mantissa" --> 1) is invalid for C `float/double`. 2) It also does not allow for negative numbers. 3) the base needs to be specified. – chux - Reinstate Monica Jun 04 '23 at 05:47
  • how on earth is Windows related to floating-point that you tag it? And did you even look at the duplicate suggestions while asking this? Did you do any research? There are lots of duplicates here on SO: [How to calculate the range, maximu, minimum value of a floating data type?](https://stackoverflow.com/q/57122134/995714), [Calculating range of float in C](https://stackoverflow.com/q/35119686/995714), [How to calculate the range of data type float in c++?](https://stackoverflow.com/q/45727806/995714) – phuclv Jun 04 '23 at 07:56

1 Answers1

1

A floating point number is typically stored as

+/- 1.________ x 2 ^ ( ______ - k )

The first blank being the mantissa (excluding the leading one), and the second blank being the exponent plus some constant k. One exponent value is usually reserved to indicate zero and subnormals, and another value is usually reserved for the NaNs and infinities.

The described format is weird since it doesn't have space for a sign bit.

⇒ Are we to assume it can only represent positive numbers?

The description of the format is lacking, missing any mention of k, and missing instructions on how to save zero, NaNs and infinities.

⇒ Are we to assume it can't represent zero?

⇒ Are we to assume k is zero, meaning it can't represent number smaller than 1? (For example, 0.1 would not be representable.)

If so, the smallest number representable is

       ____9____           ___7___
  +0b1.000000000 × 2 ^ ( 0b0000000 - 0 )
= +1 × 2 ^ 1
= +1 × 1
= +1

And the largest is

  +0b1.111111111 × 2 ^ ( 0b1111111 - 0 )
  +0b1111111111 × 2 ^ ( 0b1111111 - 0 - 9 )
= +1023 × 2 ^ ( 127 - 0 - 9 )
= +1023 × 2 ^ 118
= +1023 × 332306998946228968225951765070086144
= +339950059921992234495148655666698125312

But again, that's based on a lot of guesswork about the specifics for the format.

ikegami
  • 367,544
  • 15
  • 269
  • 518