Floating Point Algorithm when Divisor Mantissa is all zeros - say in the case of 2.0 in - IEEE -754

Viewed 198

I have a need to implement a floating point package for small SBC and have most of the routines now working, but in the course of testing I have noticed that the algorithm in this 1 (attachment) will not (indeed cannot) produce the correct answer in the case where the divisor mantissa is all zeros, for the example 500/2 will produce the answer 255.0 rather than 250.0

01000000011111110100000000000000 = 0x43FA00  (500 base 10) and
01000000000000000000000000000000 = 0x400000  (2 base 10)

will produce

01000011011111111000000000000000 =0x437F0 (255 base 10)

Is there anyone who has a good knowledge of Floating Point arithmetic or indeed FP algorithms that can help out please?

[Floating Point Division Algorithm]

1 Answers

Nothing in the chart shown says to work with the bits that are the primary encoding of the significand of a floating-point number. One should not confuse the bits that encode something with the thing itself. The actual significand of a normal IEEE-754 binary floating-point number, for example, is some binary numeral 1.xxx…xxx with a value in [1, 2) and a number of bits determined by the specific format. (Subnormal numbers use a numeral 0.xxx…xxx.) When the number is encoded in an interchange format, the xxx…xxx bits are stored in the primary significand field, and the leading 1 or 0 bit is encoded by way of the exponent field. (If the exponent field is not zero, and does not indicate an infinity or a NaN, then the leading bit is 1. Otherwise, it is 0.)

Generally, the actual significand is used for arithmetic, not just the bits of the primary significand field.

Related