This preview shows page 1. Sign up to view the full content.
Unformatted text preview: hidden side effects—function recip does a straightforward reciprocal computation, and, as the name suggests, function do_nothing does nothing. When the ﬁle is compiled with optimization ﬂag ‘O2’ and run with argument 10, however, we get the following result:
test1 t1: r1 0.100000 != r2 0.100000 test1 t2: r1 0.100000 == r2 0.100000 The ﬁrst test indicates the two reciprocals are different, while the second indicates they are the same! This is certainly not what we would expect, nor what we want. The comments in the code provide a clue for why this outcome occurs. Function recip returns its result in a ﬂoatingpoint register. Whenever procedure test1 calls some function, it must store any value currently in a ﬂoatingpoint register onto the main program stack, converting from extended to double precision in the process. (We will see why this happens shortly). Before making the second call to recip, variable r1 is converted and stored as a doubleprecision number. After the second call, variable r2 has the extendedprecision value returned by the function. In computing t1, the doubleprecision number r1 is compared to the extendedprecision number r2. Since ¼ ½ cannot be...
View
Full
Document
This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.
 Spring '10
 Schultz
 The American

Click to edit the document details