Skip to content

Commit

Permalink
mpz("+123")
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Dec 31, 2024
1 parent 0ec099e commit a7ca058
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,14 @@ MPZ_from_str(PyObject *obj, int base)
goto err;
}

int8_t negative = (buf[0] == '-');
int8_t negative = (p[0] == '-');

p += negative;
len -= negative;
if (len && p[0] == '+') {
p++;
len--;
}
if (p[0] == '0' && len >= 2) {
if (base == 0) {
if (tolower(p[1]) == 'b') {
Expand All @@ -319,7 +323,7 @@ MPZ_from_str(PyObject *obj, int base)
p += 2;
len -= 2;
if (len && p[0] == '_') {
p += 1;
p++;
len--;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_mpz.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_mpz_interface():
with pytest.raises(TypeError):
mpz(1j, 10)
assert mpz() == mpz(0) == 0
assert mpz("+123") == 123

class with_int:
def __init__(self, value):
Expand Down

0 comments on commit a7ca058

Please sign in to comment.