Question: #include #include #include #include #include q5.h int saturating_add(int x, int y); { //Solution needed here. } //////////////////////////////////////////////////////////////// // test code void test_sat_1_plus_1() { assert(saturating_add(1,1) ==

 #include #include #include #include #include "q5.h" int saturating_add(int x, int y);

#include #include #include #include

#include "q5.h"

int saturating_add(int x, int y);

{

//Solution needed here.

}

//////////////////////////////////////////////////////////////// // test code void test_sat_1_plus_1() { assert(saturating_add(1,1) == 2); } void test_neg_ov() { assert(saturating_add(INT_MIN, -5) == INT_MIN); assert(saturating_add(INT_MIN, INT_MIN) == INT_MIN); } void test_pos_ov() { assert(saturating_add(INT_MAX, 1) == INT_MAX); } void test_big_pos_ov() { assert(saturating_add(INT_MAX, INT_MAX) == INT_MAX); } int main() { std::cout

5. (5 marks) Write code for a function with the following prototype: /Addition that saturates to TMin or TMax int saturating_add(int x, int y); Instead of overflowing the way normal twos-complement addition does, satu- rating addition returns INT_MAX when there would be positive overflow, and INT_MIN when there would be negative overflow. Saturating arithmetic is com- monly used in programs that perform digital signal processing. Your function should follow the bit-level integer coding rules above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!