Skip to content

Commit 6727239

Browse files
committed
special case tests
1 parent 53e663a commit 6727239

File tree

1 file changed

+29
-44
lines changed

1 file changed

+29
-44
lines changed

quaddtype/tests/test_quaddtype.py

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,60 +3000,45 @@ def test_frexp_zero(self, x_val):
30003000
@pytest.mark.parametrize("x_val", [
30013001
"inf",
30023002
"-inf",
3003-
])
3004-
def test_frexp_inf(self, x_val):
3005-
"""Test frexp with infinity (should return ±inf mantissa, exponent 0)"""
3006-
quad_x = QuadPrecision(x_val)
3007-
3008-
quad_m, quad_e = np.frexp(quad_x)
3009-
3010-
# Mantissa should be infinity with same sign
3011-
assert np.isinf(quad_m), f"Mantissa should be infinity for frexp({x_val})"
3012-
assert np.signbit(quad_m) == np.signbit(quad_x), \
3013-
f"Sign mismatch for frexp({x_val}) mantissa"
3014-
3015-
# Exponent should be 0
3016-
assert quad_e == 0, f"Exponent should be 0 for frexp({x_val})"
3017-
3018-
# Compare with NumPy float64
3019-
float_x = np.float64(x_val)
3020-
float_m, float_e = np.frexp(float_x)
3021-
3022-
# Both should be infinity with same sign
3023-
assert np.isinf(float_m), f"NumPy mantissa should also be infinity for frexp({x_val})"
3024-
assert np.signbit(quad_m) == np.signbit(float_m), \
3025-
f"Sign mismatch with NumPy for frexp({x_val})"
3026-
3027-
# Exponent should match
3028-
assert quad_e == float_e, \
3029-
f"Exponent mismatch with NumPy for frexp({x_val}): {quad_e} != {float_e}"
3030-
3031-
@pytest.mark.parametrize("x_val", [
30323003
"nan",
30333004
"-nan",
30343005
])
3035-
def test_frexp_nan(self, x_val):
3036-
"""Test frexp with NaN (should return NaN mantissa, exponent 0)"""
3006+
def test_frexp_special_values(self, x_val):
3007+
"""Test frexp with special values (inf, nan)
3008+
3009+
For these edge cases, the C standard specifies that the exponent value
3010+
is unspecified/implementation-defined. We only verify that:
3011+
1. The mantissa matches the expected value (±inf or NaN)
3012+
2. The mantissa behavior matches NumPy's float64
3013+
3. The exponent is an integer type
3014+
3015+
We do NOT compare exponent values as they can differ across platforms
3016+
(e.g., Linux returns 0, Windows returns -1).
3017+
"""
30373018
quad_x = QuadPrecision(x_val)
3038-
30393019
quad_m, quad_e = np.frexp(quad_x)
30403020

3041-
# Mantissa should be NaN
3042-
assert np.isnan(quad_m), f"Mantissa should be NaN for frexp({x_val})"
3043-
3044-
# Exponent should be 0
3045-
assert quad_e == 0, f"Exponent should be 0 for frexp({x_val})"
3046-
30473021
# Compare with NumPy float64
30483022
float_x = np.float64(x_val)
30493023
float_m, float_e = np.frexp(float_x)
30503024

3051-
# Both should be NaN
3052-
assert np.isnan(float_m), f"NumPy mantissa should also be NaN for frexp({x_val})"
3053-
3054-
# Exponent should match
3055-
assert quad_e == float_e, \
3056-
f"Exponent mismatch with NumPy for frexp({x_val}): {quad_e} != {float_e}"
3025+
# Exponent should be an integer type (but we don't check the value)
3026+
assert isinstance(quad_e, (int, np.integer)), \
3027+
f"Exponent should be integer type for frexp({x_val})"
3028+
3029+
# Check mantissa behavior
3030+
if "inf" in x_val:
3031+
# Mantissa should be infinity with same sign
3032+
assert np.isinf(quad_m), f"Mantissa should be infinity for frexp({x_val})"
3033+
assert np.isinf(float_m), f"NumPy mantissa should also be infinity for frexp({x_val})"
3034+
assert np.signbit(quad_m) == np.signbit(quad_x), \
3035+
f"Sign mismatch for frexp({x_val}) mantissa"
3036+
assert np.signbit(quad_m) == np.signbit(float_m), \
3037+
f"Sign mismatch with NumPy for frexp({x_val})"
3038+
else: # nan
3039+
# Mantissa should be NaN
3040+
assert np.isnan(quad_m), f"Mantissa should be NaN for frexp({x_val})"
3041+
assert np.isnan(float_m), f"NumPy mantissa should also be NaN for frexp({x_val})"
30573042

30583043
def test_frexp_very_large(self):
30593044
"""Test frexp with very large values"""

0 commit comments

Comments
 (0)