diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2018-07-28 18:39:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-28 18:39:15 +0100 |
| commit | 8d2c4a78a19774d98f5603d78ab6520f39d18bcd (patch) | |
| tree | 95284815f9ec477819bbfd65e90c7cdae757a878 /src/check_stmt.cpp | |
| parent | 1ab40d86009ff569b66650eb35b050a68e11df89 (diff) | |
| parent | 8504ff920b057007382bbeefcaa8a40e35689526 (diff) | |
Merge pull request #238 from odin-lang/big-int
Big int
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 3ce7373b6..453127f0c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -260,18 +260,17 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) if (rhs->mode == Addressing_Constant) { ExactValue v = exact_value_to_integer(rhs->value); if (v.kind == ExactValue_Integer) { - i64 i = v.value_integer; - u64 u = bit_cast<u64>(i); - u64 umax = ~cast(u64)0ull; - if (lhs_bits < 64) { - umax = (1ull << cast(u64)lhs_bits) - 1ull; - } - i64 imax = 1ll << (cast(i64)lhs_bits-1ll); - - bool ok = !(u < 0 || u > umax); + BigInt i = v.value_integer; + if (!i.neg) { + u64 imax_ = ~cast(u64)0ull; + if (lhs_bits < 64) { + imax_ = (1ull << cast(u64)lhs_bits) - 1ull; + } - if (ok) { - return rhs->type; + BigInt imax = big_int_make_u64(imax_); + if (big_int_cmp(&i, &imax) > 0) { + return rhs->type; + } } } } else if (is_type_integer(rhs->type)) { |