Question

So in the context of 24-bit floating points, I have a the following question:

If I want to modify a floating point by using more or less bits for the exponent. For example, I might want to use 9 bits for the exponent, and 15 for the mantissa. How many exponent bits would be most appropriate if i wanted to use a single format representing 172810 and 19174410?

For 172810 the binary rep. was 11011000000 so my exponent was 138 (10+128) so I would want to use 8 bits to represent the exponent 138 (10001010)?

Was it helpful?

Solution

When constructing a non-standard floating-point format, the numbers of bits to allocate to the exponent or the significand1 depends on your own needs. Do what serves you. The exponent bias may also be chosen to serve you. There are no rules when you are making it up, aside from the requirements of mathematics and logic.

The two numbers you show, 1728 and 191744, require ten explicit bits in the significand (nine stored), since 191744 begins with bits 10111010112. The exponents (given a significand normalized to [1, 2)) would be 10 and 17, so you need to be able to encode eight values in the exponent field. However, if you want to reserve one exponent encoding for infinity/NaN, you need nine values. So your exponent needs four bits. (E.g., you could use four bits with a bias of 10, which would be unusual but not impossible, so that 00002 represents exponent 10 and 01112 represents exponent 17. This would make 1728 a subnormal number.) So, representing 1728 and 191744 requires one sign bit, four exponent bits, and nine significand bits. That leaves ten bits for you to allocate any way you wish.

A custom floating-point format is generally useful only for storage, and only when memory use is critical. On any hardware with floating-point support, the native floating-point format will be greatly faster than software implementations of a custom format. So it is usually preferable to convert from the custom format to a hardware-supported format when reading from storage, to perform all computations (including storing intermediate values to memory temporarily) with the hardware format, and to convert back to the custom format just prior to long-term storage.


1 Significand is the preferred term, not mantissa. Mantissas are logarithmic (the fractional part of a logarithm), whereas significands are linear (the fractional part of a floating-point number).

OTHER TIPS

You're applying circular logic. Exponent 10 is stored as 10+128 BECAUSE 128 = 2^7, half the range of your 8 bit exponent field. Had you used a 5 bit exponent field, you could store exponents -16 to +16, and exponent 10 would be stored as 11010 (26).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top