IEEE-754 Question: Execute the following while loops (modifying the code to add a counter). Explain the reasons these loops for the observed count value.



The counter is 53, 1024, 1075 for the above three for loops. The code is attatched in 4.2.

  1. According to IEEE-754 (double precision), the machine epsilon is $2^{-52}$. So numbers in the range 1+2^{-53}<=x<1+2^{-52}+2^{-53}  might be rounded to x_m=1+2^{-52}. Since the while loop counter increases 1 at 1/2^0=1, the counter is 53 finally.
  2. According to IEEE-754, the exponent e satisfies -1022\leqe<=1023, and plus one for the first loop, the counter goes to 1024 and stops. With overflow at the last loop, x would be inf.
  3. Initially, I suppose it to be 1023 because the realmin in Matlab is 2^{-1022}. However, Matlab proves me to be wrong. After reading Reference 1 by Cleve Moler, it is possible to have values less than realmin. According to Reference 5.1, when any computation tries to produce a value smaller than realmin, it is said to underflow. This involves one of the optional, and controversial, aspects of the IEEE standard. Many, but not all, machines allow exceptional denormal or subnormal floating-point numbers in the interval between [realmin, eps * realmin] . So the smallest positive subnormal number is 2^{-52}*2^{-1022}=2^{-1074} . So the counter is 1075.


C Moler. Floating points IEEE Standard unifies arithmetic model. [Online]