Question
CAN SOMEONE HELP ME WITH THIS? Task 4: Testing for Overflow The Factorial function is an extremely fast growing function. Ex: 5! = 120 10!
CAN SOMEONE HELP ME WITH THIS? Task 4: Testing for Overflow The Factorial function is an extremely fast growing function. Ex: 5! = 120 10! = 3628800 That second result is immense even though the driver or input has only doubled. In fact, the basic integer type (int) is quickly overwhelmed. What happens is that the 4 bytes that the basic integer type has available become all binary 1s. When you have the 32nd bit of a basic int become a 1, the number is actually interpreted as a negative number, because the Most Significant Bit of the 32 bits is used for sign representation. In fact, the Factorial grows so fast that the result is not accurate while the input is still in the teens. Crazy! To deal with a situation like that, one option is to use a type that has more capacity. The option we can use is the long integer type (long). You will find in the course of this assignment that the long gets overwhelmed by Factorial pretty quickly too. (It does not get pass double digits.) So finally, you are going to try a double and find where the double will be overwhelmed. Suffice to say that Factorial will overwhelm them all. In order to test for these situations you can use trial-and-error, that is you can keep running the program over and over until you figure out at what value of n the factorial result is no longer trustworthy. However, you are sitting at a computer, and you are a programmer, so you can automate that process. Deliverable 4: Write out your Program Design for how to automate the testing. The objective is to repeat the factorial calculation for different values of n, as n changes from 2, 3, 4, 5, Based on what you know so far, how would you achieve that? Think carefully. Deliverable 5: int test Include a screenshot of your testing for an int. According to your testing at what value is the factorial no longer reliable. Deliverable 6: long test Include a screenshot of your testing for a long. According to your testing at what value is the factorial no longer reliable. Deliverable 7: double test Include a screenshot of your testing for an double. According to your testing at what value is the factorial no longer reliable. Deliverable 8: (Extra Credit) The Fix? So how do we find factorials for larger numbers? What kind of data type would allow that? long int factorial(int N)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started