=========================================== Assignment #02 - range/precision errors in simple numerical calculations =========================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Wednesday January 12, 2011 Deliverables: In-lab demo during Week 1. There is nothing to hand in. Read the whole lab here before you begin. All the words. Download and compile/run the FunnyMath0.java program from the Class Notes. The program produces very wrong answers for very simple arithmetic. (Remember - this is as important as my pension fund you are calculating!) Make a table (on paper) to record the program output for each of the changes you make below: 1. Run and record the above program outputs with no changes. Can you explain what causes each wrong output? What is the reason? Do not change the program. 2. Modify the floating-point sections of the program to add 2 instead of adding 1. Do not make any other changes to the program. Run and Record the new program output. How has the output changed, when adding two? Can you explain the new floating-point outputs? 3. Modify the floating-point sections of the program to add 3 instead of adding 1. Do not make any other changes to the program. Run and Record the new program output. How has the output changed, when adding three? Can you explain the new floating-point outputs? 4. Repeat the above modifications and try adding 4, 5, 6, 7, 8, and 9. Record in your table the outputs for each modification. Do not make any other changes to the program. Can you explain the new floating-point outputs? 5. Call over your instructor. Show the table of outputs for adding 1 through 9. Try to explain what is happening to produce these wrong answers. (Don't worry - it will be explained in class.) 6. Bonus: Instead of modifying the program multiple times, rewrite the program to include a single FOR loop that iterates the floating-point sections to add each of 1 through 9 so that the program produces each of the nine outputs one after the other, for both single- and double-precision floating point. (This is faster than modifying the program multiple times and running it multiple times and writing the output down on paper!) The output of the looping program serves as your table; you don't need to write anything on paper. This lab is a Week 1 in-lab demo. There is nothing to hand in. -- | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/