The MULTIPLY_ALT scalar function returns the product of the two arguments.
>>-MULTIPLY_ALT--(--numeric_expression1--,----------------------> >--numeric_expression2--)--------------------------------------><
The schema is SYSIBM.
The MULTIPLY_ALT function is provided as an alternative to the multiplication operator, especially when the sum of the decimal precisions of the arguments exceeds 31.
The result of the function is DECIMAL when both arguments are exact numeric data types (DECIMAL, BIGINT, INTEGER, or SMALLINT); otherwise the operation is carried out using decimal floating-point arithmetic and the result of the function is decimal floating-point with a precision determined by the data type of the arguments in the same way the precision is determined for decimal floating-point arithmetic. A floating-point or string argument is cast to DECFLOAT(34) before evaluating the function.
The result can be null if at least one argument can be null, or if the database is configured with dft_sqlmathwarn set to YES; the result is the null value if one of the arguments is null.
The MULTIPLY_ALT function is a preferable choice to the multiplication operator when performing decimal arithmetic where a scale of at least 3 is required and the sum of the precisions exceeds 31. In these cases, the internal computation is performed so that overflows are avoided. The final result is then assigned to the result data type, using truncation where necessary to match the scale. Note that overflow of the final result is still possible when the scale is 3.
Type of argument 1 | Type of argument 2 | Result using MULTIPLY_ALT | Result using multiplication operator |
---|---|---|---|
DECIMAL(31,3) | DECIMAL(15,8) | DECIMAL(31,3) | DECIMAL(31,11) |
DECIMAL(26,23) | DECIMAL(10,1) | DECIMAL(31,19) | DECIMAL(31,24) |
DECIMAL(18,17) | DECIMAL(20,19) | DECIMAL(31,29) | DECIMAL(31,31) |
DECIMAL(16,3) | DECIMAL(17,8) | DECIMAL(31,9) | DECIMAL(31,11) |
DECIMAL(26,5) | DECIMAL(11,0) | DECIMAL(31,3) | DECIMAL(31,5) |
DECIMAL(21,1) | DECIMAL(15,1) | DECIMAL(31,2) | DECIMAL(31,2) |
values multiply_alt(98765432109876543210987.654,5.43210987)
1
---------------------------------
536504678578875294857887.5277415
Note that the complete
product of these two numbers is 536504678578875294857887.52774154498,
but the last 4 digits are truncated to match the scale of the result
data type. Using the multiplication operator with the same values
will cause an arithmetic overflow, since the result data type is DECIMAL(31,11)
and the result value has 24 digits left of the decimal, but the result
data type only supports 20 digits.