| 1209 | }; |
| 1210 | |
| 1211 | SLONG CVT_get_long(const dsc* desc, SSHORT scale, DecimalStatus decSt, ErrorFunction err) |
| 1212 | { |
| 1213 | /************************************** |
| 1214 | * |
| 1215 | * C V T _ g e t _ l o n g |
| 1216 | * |
| 1217 | ************************************** |
| 1218 | * |
| 1219 | * Functional description |
| 1220 | * Convert something arbitrary to a long (32 bit) integer of given |
| 1221 | * scale. |
| 1222 | * |
| 1223 | **************************************/ |
| 1224 | SLONG value, high; |
| 1225 | |
| 1226 | double d, eps; |
| 1227 | Decimal128 d128; |
| 1228 | SINT64 val64; |
| 1229 | VaryStr<50> buffer; // long enough to represent largest long in ASCII |
| 1230 | |
| 1231 | // adjust exact numeric values to same scaling |
| 1232 | |
| 1233 | if (DTYPE_IS_EXACT(desc->dsc_dtype)) |
| 1234 | scale -= desc->dsc_scale; |
| 1235 | |
| 1236 | const char* p = reinterpret_cast<char*>(desc->dsc_address); |
| 1237 | |
| 1238 | switch (desc->dsc_dtype) |
| 1239 | { |
| 1240 | case dtype_short: |
| 1241 | value = *((SSHORT *) p); |
| 1242 | break; |
| 1243 | |
| 1244 | case dtype_long: |
| 1245 | value = *((SLONG *) p); |
| 1246 | break; |
| 1247 | |
| 1248 | case dtype_int64: |
| 1249 | val64 = *((SINT64 *) p); |
| 1250 | |
| 1251 | // adjust for scale first, *before* range-checking the value. |
| 1252 | adjustForScale(val64, scale, INT64_LIMIT, err); |
| 1253 | if ((val64 > LONG_MAX_int64) || (val64 < LONG_MIN_int64)) |
| 1254 | err(Arg::Gds(isc_arith_except) << Arg::Gds(isc_numeric_out_of_range)); |
| 1255 | return (SLONG) val64; |
| 1256 | |
| 1257 | case dtype_quad: |
| 1258 | value = ((SLONG *) p)[LOW_WORD]; |
| 1259 | high = ((SLONG *) p)[HIGH_WORD]; |
| 1260 | if ((value >= 0 && !high) || (value < 0 && high == -1)) |
| 1261 | break; |
| 1262 | err(Arg::Gds(isc_arith_except) << Arg::Gds(isc_numeric_out_of_range)); |
| 1263 | break; |
| 1264 | |
| 1265 | case dtype_dec64: |
| 1266 | case dtype_dec128: |
| 1267 | if (desc->dsc_dtype == dtype_dec64) |
| 1268 | d128 = *((Decimal64*) p); |
no test coverage detected