| 1628 | } |
| 1629 | |
| 1630 | void ArithmeticNode::getDescDialect3(thread_db* /*tdbb*/, dsc* desc, dsc& desc1, dsc& desc2) |
| 1631 | { |
| 1632 | USHORT dtype; |
| 1633 | |
| 1634 | switch (blrOp) |
| 1635 | { |
| 1636 | case blr_add: |
| 1637 | case blr_subtract: |
| 1638 | { |
| 1639 | USHORT dtype1 = desc1.dsc_dtype; |
| 1640 | USHORT dtype2 = desc2.dsc_dtype; |
| 1641 | |
| 1642 | // In Dialect 2 or 3, strings can never participate in addition / sub |
| 1643 | // (use a specific cast instead) |
| 1644 | if (DTYPE_IS_TEXT(dtype1) || DTYPE_IS_TEXT(dtype2)) |
| 1645 | ERR_post(Arg::Gds(isc_expression_eval_err)); |
| 1646 | |
| 1647 | // Because dtype_int64 > dtype_double, we cannot just use the MAX macro to set |
| 1648 | // the result dtype. The rule is that two exact numeric operands yield an int64 |
| 1649 | // result, while an approximate numeric and anything yield a double result. |
| 1650 | |
| 1651 | if (DTYPE_IS_EXACT(dtype1) && DTYPE_IS_EXACT(dtype2)) |
| 1652 | { |
| 1653 | if (desc1.isInt128() || desc2.isInt128()) |
| 1654 | dtype = dtype_int128; |
| 1655 | else |
| 1656 | dtype = dtype_int64; |
| 1657 | } |
| 1658 | else if (DTYPE_IS_NUMERIC(dtype1) && DTYPE_IS_NUMERIC(dtype2)) |
| 1659 | { |
| 1660 | if (DTYPE_IS_DECFLOAT(dtype1) || DTYPE_IS_DECFLOAT(dtype2)) |
| 1661 | { |
| 1662 | USHORT d1 = DTYPE_IS_DECFLOAT(dtype1) ? dtype1 : 0; |
| 1663 | USHORT d2 = DTYPE_IS_DECFLOAT(dtype2) ? dtype2 : 0; |
| 1664 | dtype = MAX(d1, d2); |
| 1665 | } |
| 1666 | else |
| 1667 | { |
| 1668 | fb_assert(DTYPE_IS_APPROX(dtype1) || DTYPE_IS_APPROX(dtype2)); |
| 1669 | dtype = dtype_double; |
| 1670 | } |
| 1671 | } |
| 1672 | else |
| 1673 | { |
| 1674 | // mixed numeric and non-numeric: |
| 1675 | |
| 1676 | fb_assert(couldBeDate(desc1) || couldBeDate(desc2)); |
| 1677 | |
| 1678 | // the MAX(dtype) rule doesn't apply with dtype_int64 |
| 1679 | |
| 1680 | if (dtype_int64 == dtype1) |
| 1681 | dtype1 = dtype_double; |
| 1682 | |
| 1683 | if (dtype_int64 == dtype2) |
| 1684 | dtype2 = dtype_double; |
| 1685 | |
| 1686 | dtype = CVT2_compare_priority[dtype1] > CVT2_compare_priority[dtype2] ? dtype1 : dtype2; |
| 1687 | } |
nothing calls this directly
no test coverage detected