Skip to content

Commit 067a389

Browse files
committed
boolens dont requrie overflow handling
1 parent 1eb5202 commit 067a389

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

quaddtype/numpy_quaddtype/src/scalar.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -120,37 +120,20 @@ QuadPrecision_from_object(PyObject *value, QuadBackendType backend)
120120
return NULL;
121121
}
122122

123-
int overflow = 0;
124-
long long lval = PyLong_AsLongLongAndOverflow(py_int, &overflow);
123+
// Booleans are always 0 or 1, so no overflow check needed
124+
long long lval = PyLong_AsLongLong(py_int);
125+
Py_DECREF(py_int);
125126

126-
if (overflow != 0) {
127-
// Integer is too large, convert to string and recursively call this function
128-
PyObject *str_obj = PyObject_Str(py_int);
129-
Py_DECREF(py_int);
130-
if (str_obj == NULL) {
131-
Py_DECREF(self);
132-
return NULL;
133-
}
134-
135-
// Recursively convert from string
136-
QuadPrecisionObject *result = QuadPrecision_from_object(str_obj, backend);
137-
Py_DECREF(str_obj);
138-
Py_DECREF(self); // discard the default one
139-
return result;
140-
}
141-
else if (lval == -1 && PyErr_Occurred()) {
142-
Py_DECREF(py_int);
127+
if (lval == -1 && PyErr_Occurred()) {
143128
Py_DECREF(self);
144129
return NULL;
145130
}
131+
132+
if (backend == BACKEND_SLEEF) {
133+
self->value.sleef_value = Sleef_cast_from_int64q1(lval);
134+
}
146135
else {
147-
Py_DECREF(py_int);
148-
if (backend == BACKEND_SLEEF) {
149-
self->value.sleef_value = Sleef_cast_from_int64q1(lval);
150-
}
151-
else {
152-
self->value.longdouble_value = (long double)lval;
153-
}
136+
self->value.longdouble_value = (long double)lval;
154137
}
155138
return self;
156139
}

0 commit comments

Comments
 (0)