/home/uke/oil/mycpp/gc_mops.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "mycpp/gc_mops.h" |
2 | | |
3 | | #include <errno.h> |
4 | | #include <stdio.h> |
5 | | |
6 | | #include "mycpp/gc_alloc.h" |
7 | | #include "mycpp/gc_builtins.h" // StringToInt64 |
8 | | #include "mycpp/gc_str.h" |
9 | | |
10 | | namespace mops { |
11 | | |
12 | | const BigInt ZERO = BigInt{0}; |
13 | | const BigInt ONE = BigInt{1}; |
14 | | const BigInt MINUS_ONE = BigInt{-1}; |
15 | | |
16 | | static const int kInt64BufSize = 32; // more than twice as big as kIntBufSize |
17 | | |
18 | | // Copied from gc_builtins - str(int i) |
19 | 0 | BigStr* ToStr(BigInt b) { |
20 | 0 | BigStr* s = OverAllocatedStr(kInt64BufSize); |
21 | 0 | int length = snprintf(s->data(), kInt64BufSize, "%ld", b); |
22 | 0 | s->MaybeShrink(length); |
23 | 0 | return s; |
24 | 0 | } |
25 | | |
26 | | // Copied from gc_builtins - to_int() |
27 | 0 | BigInt FromStr(BigStr* s, int base) { |
28 | 0 | int64_t i; |
29 | 0 | if (StringToInt64(s->data_, len(s), base, &i)) { |
30 | 0 | return i; |
31 | 0 | } else { |
32 | 0 | throw Alloc<ValueError>(); |
33 | 0 | } |
34 | 0 | } |
35 | | |
36 | | } // namespace mops |