Skip to content

Commit 22ec619

Browse files
committed
fixing conflicts
2 parents adf0bc4 + bf28864 commit 22ec619

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

quaddtype/numpy_quaddtype/src/casts.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,7 @@ inline npy_half
13491349
from_quad<spec_npy_half>(const quad_value *x, QuadBackendType backend)
13501350
{
13511351
if (backend == BACKEND_SLEEF) {
1352-
double d = cast_sleef_to_double(x->sleef_value);
1353-
return npy_double_to_half(d);
1352+
return npy_double_to_half(cast_sleef_to_double(x->sleef_value));
13541353
}
13551354
else {
13561355
return npy_double_to_half((double)x->longdouble_value);

quaddtype/numpy_quaddtype/src/ops.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,6 @@ ld_logical_not(const long double *a)
16541654
return !ld_is_nonzero(a);
16551655
}
16561656

1657-
16581657
// Casting operations
16591658
static inline double
16601659
cast_sleef_to_double(const Sleef_quad in)

quaddtype/tests/test_quaddtype.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,7 +5369,6 @@ def test_hash_backends(self, backend):
53695369
quad_val = QuadPrecision(1.5, backend=backend)
53705370
assert hash(quad_val) == hash(1.5)
53715371

5372-
53735372
@pytest.mark.parametrize("src_backend,dst_backend", [
53745373
("sleef", "longdouble"),
53755374
("longdouble", "sleef"),
@@ -5378,7 +5377,7 @@ def test_hash_backends(self, backend):
53785377
])
53795378
@pytest.mark.parametrize("value", [
53805379
"0.0", "-0.0", "1.0", "-1.0", "3.14159265358979323846",
5381-
"inf", "-inf", "nan", "1e100", "1e-100",
5380+
"inf", "-inf", "nan", "1e100", "1e-100", "-nan"
53825381
])
53835382
def test_quad_to_quad_backend_casting(src_backend, dst_backend, value):
53845383
"""Test casting between QuadPrecDType with different backends."""
@@ -5390,6 +5389,7 @@ def test_quad_to_quad_backend_casting(src_backend, dst_backend, value):
53905389
expected_backend = 0 if dst_backend == 'sleef' else 1
53915390
assert dst_arr.dtype.backend == expected_backend
53925391

5392+
assert np.signbit(src_arr[0]) == np.signbit(dst_arr[0])
53935393
if np.isnan(src_arr[0]):
53945394
assert np.isnan(dst_arr[0])
53955395
elif np.isinf(src_arr[0]):
@@ -5665,4 +5665,17 @@ def test_quad_to_quad_same_backend_always_passes(self, backend):
56655665
result = src.astype(QuadPrecDType(backend=backend), casting="same_value")
56665666
# Should not raise, and value should be unchanged
56675667
assert str(result[0]) == str(src[0])
5668-
5668+
5669+
# quad -> float will be tested in same_values tests
5670+
@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64, np.longdouble])
5671+
@pytest.mark.parametrize("val", [0.0, -0.0, float('inf'), float('-inf'), float('nan'), float("-nan")])
5672+
def test_float_to_quad_sign_preserve(dtype, val):
5673+
"""Test that special floating-point values roundtrip correctly."""
5674+
src = np.array([val], dtype=dtype)
5675+
result = src.astype(QuadPrecDType())
5676+
5677+
assert np.signbit(result) == np.signbit(val), f"Sign bit failed for {dtype} with value {val}"
5678+
if np.isnan(val):
5679+
assert np.isnan(result), f"NaN failed for {dtype}"
5680+
else:
5681+
assert result == val, f"{val} failed for {dtype}"

0 commit comments

Comments
 (0)