Exercises
Exercise 1
 Write a program that determines whether your implementation
Raises a floatingpoint exception
when a floatingpoint error occurs in the library functions.

Exercise 2
 Check the results of the following function calls:

Exercise 3
 Assume a floatingpoint representation with β = 10 and p = 3. Thus, normalized values can be represented in the usual exponential notation: .ddd x 10^{e}. Also assume that the maximum allowable exponent is 9 and that the minimum allowable exponent is  9.
What are the normalized representations of the following values? What are the normalized representations of the values of the following expressions? .600 x 10^{3} + .600 x 10^{3} .500 x 10^{0} + .500 x 10^{1} .500 x 10^{0} + .500 x 10^{2} .500 x 10^{0} + .500 x 10^{3} .100 x 10^{1} + .100 x 10^{x1} .123 x 10^{3} + .123 x 10^{2} .123 x 10^{3} + .123 x 10^{1} .123 x 10^{3} + .123 x 10^{0}
Assuming that the floatingpoint representation does not support denormalized values, what are the results of the following expressions? .123 x 10^{8}/.100 x 10^{2} .123 x 10^{8}/.100 x 10^{3} .123 x 10^{8}/.100 x 10^{4} .123 x 10^{8}/.100 x 10^{5}
Assuming now that the floatingpoint representation does support denormalized values, what are the results of the following expressions? .123 x 10^{8}/.100 x 10^{2} .123 x 10^{8}/.100 x 10^{3} .123 x 10^{8}/.100 x 10^{4} .123 x 10^{8}/.100 x 10^{5}

Exercise 4
 Write a program that uses the macros defined in the header <float.h> (or <cfloat>) to determine the following properties of each of the three types float, double, long double for your implementation:
The radix of the floatingpoint representation The number of digits, in base radix, in the significand The minimum and maximum exponents for nonzero normalized representable values The number of decimal digits representable in the significand The minimum positive representable value The maximum representable finite value

Exercise 5
 Write a program that uses std::numeric_limits to determine the properties listed in the previous exercise.

Exercise 6
 Write a program that computes the smallest value of type double that can be added to 1.0 to produce a value that is different from 1.0. Is this value the same as numeric_limits<double>::epsilon()? Should it be?

Exercise 7
 Write a program that determines which of the standard rounding modes are supported by your implementation.

Exercise 8
 Write a program that converts each of the values 1.5, 0.5, 0.5, and 1.5 to an integer value, using each of the rounding modes supported by your implementation. Explain the results.

Exercise 9
 Write a program that rounds each of the values 1.5, 0.5, 0.5, and 1.5, using the default rounding mode and calling each of the functions ceil, floor, nearbyint, rint, lrint, llrint, round, lround, llround, and TRunc.

Exercise 10
 Write a program that consists of the following functions:
A function int dround(double) that uses the default rounding mode to return its argument rounded to an integer value A function int uround(double) that uses the function lrint to round its argument upward and return the result; on return the default rounding mode should be unchanged, even if an exception was thrown A main function that calls dround(1.1) and displays the result, then calls uround(1.1) and displays the result, and, finally, calls dround (1.1) again and displays the result Make sure that the two calls to dround return the same value.

Exercise 11
 Write a program that determines which of the standard floatingpoint exceptions are supported by your implementation.

Exercise 12
 Write a program that performs mathematical operations that raise each of the floatingpoint exceptions supported by your implementation and verifies that the exception was raised.

Exercise 13
   Write a program containing a function that raises a floatingpoint exception of your choice and a second function that calls the first but guarantees that on return, all floatingpoint exceptions are cleared, even if the return is through a C++ exception. The main function should check that the floatingpoint exceptions are cleared.

Exercise 14
 Write a program containing a function that raises a floatingpoint exception of your choice and a second function that calls the first but guarantees that on return, the floatingpoint status has been restored to its state on entry to the function, even if the return is through a C++ exception. The main function should check that the floatingpoint status is unchanged.

Exercise 15
 Write a program containing a function that raises a floatingpoint exception of your choice and a second function that calls the first but defers raising of floatingpoint exceptions until it returns.

Exercise 16
 Write a program containing a function that changes the rounding mode and raises a floatingpoint exception of your choice and a second function that calls the first but guarantees that on return, the floatingpoint status and the rounding mode have been restored to their states on entry to the function, even if the return is through a C++ exception. The main function should check that the floatingpoint status and the rounding mode are unchanged.

Exercise 17
 Write a function template that returns a string object that holds "infinite", "notanumber", "normal", "denormal", or "zero", depending on the value of its argument. Test it with the following values:
0.0 3. numeric_limits<double>::infinity() numeric_limits<double>::infinity() numeric_limits<double>::quiet_NaN() numeric_limits<double>::denorm_min()

Exercise 18
 Write a comparison function that takes two arguments of type double and imposes a strict weak ordering on all possible argument values. In particular, make sure that it handles NaN values consistently. Write a program that uses this function as the comparator for a std::set<double>, and verify that it works sensibly.

Exercise 19
 What is the type of the returned value of each of the following function calls?
Write a program to verify your answers.

