We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 83760b8 commit d1c6d4dCopy full SHA for d1c6d4d
exercise-2.1.cpp
@@ -0,0 +1,27 @@
1
+#include <cassert>
2
+#include <iostream>
3
+#include "my_intrinsics.h"
4
+#include "my_type_functions.h"
5
+
6
+using namespace std;
7
8
+bool p(int a, int b) {
9
+ if (a < 0) return b >= INT_MIN - a;
10
+ if (a > 0) return b <= INT_MAX - a;
11
+ return true;
12
+}
13
14
+bool p2(int a, int b) {
15
+ assert(sizeof(long long) > sizeof(int));
16
+ long long sum = (long long) a + b;
17
+ return sum >= INT_MIN && sum <= INT_MAX;
18
19
20
+int main() {
21
+ cout << boolalpha;
22
+ cout << p2(INT_MIN, -1) << endl;
23
+ cout << p2(INT_MAX, 1) << endl;
24
+ cout << p2(INT_MIN / 2, INT_MIN / 2) << endl;
25
+ cout << p2(INT_MAX / 2, INT_MAX / 2) << endl;
26
+ cout << p2(INT_MAX / 2 + 1, INT_MAX / 2 + 1) << endl;
27
0 commit comments