numerik-5.ms 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. .TL
  2. numerics entry test
  3. .AU
  4. strlst
  5. .SH
  6. attempt 5
  7. .NH
  8. .EQ
  9. define repr `~sub { ~ $3 } ($1) sub { $2 ~ }`
  10. define binary `repr($1, 2)`
  11. define bin `repr($1, 2)`
  12. define is `~~=~~`
  13. define corresponds `~{~= hat}~~`
  14. delim $$
  15. .EN
  16. .PP
  17. Given the following binary number $ bin(100011001) $, interpret it as $ repr(x, 2, fp) $ (where $ fp ... fixed point$) and calculate its decimal value.
  18. .EQ
  19. bin(100011001) mark corresponds repr(100011001, 2, fp) is bin(1.1001) times -1
  20. .EN
  21. .EQ
  22. lineup is ( 1 + 2 sup -1 + 2 sup -4 ) times -1
  23. .EN
  24. .EQ
  25. lineup is ( 1 + 1 smallover 2 + 1 smallover 16 ) times -1
  26. .EN
  27. .EQ
  28. lineup is ( 1 + {8 + 1} smallover 16 ) times -1 is -1 times repr(1.5625, 10)
  29. .EN
  30. .EQ
  31. 9 over 16 = 0.0625 times 9 = 1 smallover 2 + 0.0625 = 0.5625
  32. .EN
  33. .NH
  34. .PP
  35. Add the following encoded binary numbers $ A = bin(0010010001100101), B = bin(1100011101011011) $ represented by the system $ F(2,11,-14,15,true) $ (IEEE 754-2008 with half precision) using $ (round to nearest - round to even ) $ as a rounding scheme. The resulting number should be encoded in the same format.
  36. .PP
  37. The task at hand can be represented as follows:
  38. .LP
  39. .ft CW
  40. .EX
  41. vz | e | m |g|r|s
  42. 0 01001 0001100101
  43. +1 10001 1101011011
  44. e
  45. 10001
  46. -01001
  47. = 01000
  48. .EE
  49. .ft
  50. .PP
  51. Because $ A > B $, we adjust our exponent of number B to that of number A. As we add $ e sub B - e sub A = bin(01000) $ to $ e sub A $, we shift by $ bin(01000) = repr(8, 10) $ digits:
  52. .LP
  53. .ft CW
  54. .EX
  55. vz | e | m |g|r|s
  56. 0 01001 0001100101
  57. +1 10001 1101011011
  58. = 0 01001 0001100101 0 0 0 00000
  59. -0 01001 111 0 1 0 11011
  60. = 0 01001 0001100101
  61. -0 01001 111 0 1 1
  62. = 0 01001 0001011101 1 0 1
  63. = 0 01001 0001011110
  64. .EE
  65. .ft
  66. .PP
  67. The result is $ repr(0010010001011110, 2) $
  68. .NH
  69. .PP
  70. Subtract the following encoded binary number $ bin(1011101000111001) $ from the following encoded binary number $ bin(0100101010111000) $, both numbers being represented using the system $ F(2,11,-14,15,true) $ (IEEE 754-2008 with half precision) using $ (round to nearest - round to even ) $ as a rounding scheme. The resulting number should be encoded in the same format.
  71. .PP
  72. The task at hand can be represented as follows:
  73. .LP
  74. .ft CW
  75. .EX
  76. vz | e | m |g|r|s
  77. 0 10010 1010111000
  78. -1 01110 1000111001
  79. e
  80. 10010
  81. -01110
  82. = 00100
  83. .EE
  84. .ft
  85. .PP
  86. Because we are subtracting the negative number $ B $ from the positive number $ A $, we can reformulate our task:
  87. .EQ
  88. (A) - (-B) is A + B
  89. .EN
  90. .PP
  91. Additionally, like for addition, we inspect the absolute exponent distance. Because $ A > -B $, we shift $ -B $ by $ e sub a - e sub b = bin(00100) = repr(4, 10) $ .
  92. .LP
  93. .ft CW
  94. .EX
  95. vz | e | m |g|r|s
  96. 0 10010 1010111000
  97. -1 01110 1000111001
  98. = 0 10010 1010111000
  99. +0 01110 1000111001
  100. = 0 10010 1010111000
  101. +0 10010 0001100011 1 0 0 1
  102. = 0 10010 1010111000
  103. +0 10010 0001100011 1 0 1
  104. = 0 10010 1100011011 1 0 1
  105. = 0 10010 1100011100
  106. .EE
  107. .ft
  108. .PP
  109. The result is $ repr(0100101100011100, 2) $
  110. .NH
  111. .PP
  112. Multiply the following encoded binary numbers $ bin(1010100010110111), bin(1101001000001000) $ represented by the system $ F(2,11,-14,15,true) $ (IEEE 754-2008 with half precision) using $ (round to nearest - round to even ) $ as a rounding scheme. The resulting number should be encoded in the same format.
  113. .PP
  114. The task at hand can be represented as follows:
  115. .LP
  116. .ft CW
  117. .EX
  118. vz | e | m |g|r|s
  119. 1 01010 0010110111
  120. *1 10100 1000001000
  121. .EE
  122. .ft
  123. .PP
  124. We XOR the sign bit, add the exponents and multiply the mantissas. Adding the exponents would not cause an overflow, but we should subtract $ e $ regardless.
  125. .EQ
  126. e sub { common } is e sub B - e + e sub A
  127. .EN
  128. .LP
  129. .ft CW
  130. .EX
  131. 10100
  132. -01111
  133. +01010
  134. = 00101
  135. +01010
  136. = 01111
  137. .ft
  138. .EE
  139. .PP
  140. Thus our common exponent is $ bin(01111) $. Our sign bit is $ 1 ~~hat~ 1 = 0 $.
  141. .LP
  142. .ft CW
  143. .EX
  144. (1) 0010 1101 11 * (1) 1000 0010 00
  145. = 1 0010 1101 11
  146. + 1001 0110 11 1
  147. + 000 0000 00 00
  148. + 00 0000 00 000
  149. + 0 0000 00 0000
  150. + 0000 00 0000 0
  151. + 000 00 0000 00
  152. + 10 01 0110 111
  153. + 0 00 0000 0000
  154. + 00 0000 0000 0
  155. + 0 0000 0000 00
  156. = 1 1100 0110 11 1110 1110 00
  157. .EE
  158. .ft
  159. .PP
  160. Taking our results thus far, we can finalize our calculations:
  161. .LP
  162. .ft CW
  163. .EX
  164. vz | e | m |g|r|s
  165. 1 01010 0010110111
  166. *1 10100 1000001000
  167. = 0 01111 1100011011 1 1 1 0111000
  168. = 0 01111 1100011011 1 1 1
  169. = 0 01111 1100011100
  170. .EE
  171. .EE
  172. .ft
  173. .PP
  174. The result is $ bin(0011111100011100) $