Assignment 10, due Nov. 6
Part of
the homework for 22C:60, Fall 2009
|
Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!
A question: Explain why long comparison has the potential to be faster than subtraction. (0.5 points)
Background: In the long integer package from mp4, all the arithmetic routines operate on their first parameter and return that parameter as a result, so longadd(a,b) adds the long integer pointed to by b to the long integer pointed to by a and returns the pointer a.
A question: Assuming that X, Y, Z are local variables, each holding a long integer, write Hawk code equivalent to the following expression in a high level language: X = 100*Y + Z. In your code, take maximal advantage of the background information presented above. Your code must, of course, be well commented. (0.5 points)
S E E E M M M M S - the sign of the mantissa E E E - the 3-bit exponent, biased M M M M - the 4-bit mantissa, with a hidden 5th bit
The normalization rule is the common one for binary floating point numbers: the mantissa is strictly less than one and greater than or equal to 0.5, so that the hidden bit is always 1 -- and therefore, need never be stored. This number system has no NaNs and no unnormalized values, so the exponent values run over the entire range from 000 to 111.
a) What is the largest value that can be represented in this number system? Give both the binary representation and the decimal equivalent. (0.3 points)
b) What is the binary representation of 1.0 in this number system? (0.2 points)
c) What is the smallest positive nonzero value that can be represented in this number system. Give both the binary representation and the decimal equivalent. (0.3 points)
d) Explain the problem this number system poses for the representation of zero? (0.2 points)