alamb commented on issue #7939:
URL: https://github.com/apache/arrow-rs/issues/7939#issuecomment-3107366092

   # `f64` test:
   
   I wrote a test for f64 like this
   ```rust
       #[test]
       fn test_cast_decimal128_to_f64_overflow() {
           // Test positive overflow (positive infinity)
           let array = vec![Some(i128::MAX)];
           let array = create_decimal128_array(array, 25, 2).unwrap();
           let array = Arc::new(array) as ArrayRef;
   
           let result = cast(&array, &DataType::Float64).unwrap();
           let result = result.as_primitive::<Float64Type>();
           assert!(result.value(0).is_infinite());
           assert!(result.value(0) > 0.0); // Positive infinity
   
           // Test negative overflow (negative infinity)
           let array = vec![Some(i128::MIN)];
           let array = create_decimal128_array(array, 25, 2).unwrap();
           let array = Arc::new(array) as ArrayRef;
   
           let result = cast(&array, &DataType::Float64).unwrap();
           let result = result.as_primitive::<Float64Type>();
           assert!(result.value(0).is_infinite());
           assert!(result.value(0) < 0.0); // Negative infinity
       }
   ```
   
   And it fails like this
   ```rust
   
   assertion failed: result.value(0).is_infinite()
   thread 'cast::tests::test_cast_decimal128_to_f64_overflow' panicked at 
arrow-cast/src/cast/mod.rs:8655:9:
   assertion failed: result.value(0).is_infinite()
   stack backtrace:
      0: __rustc::rust_begin_unwind
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
      1: core::panicking::panic_fmt
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
      2: core::panicking::panic
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:145:5
      3: arrow_cast::cast::tests::test_cast_decimal128_to_f64_overflow
                at ./src/cast/mod.rs:8655:9
      4: 
arrow_cast::cast::tests::test_cast_decimal128_to_f64_overflow::{{closure}}
                at ./src/cast/mod.rs:8647:46
      5: core::ops::function::FnOnce::call_once
                at 
/Users/andrewlamb/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
      6: core::ops::function::FnOnce::call_once
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/ops/function.rs:250:5
   note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 
backtrace.
   
   
   ```
   
   # `f32` test
   I wrote a test for f32 like this:
   
   ```rust
       #[test]
       fn test_cast_decimal128_to_f32_overflow() {
           // Test positive overflow (positive infinity)
           let array = vec![Some(i128::MAX)];
           let array = create_decimal128_array(array, 25, 2).unwrap();
           let array = Arc::new(array) as ArrayRef;
   
           let result = cast(&array, &DataType::Float32).unwrap();
           let result = result.as_primitive::<Float32Type>();
           assert!(result.value(0).is_infinite());
           assert!(result.value(0) > 0.0); // Positive infinity
   
           // Test negative overflow (negative infinity)
           let array = vec![Some(i128::MIN)];
           let array = create_decimal128_array(array, 25, 2).unwrap();
           let array = Arc::new(array) as ArrayRef;
   
           let result = cast(&array, &DataType::Float32).unwrap();
           let result = result.as_primitive::<Float32Type>();
           assert!(result.value(0).is_infinite());
           assert!(result.value(0) < 0.0); // Negative infinity
       }
   ```
   
   And it fails like this
   
   ```
   
   assertion failed: result.value(0).is_infinite()
   thread 'cast::tests::test_cast_decimal128_to_f32_overflow' panicked at 
arrow-cast/src/cast/mod.rs:8655:9:
   assertion failed: result.value(0).is_infinite()
   stack backtrace:
      0: __rustc::rust_begin_unwind
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
      1: core::panicking::panic_fmt
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
      2: core::panicking::panic
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:145:5
      3: arrow_cast::cast::tests::test_cast_decimal128_to_f32_overflow
                at ./src/cast/mod.rs:8655:9
      4: 
arrow_cast::cast::tests::test_cast_decimal128_to_f32_overflow::{{closure}}
                at ./src/cast/mod.rs:8647:46
      5: core::ops::function::FnOnce::call_once
                at 
/Users/andrewlamb/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
      6: core::ops::function::FnOnce::call_once
                at 
/rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/ops/function.rs:250:5
   note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 
backtrace.
   
   
   ```


-- 
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...@arrow.apache.org

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

Reply via email to