| 1122 | |
| 1123 | template <typename V> |
| 1124 | void adjustForScale(V& val, SSHORT scale, const V limit, ErrorFunction err) |
| 1125 | { |
| 1126 | if (scale > 0) |
| 1127 | { |
| 1128 | int fraction = 0; |
| 1129 | do { |
| 1130 | if (scale == 1) |
| 1131 | fraction = int(val % 10); |
| 1132 | val /= 10; |
| 1133 | } while (--scale); |
| 1134 | |
| 1135 | if (fraction > 4) |
| 1136 | val++; |
| 1137 | // The following 2 lines are correct for platforms where |
| 1138 | // ((-85 / 10 == -8) && (-85 % 10 == -5)). If we port to |
| 1139 | // a platform where ((-85 / 10 == -9) && (-85 % 10 == 5)), |
| 1140 | // we'll have to change this depending on the platform. |
| 1141 | else if (fraction < -4) |
| 1142 | val--; |
| 1143 | } |
| 1144 | else if (scale < 0) |
| 1145 | { |
| 1146 | do { |
| 1147 | if ((val > limit) || (val < -limit)) |
| 1148 | err(Arg::Gds(isc_arith_except) << Arg::Gds(isc_numeric_out_of_range)); |
| 1149 | val *= 10; |
| 1150 | } while (++scale); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | class SSHORTTraits |
no test coverage detected