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

Function CVT_get_dec128

src/common/cvt.cpp:3058–3139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3056
3057
3058Decimal128 CVT_get_dec128(const dsc* desc, DecimalStatus decSt, ErrorFunction err)
3059{
3060/**************************************
3061 *
3062 * C V T _ g e t _ d e c 1 2 8
3063 *
3064 **************************************
3065 *
3066 * Functional description
3067 * Convert something arbitrary to a DecFloat(34) / (128 bit).
3068 *
3069 **************************************/
3070 VaryStr<1024> buffer; // represents unreasonably long decfloat literal in ASCII
3071 Decimal128 d128;
3072
3073 // adjust exact numeric values to same scaling
3074 int scale = 0;
3075 if (DTYPE_IS_EXACT(desc->dsc_dtype))
3076 scale = -desc->dsc_scale;
3077
3078 const char* p = reinterpret_cast<char*>(desc->dsc_address);
3079
3080 try
3081 {
3082 switch (desc->dsc_dtype)
3083 {
3084 case dtype_short:
3085 return d128.set(*(SSHORT*) p, decSt, scale);
3086
3087 case dtype_long:
3088 return d128.set(*(SLONG*) p, decSt, scale);
3089
3090 case dtype_quad:
3091 return d128.set(CVT_get_int64(desc, 0, decSt, err), decSt, scale);
3092
3093 case dtype_int64:
3094 return d128.set(*(SINT64*) p, decSt, scale);
3095
3096 case dtype_varying:
3097 case dtype_cstring:
3098 case dtype_text:
3099 make_null_string(desc, ttype_ascii, &p, &buffer, sizeof(buffer) - 1, decSt, err);
3100 try
3101 {
3102 return d128.set(buffer.vary_string, decSt);
3103 }
3104 catch (const Exception& e)
3105 {
3106 checkForIndeterminant(e, desc, err);
3107 throw;
3108 }
3109
3110 case dtype_real:
3111 return d128.set(*((float*) p), decSt);
3112
3113 case dtype_double:
3114 return d128.set(*((double*) p), decSt);
3115

Callers 5

pass2Method · 0.85
CVT_get_numericFunction · 0.85
MOV_get_dec128Function · 0.85
CVT2_compareFunction · 0.85
CVT_move_commonFunction · 0.85

Calls 6

DTYPE_IS_EXACTFunction · 0.85
CVT_get_int64Function · 0.85
make_null_stringFunction · 0.85
checkForIndeterminantFunction · 0.85
CVT_conversion_errorFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected