Skip to content

Commit 9d57423

Browse files
committed
applying other reviews
1 parent 34c9c6d commit 9d57423

2 files changed

Lines changed: 3 additions & 36 deletions

File tree

src/csrc/scalar.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,6 @@ QuadPrecision_str_dragon4(QuadPrecisionObject *self)
329329
}
330330
}
331331

332-
static PyObject *
333-
QuadPrecision_str(QuadPrecisionObject *self)
334-
// This is just define here for debugging, we actually use QuadPrecision_str_dragon4 for __str__ method.
335-
{
336-
char buffer[128];
337-
if (self->backend == BACKEND_SLEEF) {
338-
Sleef_snprintf(buffer, sizeof(buffer), "%.*Qe", SLEEF_QUAD_DIG, self->value.sleef_value);
339-
}
340-
else {
341-
snprintf(buffer, sizeof(buffer), "%.*Le", LDBL_DECIMAL_DIG - 1,
342-
self->value.longdouble_value);
343-
}
344-
return PyUnicode_FromString(buffer);
345-
}
346-
347332
static PyObject *
348333
QuadPrecision_repr_dragon4(QuadPrecisionObject *self)
349334
{

tests/test_quaddtype.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,7 +5379,6 @@ class TestScalarPickle:
53795379

53805380
@pytest.mark.parametrize("backend", ["sleef", "longdouble"])
53815381
def test_pickle_scalar_issue_repro(self, backend):
5382-
"""The exact repro from #99: was RuntimeError on loads()."""
53835382
import pickle
53845383
original = QuadPrecision("123.456", backend=backend)
53855384
loaded = pickle.loads(pickle.dumps(original))
@@ -5402,9 +5401,7 @@ def test_pickle_scalar_finite_roundtrip(self, backend, value):
54025401
loaded = pickle.loads(pickle.dumps(original))
54035402
assert isinstance(loaded, QuadPrecision)
54045403
assert loaded.dtype == QuadPrecDType(backend=backend)
5405-
# Exact equality: pickle/unpickle should not lose any bits.
54065404
assert loaded == original
5407-
# And the canonical repr should match.
54085405
assert str(loaded) == str(original)
54095406

54105407
@pytest.mark.parametrize("backend", ["sleef", "longdouble"])
@@ -5414,7 +5411,7 @@ def test_pickle_scalar_inf(self, backend):
54145411
original = QuadPrecision(s, backend=backend)
54155412
loaded = pickle.loads(pickle.dumps(original))
54165413
assert isinstance(loaded, QuadPrecision)
5417-
assert loaded == original # inf == inf, -inf == -inf
5414+
assert loaded == original
54185415
assert float(loaded) == float(original)
54195416

54205417
@pytest.mark.parametrize("backend", ["sleef", "longdouble"])
@@ -5423,7 +5420,6 @@ def test_pickle_scalar_nan(self, backend):
54235420
original = QuadPrecision("nan", backend=backend)
54245421
loaded = pickle.loads(pickle.dumps(original))
54255422
assert isinstance(loaded, QuadPrecision)
5426-
# NaN != NaN, so we check isnan instead.
54275423
import math
54285424
assert math.isnan(float(loaded))
54295425
assert loaded.dtype == QuadPrecDType(backend=backend)
@@ -5447,13 +5443,9 @@ def test_pickle_scalar_preserves_type(self):
54475443

54485444
@pytest.mark.parametrize("backend", ["sleef", "longdouble"])
54495445
def test_pickle_scalar_preserves_full_precision(self, backend):
5450-
"""Diagnostic precision-loss test. Two values with the same printed
5451-
repr can still differ at the full bit width, so check via subtraction
5452-
(which preserves precision) — `loaded - original` must be exactly zero.
5453-
Catches the regression where the longdouble path went through (double)."""
5446+
"""Compare via subtraction, not repr: two values with the same printed
5447+
repr can still differ at the full bit width."""
54545448
import pickle
5455-
# A value with more than 16 significant digits — exercises precision
5456-
# beyond what double can represent.
54575449
original = QuadPrecision("3.14159265358979323846264338327950288",
54585450
backend=backend)
54595451
loaded = pickle.loads(pickle.dumps(original))
@@ -5487,16 +5479,6 @@ def test_pickle_scalar_in_list(self):
54875479
assert math.isnan(float(loaded[2]))
54885480
assert loaded[3] == original[3]
54895481

5490-
@pytest.mark.parametrize("backend", ["sleef", "longdouble"])
5491-
def test_pickle_scalar_loads_does_not_raise(self, backend):
5492-
"""Direct regression on the exact failure mode in the bug report
5493-
(RuntimeError from numpy's legacy SETITEM path)."""
5494-
import pickle
5495-
try:
5496-
pickle.loads(pickle.dumps(QuadPrecision("123.456", backend=backend)))
5497-
except RuntimeError as exc:
5498-
pytest.fail(f"pickle.loads raised RuntimeError: {exc}")
5499-
55005482

55015483
@pytest.mark.parametrize("dtype", [
55025484
"bool",

0 commit comments

Comments
 (0)