Reputation: 105
I got this problem I have to solve where I have to multiply to floating point numbers (16 bit), but I have no way of double checking it. Any help is immensely appreciated.
Floating Point A: 0 11000 0111000000 Floating Point B: 0 11010 1011000000
I calculate the exponents:
A: 24-15=9 B: 26-15=11
Calculate mantissas (a & b):
(2^9*b) * (2^11*b) = 2^9+11 * (a*b) + 2^20 * (a*b)
Overflow, so I increase exponent of A to sane as B(11).
Then I shift mantissa of A in accordance with the calculation:
1.0111 > 0.10111 > 0.010111.
Then I multiply to get mantissa.
0.010111
* 1.101100
0000000
0000000
0010111
0010111
0000000
0010111
0010111_____
0.100110110100
I shift again.
0.100110110100 < 1.00110110100
Decrease exponent by 1, so it's 10.
Sign is 0, so it's positive number.
Answer: 0 01010 00110110100.
Is it correct?
Thanks in advance!
Upvotes: 2
Views: 2675
Reputation: 154228
Looks like binary16
Is it correct?: No.
Both "mantissas" or fraction need to include an implied bit as its not the minimum exponent. So .1011000000
becomes 1.1011000000
.
Instead 1.01 1100 0000
* 1.10 1100 0000
= 10.0110 1101 0000 0000 0000
The change in exponent is something to consider after the multiplication, in addition to rounding.
Shift right the product 1.0011 0110 1000 0000 0000 0
and +1 to the unbiased exponents 9 + 11 + 1 --> 21.
Round the product to 10 fraction bits
1.0011 0110 1000 0000 0000 0
1.0011 0110 10
Rebuild result
sign 0^0 = 0
biased exponent 21 + 15 = 36 = 100100
, which overflows. @Yves Daoust
fraction = 0011 0110 10
.
Overflow is typically set to INF 0 11111 0000000000 = infinity
Have not doubled check my work yet.
Upvotes: 1
Reputation:
I see two problems:
Upvotes: 0