Article 4QFGM Determine if x-y will overflow in c

Determine if x-y will overflow in c

by
Portal
from LinuxQuestions.org on (#4QFGM)
I have the following homework question:

Code:Write a function with the following prototype:
/* Determine whether arguments can be subtracted without overflow */
int tsub_ok(int x, int y);
This function should return 1 if the computation x - y does not overflow(I am only allowed to use bit-level and logic operation, shifts, and c constants; the code should be straight line with no conditionals, loops, division, modulus, multiplication, or relative comparison operators. Assume 2's complement for signed binaries with w-bit word size)
I want to check for positive overflow and negative overflow respectively and do a bitwise-or. But I don't know how to do each respectively. Any hints?latest?d=yIl2AUoC8zA latest?i=H4ruXDT4p8U:O0V3I_Uut7I:F7zBnMy latest?i=H4ruXDT4p8U:O0V3I_Uut7I:V_sGLiP latest?d=qj6IDK7rITs latest?i=H4ruXDT4p8U:O0V3I_Uut7I:gIN9vFwH4ruXDT4p8U
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments