Assignment for Computer Architecture Instructions: The assignment is to create a program that adds the number 1/2 to itself a large number of times and adds the number 1/3 to itself a large number of times separately first using type float and then type double. It is to then compare the values of adding the numbers to multiplying 1/2 time the number of times added to compute the “same sum” in a different way. The program will also multiply 1/3 times the number of times 1/3 was added to itself to compute the “same sum” in a different way. The program will then compare these two methods at arrive for the same value and output the difference. Hint, the value for the ½’s will be the same for the smaller numbers of times, the 1/3’s will never be the same. The output from your program is to be to a *.txt file which you are to turn in along with your code.   The program must first add the ½’s and 1/3’s using type float and compare to the value obtain using multiplication instead of addition. It is to do this for the following values: 1.000 10,000 100,000 1,000,000 10,000,000 100,000,000 1,000,000,000   The program should do this using two nested loops. The outer loop determines the number of times to add and starts at a 1000 and increments by multiples of 10 up to a 1,000,000,000. The inner loop does the addition of the numbers 1/2 and 1/3 (Note, there are to be two sums, one sum is for the ½’s and the other for the 1/3’s). When the inner loop finishes, compute the products that “should” be the same. Hint, they will not always be the same. Why? After the inner loop completes, output the two sums and the two products, and the differences between the sums and the products that “should be the same” to check for rounding errors. Hint, the ½’s will be good for at least a while, but the 1/3’s will always be off since 1/3 does not go into a float (or double) exactly. Then continue the outer loop. Remember to clear your variables for the sums before the start of the inner loop. Send this output to a text file. The top line of the output file should have your name and the assignment number.   Next the program repeats the above except that it uses type double instead of type float for the variables. This will require a second set of nested loops and different variables.   Have a brief description of the program in comments at the top, have comments in the program, use proper blocking, and make certain to test your program to verify that it is working properly.     You may do this assignment in C/C++ or Java (if you want to use another language, clear it with me first). Note that Python will not work for this assignment as it does not do single precision. Along with your code and output file, turn in an observations file, stating how much time this program took and what you learned from it. Make certain that you have your name and the assignment number at the top of your observations file and the top of your output file.  The output should look something like below (feel free to do output your way, but make it neat and readable if you want full credit):   Name: John Smith Assignment 1   FLOAT   For 1000 iterations one half addition: 500.0 one half multiplication: 500.0 the difference is 0.0 one third addition: 333.3341 one third multiplication: 333.33334 the difference is 7.6293945E-4   and so forth for the rest of the values for float and then over again for double precision values.   Note that the sums for the ½’s should be correct for a while. The sums for the 1/3’s will always be off, only a little at first (see above example) but then get worse with time.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Topic Video
Question

Assignment for Computer Architecture

Instructions:

The assignment is to create a program that adds the number 1/2 to itself a large number of times and adds the number 1/3 to itself a large number of times separately first using type float and then type double. It is to then compare the values of adding the numbers to multiplying 1/2 time the number of times added to compute the “same sum” in a different way. The program will also multiply 1/3 times the number of times 1/3 was added to itself to compute the “same sum” in a different way. The program will then compare these two methods at arrive for the same value and output the difference. Hint, the value for the ½’s will be the same for the smaller numbers of times, the 1/3’s will never be the same. The output from your program is to be to a *.txt file which you are to turn in along with your code.

 

The program must first add the ½’s and 1/3’s using type float and compare to the value obtain using multiplication instead of addition. It is to do this for the following values:

1.000

10,000

100,000

1,000,000

10,000,000

100,000,000

1,000,000,000

 

The program should do this using two nested loops. The outer loop determines the number of times to add and starts at a 1000 and increments by multiples of 10 up to a 1,000,000,000. The inner loop does the addition of the numbers 1/2 and 1/3 (Note, there are to be two sums, one sum is for the ½’s and the other for the 1/3’s). When the inner loop finishes, compute the products that “should” be the same. Hint, they will not always be the same. Why? After the inner loop completes, output the two sums and the two products, and the differences between the sums and the products that “should be the same” to check for rounding errors. Hint, the ½’s will be good for at least a while, but the 1/3’s will always be off since 1/3 does not go into a float (or double) exactly. Then continue the outer loop. Remember to clear your variables for the sums before the start of the inner loop. Send this output to a text file. The top line of the output file should have your name and the assignment number.

 

Next the program repeats the above except that it uses type double instead of type float for the variables. This will require a second set of nested loops and different variables.

 

Have a brief description of the program in comments at the top, have comments in the program, use proper blocking, and make certain to test your program to verify that it is working properly.

 

 

You may do this assignment in C/C++ or Java (if you want to use another language, clear it with me first). Note that Python will not work for this assignment as it does not do single precision.

Along with your code and output file, turn in an observations file, stating how much time this program took and what you learned from it. Make certain that you have your name and the assignment number at the top of your observations file and the top of your output file. 

The output should look something like below (feel free to do output your way, but make it neat and readable if you want full credit):

 

Name: John Smith

Assignment 1

 

FLOAT

 

For 1000 iterations

one half addition: 500.0

one half multiplication: 500.0

the difference is 0.0

one third addition: 333.3341

one third multiplication: 333.33334

the difference is 7.6293945E-4

 

and so forth for the rest of the values for float and then over again for double precision values.

 

Note that the sums for the ½’s should be correct for a while. The sums for the 1/3’s will always be off, only a little at first (see above example) but then get worse with time.

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT