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 ﬂoating-point register. Whenever procedure test1 calls some function, it must store any value currently in a ﬂoating-point 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 double-precision number. After the second call, variable r2 has the extended-precision value returned by the function. In computing t1, the double-precision number r1 is compared to the extended-precision 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
- The American