-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
70 lines (65 loc) · 1.61 KB
/
test.cpp
File metadata and controls
70 lines (65 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <cstdlib>
extern "C"{
#include "Int64.h"
}
using namespace std;
Int64 set(long long int a)
{
Int64 ret;
int* p = (int*)(&a);
ret.low = *p++;
ret.hi = *p;
return ret;
}
long long int get (Int64 x)
{
union
{
long long int a;
int p[2];
};
p[0] = x.low;
p[1] = x.hi;
return a;
}
void test (long long int a, long long int b)
{
Int64 m, n;
m = set(a);
n = set(b);
cout << a << " vs " << b << endl << endl;
if (a+b != get(Int64_plus(m, n)))
cout << a+b << ":" << get(Int64_plus(m, n)) << endl << "Error!" << endl << endl;
else
cout << a+b << endl << "OK" << endl << endl;
if (a-b != get(Int64_minus(m, n)))
cout << a-b << ":" << get(Int64_plus(m, n)) << endl << "Error!" << endl << endl;
else
cout << a-b << endl << "OK" << endl << endl;
if (a*b != get(Int64_multi(m, n)))
cout << a*b << ":" << get(Int64_plus(m, n)) << endl << "Error!" << endl << endl;
else
cout << a*b << endl << "OK" << endl << endl;
if (a/b != get(Int64_div(m, n)))
cout << a/b << ":" << get(Int64_plus(m, n)) << endl << "Error!" << endl << endl;
else
cout << a/b << endl << "OK" << endl << endl;
}
int main()
{
test (1, -1);
test (0, 1);
test (35, 30);
test (60, 30);
test (1000, 34);
test (-234872, 8742);
test (0x70000000000, 0x80000001);
test (0x398748297342, 0x7FFFFFFF);
test (0x70000000000, 0x98374234);
test (0x34627834687, 0x83648924);
test (0xFF80000000000000, 0x8000000000);
test (-4, -1);
test (0xFFF2394729834342, 0xFF34257438453824);
test (2985952495825, 22525398235235);
}