numerik-3.ms 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. .TL
  2. numerics entry test
  3. .AU
  4. strlst
  5. .SH
  6. attempt 3
  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(000010110) $, interpret it as $ repr(x, 2, fp) $ (where $ fp ... fixed point$) and calculate its decimal value.
  18. .EQ
  19. bin(000010110) mark corresponds repr(000010110, 2, fp) is bin(00001.0110)
  20. .EN
  21. .EQ
  22. lineup is 2 sup 1 + 2 sup -2 + 2 sup -3
  23. .EN
  24. .EQ
  25. lineup is 2 + 1 smallover 4 + 1 smallover 8
  26. .EN
  27. .EQ
  28. lineup is 2 + {2 + 1} smallover 8 is 2 + 3 smallover 8 is repr(2.375, 10)
  29. .EN
  30. .EQ
  31. 3 over 8 = 0.125 times 3 = 0.375
  32. .EN
  33. .NH
  34. .PP
  35. Add the following encoded binary numbers $ bin(1001110011001111), bin(0000011111010110) $ 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 00111 0011001111
  43. +0 00001 1111010110
  44. .EE
  45. .ft
  46. .LP
  47. .ft CW
  48. .EX
  49. vz | e | m |g|r|s
  50. 1 00111 0011001111
  51. +0 00001 1111010110
  52. = 1 00111 0011001111 0 0 0 000
  53. +0 00001 1111 0 1 0 110
  54. = 1 00001 0011001111
  55. +0 00001 0000001111 0 1 0 110
  56. = 1 00001 0011001111
  57. +0 00001 0000001111 0 1 0 110
  58. = 1 00001 0011011110 0 1 0 110
  59. = 1 00001 0011011110 0 1 1
  60. = 1 00001 0011011110
  61. .EE
  62. .ft
  63. .PP
  64. The result is $ repr(1000010011011110, 2) $
  65. .NH
  66. .PP
  67. Subtract the following encoded binary number $ bin(0110100111100110) $ from the following encoded binary number $ bin(1000101011100100) $, 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.
  68. .PP
  69. The task at hand can be represented as follows:
  70. .LP
  71. .ft CW
  72. .EX
  73. vz | e | m |g|r|s
  74. 1 00010 1011100100
  75. -0 11010 0111100110
  76. .EE
  77. .ft
  78. .PP
  79. Because our first number $ A $ is smaller than our second number $ B $, we can avoid overflow problems by reformulating the task:
  80. .EQ
  81. B > A ~: A - B is -~(B - A)
  82. .EN
  83. .LP
  84. .ft CW
  85. .EX
  86. vz | e | m |g|r|s
  87. 1 00010 1011100100
  88. -0 11010 0111100110
  89. = 1 11010 0111100110
  90. -1 00010 1011100100
  91. +1
  92. .EE
  93. .ft
  94. .PP
  95. Next we need to calculate the absolute exponent difference $ e sub { dist } = e sub B - e sub A ,~ e sub B > e sub A $
  96. .LP
  97. .ft CW
  98. .EX
  99. 11010
  100. -00010
  101. = 11000
  102. .EE
  103. .ft
  104. .EQ
  105. bin(11000) is 2 sup 3 + 2 sup 4 is 8 + 16 is repr(24, 10)
  106. .EN
  107. .LP
  108. .ft CW
  109. .EX
  110. vz | e | m |g|r|s
  111. 1 00010 1011100100
  112. -0 11010 0111100110
  113. = 1 11010 0111100110
  114. -1 00010 1011100100
  115. +1
  116. = 1 11010 0111100110
  117. -1 11010 0000000000 0 0 0 000000000001011100100
  118. +1
  119. = 1 11010 0111100110
  120. .EE
  121. .ft
  122. .PP
  123. The result is $ repr(1110100111100110, 2) $
  124. .NH
  125. .PP
  126. Multiply the following encoded binary numbers $ bin(0100110011111010), bin(0100010100000001) $ 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.
  127. .PP
  128. The task at hand can be represented as follows:
  129. .LP
  130. .ft CW
  131. .EX
  132. vz | e | m |g|r|s
  133. 0 10011 0011111010
  134. *0 10001 0100000001
  135. .EE
  136. .ft
  137. .PP
  138. We XOR the sign bit, add the exponents and multiply the mantissas. It should be noted, because adding the exponents would cause an overflow, we subtract the excess number first.
  139. .EQ
  140. e sub { common } is e sub A - e + e sub B
  141. .EN
  142. .LP
  143. .ft CW
  144. .EX
  145. 10011
  146. -01111
  147. +10001
  148. = 00100
  149. +10001
  150. = 10101
  151. .ft
  152. .EE
  153. .PP
  154. Thus our common exponent is $ bin(10101) $. Our sign bit remains $ 0 $.
  155. .LP
  156. .ft CW
  157. .EX
  158. (1) 0011 1110 10 * (1) 0100 0000 01
  159. = 1 0011 1110 10
  160. + 0000 0000 00 0
  161. + 100 1111 10 10
  162. + 00 0000 00 000
  163. + 0 0000 00 0000
  164. + 0000 00 0000 0
  165. + 000 00 0000 00
  166. + 00 00 0000 000
  167. + 0 00 0000 0000
  168. + 00 0000 0000 0
  169. + 1 0011 1110 10
  170. = 1 1000 1110 01 1011 1110 10
  171. .EE
  172. .ft
  173. .PP
  174. Taking our results thus far, we can finalize our calculations:
  175. .LP
  176. .ft CW
  177. .EX
  178. vz | e | m |g|r|s
  179. 0 10011 0011111010
  180. *0 10001 0100000001
  181. = 0 10101 1000111001 1 0 1 1111010
  182. = 0 10101 1000111001 1 0 1
  183. = 0 10101 1000111010
  184. .EE
  185. .EE
  186. .ft
  187. .PP
  188. The result is $ bin(0101011000111010) $