MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / CVT_get_long

Function CVT_get_long

src/common/cvt.cpp:1211–1339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1209};
1210
1211SLONG 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);

Callers 8

setParamsDateAddFunction · 0.85
makeDateDiffFunction · 0.85
makePadFunction · 0.85
makeSubstrMethod · 0.85
MOV_get_longFunction · 0.85
CVT2_compareFunction · 0.85
cvt_get_shortFunction · 0.85
CVT_move_commonFunction · 0.85

Calls 8

DTYPE_IS_EXACTFunction · 0.85
adjustForScaleFunction · 0.85
GdsClass · 0.85
CVT_power_of_tenFunction · 0.85
CVT_make_stringFunction · 0.85
cvt_decomposeFunction · 0.85
CVT_conversion_errorFunction · 0.85
toIntegerMethod · 0.45

Tested by

no test coverage detected