()
| 638 | |
| 639 | #[test] |
| 640 | fn test_pow_decimal_float_fallback() { |
| 641 | // Test negative exponent: 4^(-1) = 0.25 |
| 642 | // 4 with scale 2 = 400, result should be 25 (0.25 with scale 2) |
| 643 | let result: i128 = pow_decimal_float(400i128, 2, -1.0).unwrap(); |
| 644 | assert_eq!(result, 25); |
| 645 | |
| 646 | // Test non-integer exponent: 4^0.5 = 2 |
| 647 | // 4 with scale 2 = 400, result should be 200 (2.0 with scale 2) |
| 648 | let result: i128 = pow_decimal_float(400i128, 2, 0.5).unwrap(); |
| 649 | assert_eq!(result, 200); |
| 650 | |
| 651 | // Test 8^(1/3) = 2 (cube root) |
| 652 | // 8 with scale 1 = 80, result should be 20 (2.0 with scale 1) |
| 653 | let result: i128 = pow_decimal_float(80i128, 1, 1.0 / 3.0).unwrap(); |
| 654 | assert_eq!(result, 20); |
| 655 | |
| 656 | // Test negative base with integer exponent still works |
| 657 | // (-2)^3 = -8 |
| 658 | // -2 with scale 1 = -20, result should be -80 (-8.0 with scale 1) |
| 659 | let result: i128 = pow_decimal_float(-20i128, 1, 3.0).unwrap(); |
| 660 | assert_eq!(result, -80); |
| 661 | |
| 662 | // Test positive integer exponent goes through fast path |
| 663 | // 2.5^4 = 39.0625 |
| 664 | // 25 with scale 1, result should be 390 (39.0 with scale 1) - truncated |
| 665 | let result: i128 = pow_decimal_float(25i128, 1, 4.0).unwrap(); |
| 666 | assert_eq!(result, 390); // Uses integer path |
| 667 | |
| 668 | // Test non-finite exponent returns error |
| 669 | assert!(pow_decimal_float(100i128, 2, f64::NAN).is_err()); |
| 670 | assert!(pow_decimal_float(100i128, 2, f64::INFINITY).is_err()); |
| 671 | |
| 672 | // PostgreSQL: zero to a negative power is undefined |
| 673 | assert!(pow_decimal_float(0i128, 2, -1.0).is_err()); |
| 674 | } |
| 675 | |
| 676 | #[test] |
| 677 | fn test_pow_decimal256_zero_to_negative_exp_errors() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…