Question: You are assigned the task of writing code for a function tsub_ok, with arguments x and y, that will return 1 if computing x-y does

You are assigned the task of writing code for a function tsub_ok, with arguments x and y, that will return 1 if computing x-y does not cause overflow. Having just written the code for Problem 2.30, you write the following:

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

For what values of x and y will this function give incorrect results? Writing a correct version of this function is left as an exercise (Problem 2.74).

Problem 2.30

Write a function with the following prototype:

/* Determine whether arguments can be added without overflow */ int tadd_ok (int x, int y);

This function should return 1 if arguments x and y can be added without causing overflow.

Problem 2.74 

Write a function with the following prototype:

/* Determine whether arguments can be subtracted without overflow */ int tsub_ok (int x, int y);

We can represent a bit pattern of length w = 4 with a single hex digit. For a two’scomplement
interpretation of these digits, fill in the following table to determine
the additive inverses of the digits shown:This function should return 1 if the computation x-y does not overflow.

/* Determine whether arguments can be subtracted without overflow */ /* WARNING: This code is buggy. */ int tsub_ok (int x, int y) { return tadd_ok (x, -y); }

Step by Step Solution

3.61 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This function will give correct values except when y is TMin In this case we will have y als... 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!