findepi commented on PR #13590:
URL: https://github.com/apache/datafusion/pull/13590#issuecomment-2518507421

   > * Use rounding in the SLT engine for all floats. Don't use rounding for 
decimal.
   
   That would be my almost preferred way.
   internally at SDF we also use SLT tests (separate suites of tests) and 
rounding - albeit imperfect - works for us so far.
   
   the code goes something like
   
   ```rust
   fn f64_to_str(value: f64) -> String {
       // TODO compare float values with epsilon. As a workaround the rendering 
precision is reduced.
       float_to_str(value, 10)
   }
   
   fn float_to_str(value: f64, max_significant_digits: u8) -> String {
       if value.is_nan() {
           // The sign of NaN can be different depending on platform.
           // So the string representation of NaN ignores the sign.
           "NaN".to_string()
       } else if value == f64::INFINITY {
           "Infinity".to_string()
       } else if value == f64::NEG_INFINITY {
           "-Infinity".to_string()
       } else {
           let mut big_decimal = BigDecimal::from_f64(value)
               .unwrap()
               // Truncate trailing decimal zeros
               .normalized();
           let precision = big_decimal.digits();
           if precision > max_significant_digits as u64 {
               let scale = big_decimal.as_bigint_and_exponent().1;
               big_decimal = big_decimal
                   .with_scale_round(
                       scale + (max_significant_digits as i64 - precision as 
i64),
                       RoundingMode::HalfUp,
                   )
                   // Truncate trailing decimal zeros
                   .normalized();
           }
           big_decimal.to_string()
       }
   }
   ```
   
   A better way would be to interpret the values with an epsilon, but that will 
be hard to do in SLT which relies on the rows being stringified before 
comparison.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to