20 #include "epicsMath.h" 29 {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
35 epicsInt32 whole, iplace, number, fraction, fplace;
40 if (
isnan(flt_value) || precision > 8 ||
41 flt_value > 10000000.0 || flt_value < -10000000.0) {
42 if (precision > 8 || flt_value >= 1e8 || flt_value <= -1e8) {
43 if (precision > 12) precision = 12;
44 sprintf(pdest,
"%*.*e", precision+6, precision, (
double) flt_value);
46 if (precision > 3) precision = 3;
47 sprintf(pdest,
"%.*f", precision, (
double) flt_value);
49 return((
int)strlen(pdest));
56 flt_value = -flt_value;
61 ftemp = flt_value - whole;
64 fplace = frac_multiplier[precision];
66 fraction = (fraction + 5) / 10;
69 if ((fraction / fplace) >= 1){
76 for (iplace = 10000000; iplace >= 1; iplace /= 10){
79 number = whole / iplace;
80 whole = whole - (number * iplace);
81 *pdest = number +
'0';
98 for (fplace /= 10, i = precision; i > 0; fplace /= 10,i--){
99 number = fraction / fplace;
100 fraction -= number * fplace;
101 *pdest = number +
'0';
107 return((
int)(pdest - startAddr));
116 epicsInt32 whole,iplace,number,fraction,fplace;
121 if (
isnan(flt_value) || precision > 8 || flt_value > 10000000.0 || flt_value < -10000000.0) {
122 if (precision > 8 || flt_value > 1e16 || flt_value < -1e16) {
123 if(precision>17) precision=17;
124 sprintf(pdest,
"%*.*e",precision+7,precision,
127 if(precision>3) precision=3;
128 sprintf(pdest,
"%.*f",precision,flt_value);
130 return((
int)strlen(pdest));
137 flt_value = -flt_value;
142 ftemp = flt_value - whole;
145 fplace = frac_multiplier[precision];
147 fraction = (fraction + 5) / 10;
150 if ((fraction / fplace) >= 1){
157 for (iplace = 10000000; iplace >= 1; iplace /= 10){
158 if (whole >= iplace){
160 number = whole / iplace;
161 whole = whole - (number * iplace);
162 *pdest = number +
'0';
179 for (fplace /= 10, i = precision; i > 0; fplace /= 10,i--){
180 number = fraction / fplace;
181 fraction -= number * fplace;
182 *pdest = number +
'0';
188 return((
int)(pdest - startAddr));
215 if ((val < 1.e4 && val > 1.e-4) ||
216 (val > -1.e4 && val < -1.e-4) ||
245 if ((val < 1.e4 && val > 1.e-4) ||
246 (val > -1.e4 && val < -1.e-4) ||
263 for (i = 0; val; i++) {
266 digit[
i] = val - tenth * 10 +
'0';
272 *pdest++ = digit[--
i];
282 char digit, digits[32];
285 for (i = 0; val; i++) {
288 digit = val - tenth *
base;
289 digits[
i] = digit < 10 ? digit +
'0' : digit - 10 +
'a';
295 *pdest++ = digits[--
i];
308 for (i = 0; val; i++) {
311 digit[
i] = val - tenth * 10 +
'0';
317 *pdest++ = digit[--
i];
327 char digit, digits[64];
330 for (i = 0; val; i++) {
333 digit = val - tenth *
base;
334 digits[
i] = digit < 10 ? digit +
'0' : digit - 10 +
'a';
340 *pdest++ = digits[--
i];
358 return UInt32ToDec(val, pdest);
371 return UInt32ToDec(val, pdest);
373 if (val == -0x80000000) {
374 strcpy(pdest,
"-2147483648");
375 return strlen(pdest);
379 return 1 + UInt32ToDec(-val, pdest);
392 return UInt64ToDec(val, pdest);
405 return UInt64ToDec(val, pdest);
407 if (val == -0x8000000000000000LL) {
408 strcpy(pdest,
"-9223372036854775808");
409 return strlen(pdest);
413 return 1 + UInt64ToDec(-val, pdest);
433 return 2 + UInt32ToBase(val, pdest, 16);
435 if (val == -0x80000000) {
436 strcpy(pdest,
"80000000");
440 return 3 + UInt32ToBase(-val, pdest, 16);
455 return 2 + UInt32ToBase(val, pdest, 16);
469 return 1 + UInt32ToBase(val, pdest, 8);
472 if (val == -0x80000000) {
473 strcpy(pdest,
"-020000000000");
474 return strlen(pdest);
479 return 2 + UInt32ToBase(-val, pdest, 8);
498 return 2 + UInt64ToBase(val, pdest, 16);
500 if (val == -0x8000000000000000LL) {
501 strcpy(pdest,
"8000000000000000");
505 return 3 + UInt64ToBase(-val, pdest, 16);
520 return 2 + UInt64ToBase(val, pdest, 16);
size_t cvtInt32ToString(epicsInt32 val, char *pdest)
size_t cvtInt32ToHexString(epicsInt32 val, char *pdest)
int cvtFloatToExpString(float val, char *pdest, epicsUInt16 precision)
int cvtDoubleToString(double flt_value, char *pdest, epicsUInt16 precision)
size_t cvtUInt32ToString(epicsUInt32 val, char *pdest)
unsigned short epicsUInt16
int cvtDoubleToExpString(double val, char *pdest, epicsUInt16 precision)
size_t cvtUInt64ToHexString(epicsUInt64 val, char *pdest)
unsigned long long epicsUInt64
size_t cvtInt64ToHexString(epicsInt64 val, char *pdest)
int cvtFloatToCompactString(float val, char *pdest, epicsUInt16 precision)
size_t cvtInt64ToString(epicsInt64 val, char *pdest)
int cvtDoubleToCompactString(double val, char *pdest, epicsUInt16 precision)
size_t cvtUInt64ToString(epicsUInt64 val, char *pdest)
size_t cvtUInt32ToHexString(epicsUInt32 val, char *pdest)
int cvtFloatToString(float flt_value, char *pdest, epicsUInt16 precision)
size_t cvtInt32ToOctalString(epicsInt32 val, char *pdest)
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3