ECE-1021

HOMEWORK #3

(Last Mod: 27 November 2010 21:38:42 )

ECE-1021 Course Homepage

ECE-1021 Semester Homepage


Objectives


Assignment

NOTE: This is IDENTICAL to assignment #2, but it IS a different assignment. Meaning if you submitted homework for HW#2, that submission was for HW#2. If you want to use that same code for HW#3, then you must copy it to an appropriately named file and submit it for HW#3 using the proper e-mail subject line. 

Integer Output

Write the following functions to output the numerical values of the following integer data types.

  1. int PutV_i(int n);

  2. int PutV_u(unsigned n);

  3. int PutV_li(long n);

  4. int PutV_lu(unsigned long n);

All of the above functions print the values in decimal.

In each case, the return value is the number of characters actually printed. The functions should not print any space characters before or after the output.

Your test program should test the these functions for both typical values and extreme values. The maximum and minimum values can be accessed via the constants in <limits.h>.

For each value printed, your program should also print out the internal bit representation of that value.


Floating Point Output

Write the following functions to output the numerical values of each of the basic floating point data types.

  1. int PutV_f(float v);

  2. int PutV_lf(double v);

  3. int PutV_e(float v);

  4. int PutV_le(double v);

The _f and _lf functions are to print all digits to the left of the decimal point. If the absolute value is less than one, a single zero is printed to the left of the decimal point. Six digits to the right of the decimal point should be printed.

The _e and _le functions are to print the output in normalized exponential notation six digits to the right of the decimal point. The format should be as indicated in the following examples:

3.451234e2

-6.123498e-19

All of the above functions print the values in decimal. Your functions need not perform rounding on the last decimal place - but extra credit will be given to that that do so correctly.

In each case, the return value is the number of characters actually printed. The functions should not print any space characters before or after the output.

Your test program should test the these functions for both typical values and extreme values. The maximum and minimum values can be accessed via the constants in <float.h>.

For each value printed, your program should also print out the internal bit representation of that value.