@@ -2255,6 +2255,7 @@ def test_direction(self):
22552255                assert  result  >  q_x , f"nextafter({ x } { y } { x } { result }  
22562256            elif  expected_dir  ==  "less" :
22572257                assert  result  <  q_x , f"nextafter({ x } { y } { x } { result }  
2258+ 
22582259class  TestSpacing :
22592260    """Test cases for np.spacing function with QuadPrecision dtype""" 
22602261
@@ -2341,7 +2342,7 @@ def test_one_and_negative_one(self, x):
23412342        0.5 , - 0.5 , 
23422343        0.25 , - 0.25 , 
23432344    ]) 
2344-     def  test_positive_magnitude (self , x ):
2345+     def  test_spacing_is_non_zero (self , x ):
23452346        """Test that spacing always has positive magnitude""" 
23462347        q_x  =  QuadPrecision (x )
23472348        result  =  np .spacing (q_x )
@@ -2429,3 +2430,30 @@ def test_subnormal_range(self, x):
24292430            assert  np .signbit (result ) ==  np .signbit (q_x ), \
24302431                f"spacing({ x } { x }  
24312432
2433+     def  test_smallest_normal_spacing (self ):
2434+         """Test spacing for smallest normal value and 2*smallest normal""" 
2435+         finfo  =  np .finfo (QuadPrecDType ())
2436+         smallest_normal  =  finfo .smallest_normal 
2437+         
2438+         # Test spacing at smallest normal value 
2439+         result1  =  np .spacing (smallest_normal )
2440+         
2441+         # Test spacing at 2 * smallest normal value 
2442+         two_smallest_normal  =  2  *  smallest_normal 
2443+         result2  =  np .spacing (two_smallest_normal )
2444+         
2445+         q_zero  =  QuadPrecision ("0" )
2446+         
2447+         # spacing(smallest_normal) should be smallest_subnormal 
2448+         # (the spacing at the boundary between subnormal and normal range) 
2449+         expected1  =  finfo .smallest_subnormal 
2450+         assert  result1  ==  expected1 , \
2451+             f"spacing(smallest_normal) should be { expected1 } { result1 }  
2452+         assert  result1  >  q_zero , "Result should be positive" 
2453+         
2454+         # The scaling relationship: spacing(2*x) = 2*spacing(x) for normal numbers 
2455+         expected2  =  2  *  finfo .smallest_subnormal 
2456+         assert  result2  ==  expected2 , \
2457+             f"spacing(2*smallest_normal) should be { expected2 } { result2 }  
2458+         assert  result2  >  q_zero , "Result should be positive" 
2459+ 
0 commit comments