MCPcopy Create free account
hub / github.com/apache/datafusion / test_pmod_float32

Function test_pmod_float32

datafusion/spark/src/function/math/modulus.rs:526–581  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

524
525 #[test]
526 fn test_pmod_float32() {
527 let left = Float32Array::from(vec![
528 Some(10.5),
529 Some(-7.2),
530 Some(15.8),
531 Some(-15.8),
532 Some(f32::NAN),
533 Some(f32::INFINITY),
534 Some(5.0),
535 Some(-5.0),
536 Some(10.5),
537 Some(-7.2),
538 ]);
539 let right = Float32Array::from(vec![
540 Some(3.0),
541 Some(3.0),
542 Some(4.2),
543 Some(4.2),
544 Some(2.0),
545 Some(2.0),
546 Some(f32::INFINITY),
547 Some(f32::INFINITY),
548 Some(0.0),
549 Some(0.0),
550 ]);
551
552 let left_value = ColumnarValue::Array(Arc::new(left));
553 let right_value = ColumnarValue::Array(Arc::new(right));
554
555 let result = spark_pmod(&[left_value, right_value], false).unwrap();
556
557 if let ColumnarValue::Array(result_array) = result {
558 let result_float32 = result_array
559 .as_any()
560 .downcast_ref::<Float32Array>()
561 .unwrap();
562 // Regular cases
563 assert!((result_float32.value(0) - 1.5).abs() < f32::EPSILON); // 10.5 pmod 3.0 = 1.5
564 assert!((result_float32.value(1) - 1.8).abs() < f32::EPSILON * 3.0); // -7.2 pmod 3.0 = 1.8 (positive)
565 assert!((result_float32.value(2) - 3.2).abs() < f32::EPSILON * 10.0); // 15.8 pmod 4.2 = 3.2
566 assert!((result_float32.value(3) - 1.0).abs() < f32::EPSILON * 10.0); // -15.8 pmod 4.2 = 1.0 (positive)
567 // nan pmod 2.0 = nan
568 assert!(result_float32.value(4).is_nan());
569 // inf pmod 2.0 = nan (IEEE 754)
570 assert!(result_float32.value(5).is_nan());
571 // 5.0 pmod inf = 5.0
572 assert!((result_float32.value(6) - 5.0).abs() < f32::EPSILON * 10.0);
573 // -5.0 pmod inf = NaN
574 assert!(result_float32.value(7).is_nan());
575 // Division by zero returns NULL
576 assert!(result_float32.is_null(8)); // 10.5 pmod 0.0 = NULL
577 assert!(result_float32.is_null(9)); // -7.2 pmod 0.0 = NULL
578 } else {
579 panic!("Expected array result");
580 }
581 }
582
583 #[test]

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
spark_pmodFunction · 0.85
as_anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…