berkaysynnada commented on PR #16745:
URL: https://github.com/apache/datafusion/pull/16745#issuecomment-3065030622

   Currently, when computing the next representable float from +0.0 or -0.0, 
the behavior incorrectly skips directly to the smallest subnormal (±ε) instead 
of transitioning between -0.0 and +0.0. For example, next_down(+0.0) returns 
-ε, but we expect it to return -0.0. Similarly, next_up(-0.0) returns +ε, but 
we expect it to return +0.0. 
   
   This causes intervals like [-0.0, -ε] instead of the expected [-0.0, -0.0]. 
In ScalarValue comparisons we already treat -0.0 and +0.0 as NOT equal, but the 
rounding logic was skipping over them and jumping directly to subnormals.
   
   To fix this, I locally updated next_up and next_down to handle ±0.0 
explicitly. In next_up, if the input is -0.0, it now returns +0.0 instead of 
+ε. In next_down, if the input is +0.0, it now returns -0.0 instead of -ε. All 
other cases remain as they were. This keeps the fix localized to the specific 
±0.0 boundary without unnecessarily affecting the general behavior of interval 
arithmetic logic. 
   
   ```rust
   pub fn next_up<F: FloatBits + Copy>(float: F) -> F {
       let bits = float.to_bits();
       if float.float_is_nan() || bits == F::infinity().to_bits() {
           return float;
       }
   
       // Special case: -0.0 → +0.0
       if bits == F::NEG_ZERO {
           return F::from_bits(F::ZERO);
       }
       ...
   ```
   ```rust
   pub fn next_down<F: FloatBits + Copy>(float: F) -> F {
       let bits = float.to_bits();
       if float.float_is_nan() || bits == F::neg_infinity().to_bits() {
           return float;
       }
       
       // Special case: +0.0 → -0.0
       if bits == F::ZERO {
           return F::from_bits(F::NEG_ZERO);
       }
       ...
   ```
   
   With these changes, the interval calculations now respect the special ±0.0 
representations before moving into the subnormal range. This aligns the 
rounding behavior with how ScalarValue comparisons already work and avoids 
producing unexpected intervals.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to