| 2972 | |
| 2973 | |
| 2974 | Decimal64 CVT_get_dec64(const dsc* desc, DecimalStatus decSt, ErrorFunction err) |
| 2975 | { |
| 2976 | /************************************** |
| 2977 | * |
| 2978 | * C V T _ g e t _ d e c 6 4 |
| 2979 | * |
| 2980 | ************************************** |
| 2981 | * |
| 2982 | * Functional description |
| 2983 | * Convert something arbitrary to a DecFloat(16) / (64 bit). |
| 2984 | * |
| 2985 | **************************************/ |
| 2986 | VaryStr<512> buffer; // long enough to represent largest decimal float in ASCII |
| 2987 | Decimal64 d64; |
| 2988 | |
| 2989 | // adjust exact numeric values to same scaling |
| 2990 | int scale = 0; |
| 2991 | if (DTYPE_IS_EXACT(desc->dsc_dtype)) |
| 2992 | scale = -desc->dsc_scale; |
| 2993 | |
| 2994 | const char* p = reinterpret_cast<char*>(desc->dsc_address); |
| 2995 | |
| 2996 | try |
| 2997 | { |
| 2998 | switch (desc->dsc_dtype) |
| 2999 | { |
| 3000 | case dtype_short: |
| 3001 | return d64.set(*(SSHORT*) p, decSt, scale); |
| 3002 | |
| 3003 | case dtype_long: |
| 3004 | return d64.set(*(SLONG*) p, decSt, scale); |
| 3005 | |
| 3006 | case dtype_quad: |
| 3007 | return d64.set(CVT_get_int64(desc, 0, decSt, err), decSt, scale); |
| 3008 | |
| 3009 | case dtype_int64: |
| 3010 | return d64.set(*(SINT64*) p, decSt, scale); |
| 3011 | |
| 3012 | case dtype_varying: |
| 3013 | case dtype_cstring: |
| 3014 | case dtype_text: |
| 3015 | make_null_string(desc, ttype_ascii, &p, &buffer, sizeof(buffer) - 1, decSt, err); |
| 3016 | try |
| 3017 | { |
| 3018 | return d64.set(buffer.vary_string, decSt); |
| 3019 | } |
| 3020 | catch (const Exception& e) |
| 3021 | { |
| 3022 | checkForIndeterminant(e, desc, err); |
| 3023 | throw; |
| 3024 | } |
| 3025 | |
| 3026 | case dtype_real: |
| 3027 | return d64.set(*((float*) p), decSt); |
| 3028 | |
| 3029 | case dtype_double: |
| 3030 | return d64.set(*((double*) p), decSt); |
| 3031 |
no test coverage detected