0

I'm trying to understand how to get the mantissa and the exponent in this case. Here's an example I have in my book.

I have this formula (-1)^s * (1 + M) * b^E-e = x

s = 0 or 1 (the sign)
M = mantissa
b = base (In this case 2)
E = the exponent of this mantissa
e = 127 (for a 32bits system)

Still in by book, for x = 1.602177 * 10^-19, I get

S = 0,

M = 0.4777474,

E = 64

which it works.

1 * 1.4777474 * 2^-63 = 1.60210^-19*

However, I don't know how to get the values for M and E.

I read that E = log b |x| then M = |x|b^-E

In this case E = log2(1.602177*10^-19) = -62.43660 (I'm using a website for the log base 2, so I'm not sure about the result so I tried E = -62 and -63).

M = (1.602177 * 10^-19) * 2^-(-62) = 0.7388737

M = (1.602177 * 10^-19) * 2^-(-63) = 1.4777474

Correct me if I'm wrong but the mantissa is the digits to the right of the floating point. In this case 0.4777474 looks right.

At this point I have E = -63 and M = 0.4777474, but E should be 64

JacobIRR
  • 8,545
  • 8
  • 39
  • 68
proxima
  • 23
  • 1
  • 5
  • " In this case 0.4777474 looks right." --> Not precisely. The fraction portion is a [Dyadic rational](https://en.wikipedia.org/wiki/Dyadic_rational), not 0.4777474, but perhaps 4,007,636/(2^23). – chux - Reinstate Monica Sep 01 '20 at 15:52

1 Answers1

0

I have E = -63 and M = 0.4777474, but E should be 64

Mathematically, the exponent is -63 as x = 1.602177 * 10^-19 is in the 2-63 neighborhood. Yet the value stored is a 8-bit unsigned biased exponent with binary32. Subtract the bias (-127) from the math exponent to get the biased exponent.

biased_exponent = expo - bias
64 = -63 - (-127)
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • The bias is always -127? I didn't know that. However, for x = pi, the description above doesn't work. – proxima Sep 02 '20 at 02:48
  • @proxima There are special considerations when the biased exponent is at min/max. Review [binary32](https://en.wikipedia.org/wiki/Single-precision_floating-point_format) for details. – chux - Reinstate Monica Sep 02 '20 at 02:51
  • I can't find the proper way to find the mantissa. What I did doesn't work for pi. – proxima Sep 02 '20 at 03:42