@@ -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])
53835382def 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