Lab 6 - Fun with Floats

Purpose:

To practice using floating point numbers in C, and explore different aspects of them.
 
PRELAB:
The prelab is intended to provide practice for dealing with the way computers represent floating point numbers.

1.) Convert 0x7237176E from binary FP to decimal.

2.) Compute the following sums (convert to binary FP and perform sums):
            x = -3.7*2^30         y = 3.7*2^30            z = 1.0
             a.)  x + (y + z)
             b.)  (x + y) + z
 

LAB:

Task 1: Precision

As you should know, floating points are approximation of real numbers. Not every real number can be represented. Define two numbers in double precision:
A =  55555555555555555555552523523523525555.1305197613051976;
B = -55555555555555555555252352523525555555.1305197613051976;
And now print them on the screen using printf. Are the numbers you have printed the one you have defined? If not why?
Task 2: Infinity We want to explore now how the positive infinity value is represented. Refer to lecture notes to figure out how to input positive infinity, then print it out as integer, float, and hexadecimal.

When you have done this, do the same for negative infinity.

Task 3: Not a number And now, let's see how NaN is printed out. Refer to lecture notes again to input this value, and print it out as integer, float, and hexadecimal. Task 4: Associative property It should be pretty clear now that floating point numbers and real numbers are two different sets of numbers. You have studied that addition is associative for real numbers. This means that if A,B and C are real number, than (A+B)+C = A+(B+C). Well, this is NOT true for floating point.

Write a short C program to prove that addition is not associative for floating point.

Task 4: Numeric conversion Now we want to study how the type conversion between float and int work. Define an integer number E and a double number F. Assign to E the value: 5732213051976130519761305197613051976. Then cast the value of E into F. Print the content of these two variables with printf.

Last but not least, try to print the value of F as an integer. What is goin' on?

Notes: Last updated: 9/28