Question: You are given the assignment to develop code for a function tmult_ok that will determine whether two arguments can be multiplied without causing overflow. Here

You are given the assignment to develop code for a function tmult_ok that will determine whether two arguments can be multiplied without causing overflow. Here is your solution:

/* Determine whether arguments can be multiplied without overflow */ int tmult_ok (int x, int y) { } int p =You test this code for a number of values of x and y, and it seems to work properly. Your coworker challenges you, saying, "If I can't use subtraction to test whether addition has overflowed (see Problem 2.31), then how can you use division to test whether multiplication has overflowed?" Devise a mathematical justification of your approach, along the following lines. First, argue that the case x = 0 is handled correctly. Otherwise, consider w-bit numbers x (x ≠ 0), y, p, and q, where p is the result of performing two's complement multiplication on x and y, and q is the result of dividing p by x.
Problem 2.31

Your coworker gets impatient with your analysis of the overflow conditions for two’s-complement addition and presents you with the following implementation of tadd_ok:

/* Determine whether arguments can be added without overflow */ /*WARNING: This code is buggy. */ int tadd_ok

You look at the code and laugh. Explain why.

/* Determine whether arguments can be multiplied without overflow */ int tmult_ok (int x, int y) { } int p = x*y; /* Either x is zero, or dividing p by x gives y */ return !x p/x == y;

Step by Step Solution

3.48 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It is not realistic to test this function for all possible values of x and y Even if you could run 1... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Systems A Programmers Perspective Questions!