numerik-4.ms 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. .TL
  2. numerics entry test
  3. .AU
  4. strlst
  5. .SH
  6. attempt 4
  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(100001010) $, interpret it as $ repr(x, 2, fp) $ (where $ fp ... fixed point$) and calculate its decimal value.
  18. .EQ
  19. bin(100001010) mark corresponds repr(100001010, 2, fp) is bin(0.1010) times -1
  20. .EN
  21. .EQ
  22. lineup is ( 2 sup -1 + 2 sup -3 ) times -1
  23. .EN
  24. .EQ
  25. lineup is ( 1 smallover 2 + 1 smallover 8 ) times -1
  26. .EN
  27. .EQ
  28. lineup is {4 + 1} smallover 8 times -1 is -1 times repr(0.625, 10)
  29. .EN
  30. .EQ
  31. 5 over 8 = 0.125 times 5 = 0.625
  32. .EN
  33. .NH
  34. .PP
  35. Add the following encoded binary numbers $ A = bin(1000101011100100), B = bin(0110100111100110) $ 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. 1 00010 1011100100
  43. +0 11010 0111100110
  44. .EE
  45. .ft
  46. .PP
  47. Because $ A < B $, we adjust our exponent of number A to that of number B. Because we add $ e sub B - e sub A = bin(11000) $ to $ e sub A $, we shift by $ bin(11000) = 24 $ digits:
  48. .LP
  49. .ft CW
  50. .EX
  51. vz | e | m |g|r|s
  52. 1 00010 1011100100
  53. +0 11010 0111100110
  54. = 1 11010 0000000000 0 0 0 0000000000 (1) 1011100100
  55. +0 11010 0111100110
  56. = 0 11010 0111100110
  57. -0 11010 0000000000 0 0 0 0000000000 (1) 1011100100
  58. = 0 11010 0111100110
  59. -0 11010 0000000000 0 0 1
  60. = 0 11010 0111100110
  61. -0 11010 0000000000
  62. = 0 11010 0111100110
  63. .EE
  64. .ft
  65. .PP
  66. The result is $ repr(0110100111100110, 2) $
  67. .NH
  68. .PP
  69. Subtract the following encoded binary number $ bin(0100001111111100) $ from the following encoded binary number $ bin(1100001010110010) $, 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.
  70. .PP
  71. The task at hand can be represented as follows:
  72. .LP
  73. .ft CW
  74. .EX
  75. vz | e | m |g|r|s
  76. 1 10000 1010110010
  77. -0 10000 1111111100
  78. .EE
  79. .ft
  80. .PP
  81. Because we are subtracting the positive number $ B $ from the negative number $ A $, we can reformulate our task:
  82. .EQ
  83. (-A) - (B) is (-A) + (-B)
  84. .EN
  85. .LP
  86. .ft CW
  87. .EX
  88. vz | e | m |g|r|s
  89. 1 10000 1010110010
  90. -0 10000 1111111100
  91. = 1 10000 1010110010
  92. +1 10000 1111111100
  93. = 1 10001 1101010111 0
  94. = 1 10001 1101010111
  95. aux calculation:
  96. (1) 1010110010
  97. +(1) 1111111100
  98. = 11 1010101110
  99. = (1) 1 1010101110
  100. = (1) 1101010111 0 => overflow => exp. correction
  101. .EE
  102. .ft
  103. .PP
  104. The result is $ repr(1100011101010111, 2) $
  105. .NH
  106. .PP
  107. Multiply the following encoded binary numbers $ bin(0010010001100101), bin(0011000000010010) $ 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.
  108. .PP
  109. The task at hand can be represented as follows:
  110. .LP
  111. .ft CW
  112. .EX
  113. vz | e | m |g|r|s
  114. 0 01001 0001100101
  115. *0 01100 0000010010
  116. .EE
  117. .ft
  118. .PP
  119. We XOR the sign bit, add the exponents and multiply the mantissas. Adding the exponents would not cause an overflow, so we can primitively add the exponents.
  120. .EQ
  121. e sub { common } is e sub A + e sub B
  122. .EN
  123. .LP
  124. .ft CW
  125. .EX
  126. 01001
  127. +01100
  128. = 10101
  129. .ft
  130. .EE
  131. .PP
  132. Thus our common exponent is $ bin(10101) $. Our sign bit remains $ 0 $.
  133. .LP
  134. .ft CW
  135. .EX
  136. (1) 0001 1001 01 * (1) 0000 0100 10
  137. = 1 0001 1001 01
  138. + 0000 0000 00 0
  139. + 000 0000 00 00
  140. + 00 0000 00 000
  141. + 0 0000 00 0000
  142. + 0000 00 0000 0
  143. + 100 01 1001 01
  144. + 00 00 0000 000
  145. + 0 00 0000 0000
  146. + 10 0011 0010 1
  147. + 0 0000 0000 00
  148. = 1 0001 1110 00 1100 0110 10
  149. .EE
  150. .ft
  151. .PP
  152. Taking our results thus far, we can finalize our calculations:
  153. .LP
  154. .ft CW
  155. .EX
  156. vz | e | m |g|r|s
  157. 0 01001 0001100101
  158. *0 01100 0000010010
  159. = 0 10101 0001111000 1 1 0 0011010
  160. = 0 10101 0001111000 1 1 1
  161. = 0 10101 0001111001
  162. .EE
  163. .EE
  164. .ft
  165. .PP
  166. The result is $ bin(0101010001111001) $