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

Function test_mod_float32

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

Source from the content-addressed store, hash-verified

293
294 #[test]
295 fn test_mod_float32() {
296 let left = Float32Array::from(vec![
297 Some(10.5),
298 Some(7.2),
299 Some(15.8),
300 Some(f32::NAN),
301 Some(f32::INFINITY),
302 Some(5.0),
303 Some(5.0),
304 Some(f32::NAN),
305 Some(f32::INFINITY),
306 Some(10.5),
307 Some(15.8),
308 ]);
309 let right = Float32Array::from(vec![
310 Some(3.0),
311 Some(2.5),
312 Some(4.2),
313 Some(2.0),
314 Some(2.0),
315 Some(f32::NAN),
316 Some(f32::INFINITY),
317 Some(f32::INFINITY),
318 Some(f32::NAN),
319 Some(0.0),
320 Some(0.0),
321 ]);
322
323 let left_value = ColumnarValue::Array(Arc::new(left));
324 let right_value = ColumnarValue::Array(Arc::new(right));
325
326 let result = spark_mod(&[left_value, right_value], false).unwrap();
327
328 if let ColumnarValue::Array(result_array) = result {
329 let result_float32 = result_array
330 .as_any()
331 .downcast_ref::<Float32Array>()
332 .unwrap();
333 // Regular cases
334 assert!((result_float32.value(0) - 1.5).abs() < f32::EPSILON); // 10.5 % 3.0 = 1.5
335 assert!((result_float32.value(1) - 2.2).abs() < f32::EPSILON * 3.0); // 7.2 % 2.5 = 2.2
336 assert!((result_float32.value(2) - 3.2).abs() < f32::EPSILON * 10.0); // 15.8 % 4.2 = 3.2
337 // nan % 2.0 = nan
338 assert!(result_float32.value(3).is_nan());
339 // inf % 2.0 = nan (IEEE 754)
340 assert!(result_float32.value(4).is_nan());
341 // 5.0 % nan = nan
342 assert!(result_float32.value(5).is_nan());
343 // 5.0 % inf = 5.0
344 assert!((result_float32.value(6) - 5.0).abs() < f32::EPSILON);
345 // nan % inf = nan
346 assert!(result_float32.value(7).is_nan());
347 // inf % nan = nan
348 assert!(result_float32.value(8).is_nan());
349 // Division by zero returns NULL
350 assert!(result_float32.is_null(9)); // 10.5 % 0.0 = NULL
351 assert!(result_float32.is_null(10)); // 15.8 % 0.0 = NULL
352 } else {

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
spark_modFunction · 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…