@@ -1942,14 +1942,14 @@ TEST_F(TestBinaryArithmeticDecimal, DispatchExact) {
19421942 name += suffix;
19431943 ARROW_SCOPED_TRACE (name);
19441944
1945- CheckDispatchExact (name, {decimal128 (2 , 1 ), decimal128 (2 , 1 )});
1946- CheckDispatchExact (name, {decimal128 (3 , 1 ), decimal128 (2 , 1 )});
1947- CheckDispatchExact (name, {decimal128 (2 , 1 ), decimal128 (2 , 0 )});
1945+ CheckDispatchExactFails (name, {decimal128 (2 , 1 ), decimal128 (2 , 1 )});
1946+ CheckDispatchExactFails (name, {decimal128 (3 , 1 ), decimal128 (2 , 1 )});
1947+ CheckDispatchExactFails (name, {decimal128 (2 , 1 ), decimal128 (2 , 0 )});
19481948 CheckDispatchExactFails (name, {decimal128 (2 , 0 ), decimal128 (2 , 1 )});
19491949
1950- CheckDispatchExact (name, {decimal256 (2 , 1 ), decimal256 (2 , 1 )});
1951- CheckDispatchExact (name, {decimal256 (3 , 1 ), decimal256 (2 , 1 )});
1952- CheckDispatchExact (name, {decimal256 (2 , 1 ), decimal256 (2 , 0 )});
1950+ CheckDispatchExactFails (name, {decimal256 (2 , 1 ), decimal256 (2 , 1 )});
1951+ CheckDispatchExactFails (name, {decimal256 (3 , 1 ), decimal256 (2 , 1 )});
1952+ CheckDispatchExactFails (name, {decimal256 (2 , 1 ), decimal256 (2 , 0 )});
19531953 CheckDispatchExactFails (name, {decimal256 (2 , 0 ), decimal256 (2 , 1 )});
19541954 }
19551955 }
@@ -2025,24 +2025,36 @@ TEST_F(TestBinaryArithmeticDecimal, DispatchBest) {
20252025 name += suffix;
20262026 SCOPED_TRACE (name);
20272027
2028- CheckDispatchBest (name, {int64 (), decimal128 (1 , 0 )},
2029- {decimal128 (23 , 4 ), decimal128 (1 , 0 )});
2030- CheckDispatchBest (name, {decimal128 (1 , 0 ), int64 ()},
2031- {decimal128 (21 , 20 ), decimal128 (19 , 0 )});
2032-
2033- CheckDispatchBest (name, {decimal128 (2 , 1 ), decimal128 (2 , 1 )},
2034- {decimal128 (6 , 5 ), decimal128 (2 , 1 )});
2035- CheckDispatchBest (name, {decimal256 (2 , 1 ), decimal256 (2 , 1 )},
2036- {decimal256 (6 , 5 ), decimal256 (2 , 1 )});
2037- CheckDispatchBest (name, {decimal128 (2 , 1 ), decimal256 (2 , 1 )},
2038- {decimal256 (6 , 5 ), decimal256 (2 , 1 )});
2039- CheckDispatchBest (name, {decimal256 (2 , 1 ), decimal128 (2 , 1 )},
2040- {decimal256 (6 , 5 ), decimal256 (2 , 1 )});
2041-
2042- CheckDispatchBest (name, {decimal128 (2 , 0 ), decimal128 (2 , 1 )},
2043- {decimal128 (7 , 5 ), decimal128 (2 , 1 )});
2044- CheckDispatchBest (name, {decimal128 (2 , 1 ), decimal128 (2 , 0 )},
2045- {decimal128 (5 , 4 ), decimal128 (2 , 0 )});
2028+ CheckDispatchBestWithCastedTypes (name, {int64 (), decimal128 (1 , 0 )},
2029+ {decimal128 (23 , 4 ), decimal128 (1 , 0 )});
2030+ CheckDispatchBestWithCastedTypes (name, {decimal128 (1 , 0 ), int64 ()},
2031+ {decimal128 (21 , 20 ), decimal128 (19 , 0 )});
2032+
2033+ CheckDispatchBestWithCastedTypes (name, {decimal128 (2 , 1 ), decimal128 (2 , 1 )},
2034+ {decimal128 (6 , 5 ), decimal128 (2 , 1 )});
2035+ CheckDispatchBestWithCastedTypes (name, {decimal256 (2 , 1 ), decimal256 (2 , 1 )},
2036+ {decimal256 (6 , 5 ), decimal256 (2 , 1 )});
2037+ CheckDispatchBestWithCastedTypes (name, {decimal128 (2 , 1 ), decimal256 (2 , 1 )},
2038+ {decimal256 (6 , 5 ), decimal256 (2 , 1 )});
2039+ CheckDispatchBestWithCastedTypes (name, {decimal256 (2 , 1 ), decimal128 (2 , 1 )},
2040+ {decimal256 (6 , 5 ), decimal256 (2 , 1 )});
2041+
2042+ CheckDispatchBestWithCastedTypes (name, {decimal128 (2 , 0 ), decimal128 (2 , 1 )},
2043+ {decimal128 (7 , 5 ), decimal128 (2 , 1 )});
2044+ CheckDispatchBestWithCastedTypes (name, {decimal128 (2 , 1 ), decimal128 (2 , 0 )},
2045+ {decimal128 (5 , 4 ), decimal128 (2 , 0 )});
2046+
2047+ // GH-39875: Expression call to decimal(3 ,2) / decimal(15, 2) wrong result type.
2048+ // decimal128(3, 2) / decimal128(15, 2)
2049+ // -> decimal128(19, 18) / decimal128(15, 2) = decimal128(19, 16)
2050+ CheckDispatchBestWithCastedTypes (name, {decimal128 (3 , 2 ), decimal128 (15 , 2 )},
2051+ {decimal128 (19 , 18 ), decimal128 (15 , 2 )});
2052+
2053+ // GH-40911: Expression call to decimal(7 ,2) / decimal(6, 1) wrong result type.
2054+ // decimal128(7, 2) / decimal128(6, 1)
2055+ // -> decimal128(14, 9) / decimal128(6, 1) = decimal128(14, 8)
2056+ CheckDispatchBestWithCastedTypes (name, {decimal128 (7 , 2 ), decimal128 (6 , 1 )},
2057+ {decimal128 (14 , 9 ), decimal128 (6 , 1 )});
20462058 }
20472059 }
20482060 for (std::string name : {" atan2" , " logb" , " logb_checked" , " power" , " power_checked" }) {
@@ -2332,6 +2344,14 @@ TEST_F(TestBinaryArithmeticDecimal, Divide) {
23322344 CheckScalarBinary (" divide" , left, right, expected);
23332345 }
23342346
2347+ // decimal(p1, s1) decimal(p2, s2) where s1 < s2
2348+ {
2349+ auto left = ScalarFromJSON (decimal128 (6 , 5 ), R"( "2.71828")" );
2350+ auto right = ScalarFromJSON (decimal128 (7 , 6 ), R"( "3.141592")" );
2351+ auto expected = ScalarFromJSON (decimal128 (14 , 7 ), R"( "0.8652555")" );
2352+ CheckScalarBinary (" divide" , left, right, expected);
2353+ }
2354+
23352355 // decimal128 decimal256
23362356 {
23372357 auto left = ScalarFromJSON (decimal256 (6 , 5 ), R"( "2.71828")" );
0 commit comments