| ... | ... | @@ -1766,6 +1766,7 @@ test "parseInt" { |
| 1766 | 1766 | try std.testing.expect((try parseInt(u8, "+0", 10)) == 0); |
| 1767 | 1767 | |
| 1768 | 1768 | // ensure minInt is parsed correctly |
| 1769 | try std.testing.expect((try parseInt(i1, "-1", 10)) == math.minInt(i1)); |
| 1769 | 1770 | try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8)); |
| 1770 | 1771 | try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43)); |
| 1771 | 1772 | |
| ... | ... | @@ -1847,7 +1848,15 @@ fn parseWithSign( |
| 1847 | 1848 | if (c == '_') continue; |
| 1848 | 1849 | const digit = try charToDigit(c, buf_base); |
| 1849 | 1850 | |
| 1850 | | if (x != 0) x = try math.mul(T, x, math.cast(T, buf_base) orelse return error.Overflow); |
| 1851 | if (x != 0) { |
| 1852 | x = try math.mul(T, x, math.cast(T, buf_base) orelse return error.Overflow); |
| 1853 | } else if (sign == .neg) { |
| 1854 | // The first digit of a negative number. |
| 1855 | // Consider parsing "-4" as an i3. |
| 1856 | // This should work, but positive 4 overflows i3, so we can't cast the digit to T and subtract. |
| 1857 | x = math.cast(T, -@intCast(i8, digit)) orelse return error.Overflow; |
| 1858 | continue; |
| 1859 | } |
| 1851 | 1860 | x = try add(T, x, math.cast(T, digit) orelse return error.Overflow); |
| 1852 | 1861 | } |
| 1853 | 1862 | |