1 | #include "mycpp/gc_mops.h"
|
2 |
|
3 | #include "mycpp/runtime.h"
|
4 | #include "vendor/greatest.h"
|
5 |
|
6 | TEST bigint_test() {
|
7 | // You need to instantiate it as a BigInt, the constant (1) doesn't work
|
8 | // And also use %ld
|
9 |
|
10 | mops::BigInt i = mops::BigInt{1} << 31;
|
11 | log("bad i = %d", i); // bug
|
12 | log("good i = %ld", i);
|
13 | log("");
|
14 |
|
15 | mops::BigInt i2 = mops::BigInt{1} << 32;
|
16 | log("good i2 = %ld", i2);
|
17 | log("");
|
18 |
|
19 | mops::BigInt i3 = i2 + i2;
|
20 | log("good i3 = %ld", i3);
|
21 | log("");
|
22 |
|
23 | int64_t j = int64_t{1} << 31;
|
24 | log("bad j = %d", j); // bug
|
25 | log("good j = %ld", j);
|
26 |
|
27 | PASS();
|
28 | }
|
29 |
|
30 | TEST static_cast_test() {
|
31 | // These conversion ops are currently implemented by static_cast<>
|
32 |
|
33 | auto big = mops::BigInt{1} << 31;
|
34 |
|
35 | // Turns into a negative number
|
36 | int i = mops::BigTruncate(big);
|
37 | log("i = %d", i);
|
38 |
|
39 | // Truncates float to int. TODO: Test out Oils behavior.
|
40 | float f = 3.14f;
|
41 | auto fbig = mops::FromFloat(f);
|
42 | log("%f -> %ld", f, fbig);
|
43 |
|
44 | f = 3.99f;
|
45 | fbig = mops::FromFloat(f);
|
46 | log("%f = %ld", f, fbig);
|
47 |
|
48 | // OK this is an exact integer
|
49 | f = mops::ToFloat(big);
|
50 | log("f = %f", f);
|
51 | ASSERT_EQ_FMT(f, 2147483648.0, "%f");
|
52 |
|
53 | PASS();
|
54 | }
|
55 |
|
56 | GREATEST_MAIN_DEFS();
|
57 |
|
58 | int main(int argc, char** argv) {
|
59 | gHeap.Init();
|
60 |
|
61 | GREATEST_MAIN_BEGIN();
|
62 |
|
63 | RUN_TEST(bigint_test);
|
64 | RUN_TEST(static_cast_test);
|
65 |
|
66 | gHeap.CleanProcessExit();
|
67 |
|
68 | GREATEST_MAIN_END();
|
69 |
|
70 | return 0;
|
71 | }
|