This is Unofficial EPICS BASE Doxygen Site
cvtFast.h File Reference
#include <stddef.h>
#include "epicsTypes.h"
#include "libComAPI.h"
+ Include dependency graph for cvtFast.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define cvtCharToString(val, str)   cvtInt32ToString(val, str)
 
#define cvtUcharToString(val, str)   cvtUInt32ToString(val, str)
 
#define cvtShortToString(val, str)   cvtInt32ToString(val, str)
 
#define cvtUshortToString(val, str)   cvtUInt32ToString(val, str)
 
#define cvtLongToString(val, str)   cvtInt32ToString(val, str)
 
#define cvtUlongToString(val, str)   cvtUInt32ToString(val, str)
 
#define cvtLongToHexString(val, str)   cvtInt32ToHexString(val, str)
 
#define cvtULongToHexString(val, str)   cvtUInt32ToHexString(val, str)
 
#define cvtLongToOctalString(val, str)   cvtInt32ToOctalString(val, str)
 

Functions

LIBCOM_API int cvtFloatToString (float val, char *pdest, epicsUInt16 prec)
 
LIBCOM_API int cvtDoubleToString (double val, char *pdest, epicsUInt16 prec)
 
LIBCOM_API int cvtFloatToExpString (float val, char *pdest, epicsUInt16 prec)
 
LIBCOM_API int cvtDoubleToExpString (double val, char *pdest, epicsUInt16 prec)
 
LIBCOM_API int cvtFloatToCompactString (float val, char *pdest, epicsUInt16 prec)
 
LIBCOM_API int cvtDoubleToCompactString (double val, char *pdest, epicsUInt16 prec)
 
LIBCOM_API size_t cvtInt32ToString (epicsInt32 val, char *pdest)
 
LIBCOM_API size_t cvtUInt32ToString (epicsUInt32 val, char *pdest)
 
LIBCOM_API size_t cvtInt64ToString (epicsInt64 val, char *pdest)
 
LIBCOM_API size_t cvtUInt64ToString (epicsUInt64 val, char *pdest)
 
LIBCOM_API size_t cvtInt32ToHexString (epicsInt32 val, char *pdest)
 
LIBCOM_API size_t cvtUInt32ToHexString (epicsUInt32 val, char *pdest)
 
LIBCOM_API size_t cvtInt32ToOctalString (epicsInt32 val, char *pdest)
 
LIBCOM_API size_t cvtInt64ToHexString (epicsInt64 val, char *pdest)
 
LIBCOM_API size_t cvtUInt64ToHexString (epicsUInt64 val, char *pdest)
 

Macro Definition Documentation

#define cvtCharToString (   val,
  str 
)    cvtInt32ToString(val, str)

Definition at line 68 of file cvtFast.h.

#define cvtLongToHexString (   val,
  str 
)    cvtInt32ToHexString(val, str)

Definition at line 75 of file cvtFast.h.

#define cvtLongToOctalString (   val,
  str 
)    cvtInt32ToOctalString(val, str)

Definition at line 77 of file cvtFast.h.

#define cvtLongToString (   val,
  str 
)    cvtInt32ToString(val, str)

Definition at line 72 of file cvtFast.h.

#define cvtShortToString (   val,
  str 
)    cvtInt32ToString(val, str)

Definition at line 70 of file cvtFast.h.

#define cvtUcharToString (   val,
  str 
)    cvtUInt32ToString(val, str)

Definition at line 69 of file cvtFast.h.

#define cvtULongToHexString (   val,
  str 
)    cvtUInt32ToHexString(val, str)

Definition at line 76 of file cvtFast.h.

#define cvtUlongToString (   val,
  str 
)    cvtUInt32ToString(val, str)

Definition at line 73 of file cvtFast.h.

#define cvtUshortToString (   val,
  str 
)    cvtUInt32ToString(val, str)

Definition at line 71 of file cvtFast.h.

Function Documentation

LIBCOM_API int cvtDoubleToCompactString ( double  val,
char *  pdest,
epicsUInt16  prec 
)

Definition at line 243 of file cvtFast.c.

244 {
245  if ((val < 1.e4 && val > 1.e-4) ||
246  (val > -1.e4 && val < -1.e-4) ||
247  val == 0.0)
248  return cvtDoubleToString(val, pdest, precision);
249 
250  return cvtDoubleToExpString(val, pdest, precision);
251 }
int cvtDoubleToString(double flt_value, char *pdest, epicsUInt16 precision)
Definition: cvtFast.c:110
int cvtDoubleToExpString(double val, char *pdest, epicsUInt16 precision)
Definition: cvtFast.c:230
LIBCOM_API int cvtDoubleToExpString ( double  val,
char *  pdest,
epicsUInt16  prec 
)

Definition at line 230 of file cvtFast.c.

231 {
232  return epicsSnprintf(pdest, MAX_STRING_SIZE, "%.*e", precision, val);
233 }
#define MAX_STRING_SIZE
Definition: epicsTypes.h:65
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
LIBCOM_API int cvtDoubleToString ( double  val,
char *  pdest,
epicsUInt16  prec 
)

Definition at line 110 of file cvtFast.c.

114 {
115  epicsUInt16 got_one,i;
116  epicsInt32 whole,iplace,number,fraction,fplace;
117  double ftemp;
118  char *startAddr;
119 
120  /* can this routine handle this conversion */
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,
125  flt_value);
126  } else {
127  if(precision>3) precision=3;
128  sprintf(pdest,"%.*f",precision,flt_value);
129  }
130  return((int)strlen(pdest));
131  }
132  startAddr = pdest;
133 
134  /* determine the sign */
135  if (flt_value < 0){
136  *pdest++ = '-';
137  flt_value = -flt_value;
138  };
139 
140  /* remove the whole number portion */
141  whole = (epicsInt32)flt_value;
142  ftemp = flt_value - whole;
143 
144  /* multiplier to convert fractional portion to integer */
145  fplace = frac_multiplier[precision];
146  fraction = (epicsInt32)(ftemp * fplace * 10);
147  fraction = (fraction + 5) / 10; /* round up */
148 
149  /* determine rounding into the whole number portion */
150  if ((fraction / fplace) >= 1){
151  whole++;
152  fraction -= fplace;
153  }
154 
155  /* whole numbers */
156  got_one = 0;
157  for (iplace = 10000000; iplace >= 1; iplace /= 10){
158  if (whole >= iplace){
159  got_one = 1;
160  number = whole / iplace;
161  whole = whole - (number * iplace);
162  *pdest = number + '0';
163  pdest++;
164  }else if (got_one){
165  *pdest = '0';
166  pdest++;
167  }
168  }
169  if (!got_one){
170  *pdest = '0';
171  pdest++;
172  }
173 
174  /* fraction */
175  if (precision > 0){
176  /* convert fractional portional to ASCII */
177  *pdest = '.';
178  pdest++;
179  for (fplace /= 10, i = precision; i > 0; fplace /= 10,i--){
180  number = fraction / fplace;
181  fraction -= number * fplace;
182  *pdest = number + '0';
183  pdest++;
184  }
185  }
186  *pdest = 0;
187 
188  return((int)(pdest - startAddr));
189 }
int i
Definition: scan.c:967
unsigned short epicsUInt16
Definition: epicsTypes.h:41
#define isnan(x)
Definition: epicsMath.h:21
int epicsInt32
Definition: epicsTypes.h:42
LIBCOM_API int cvtFloatToCompactString ( float  val,
char *  pdest,
epicsUInt16  prec 
)

Definition at line 213 of file cvtFast.c.

214 {
215  if ((val < 1.e4 && val > 1.e-4) ||
216  (val > -1.e4 && val < -1.e-4) ||
217  val == 0.0)
218  return cvtFloatToString(val, pdest, precision);
219 
220  return cvtFloatToExpString(val, pdest, precision);
221 }
int cvtFloatToExpString(float val, char *pdest, epicsUInt16 precision)
Definition: cvtFast.c:201
int cvtFloatToString(float flt_value, char *pdest, epicsUInt16 precision)
Definition: cvtFast.c:31
LIBCOM_API int cvtFloatToExpString ( float  val,
char *  pdest,
epicsUInt16  prec 
)

Definition at line 201 of file cvtFast.c.

202 {
203  return epicsSnprintf(pdest, MAX_STRING_SIZE, "%.*e", precision, val);
204 }
#define MAX_STRING_SIZE
Definition: epicsTypes.h:65
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
LIBCOM_API int cvtFloatToString ( float  val,
char *  pdest,
epicsUInt16  prec 
)

Definition at line 31 of file cvtFast.c.

33 {
34  int got_one, i;
35  epicsInt32 whole, iplace, number, fraction, fplace;
36  float ftemp;
37  char *startAddr;
38 
39  /* can this routine handle this conversion */
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; /* FIXME */
44  sprintf(pdest, "%*.*e", precision+6, precision, (double) flt_value);
45  } else {
46  if (precision > 3) precision = 3; /* FIXME */
47  sprintf(pdest, "%.*f", precision, (double) flt_value);
48  }
49  return((int)strlen(pdest));
50  }
51  startAddr = pdest;
52 
53  /* determine the sign */
54  if (flt_value < 0){
55  *pdest++ = '-';
56  flt_value = -flt_value;
57  };
58 
59  /* remove the whole number portion */
60  whole = (epicsInt32)flt_value;
61  ftemp = flt_value - whole;
62 
63  /* multiplier to convert fractional portion to integer */
64  fplace = frac_multiplier[precision];
65  fraction = (epicsInt32)(ftemp * fplace * 10);
66  fraction = (fraction + 5) / 10; /* round up */
67 
68  /* determine rounding into the whole number portion */
69  if ((fraction / fplace) >= 1){
70  whole++;
71  fraction -= fplace;
72  }
73 
74  /* whole numbers */
75  got_one = 0;
76  for (iplace = 10000000; iplace >= 1; iplace /= 10){
77  if (whole >= iplace){
78  got_one = 1;
79  number = whole / iplace;
80  whole = whole - (number * iplace);
81  *pdest = number + '0';
82  pdest++;
83  }else if (got_one){
84  *pdest = '0';
85  pdest++;
86  }
87  }
88  if (!got_one){
89  *pdest = '0';
90  pdest++;
91  }
92 
93  /* fraction */
94  if (precision > 0){
95  /* convert fractional portional to ASCII */
96  *pdest = '.';
97  pdest++;
98  for (fplace /= 10, i = precision; i > 0; fplace /= 10,i--){
99  number = fraction / fplace;
100  fraction -= number * fplace;
101  *pdest = number + '0';
102  pdest++;
103  }
104  }
105  *pdest = 0;
106 
107  return((int)(pdest - startAddr));
108 }
int i
Definition: scan.c:967
#define isnan(x)
Definition: epicsMath.h:21
int epicsInt32
Definition: epicsTypes.h:42
LIBCOM_API size_t cvtInt32ToHexString ( epicsInt32  val,
char *  pdest 
)

Definition at line 418 of file cvtFast.c.

419 {
420  if (val < 0)
421  *pdest++ = '-';
422 
423  *pdest++ = '0';
424  *pdest++ = 'x';
425 
426  if (val == 0) {
427  *pdest++ = '0';
428  *pdest = 0;
429  return 3;
430  }
431 
432  if (val > 0)
433  return 2 + UInt32ToBase(val, pdest, 16);
434 
435  if (val == -0x80000000) {
436  strcpy(pdest, "80000000");
437  return 11;
438  }
439 
440  return 3 + UInt32ToBase(-val, pdest, 16);
441 }
LIBCOM_API size_t cvtInt32ToOctalString ( epicsInt32  val,
char *  pdest 
)

Definition at line 459 of file cvtFast.c.

460 {
461  if (val == 0) {
462  *pdest++ = '0';
463  *pdest = 0;
464  return 1;
465  }
466 
467  if (val > 0) {
468  *pdest++ = '0';
469  return 1 + UInt32ToBase(val, pdest, 8);
470  }
471 
472  if (val == -0x80000000) {
473  strcpy(pdest, "-020000000000");
474  return strlen(pdest);
475  }
476 
477  *pdest++ = '-';
478  *pdest++ = '0';
479  return 2 + UInt32ToBase(-val, pdest, 8);
480 }
LIBCOM_API size_t cvtInt32ToString ( epicsInt32  val,
char *  pdest 
)

Definition at line 362 of file cvtFast.c.

363 {
364  if (val == 0) {
365  *pdest++ = '0';
366  *pdest = 0;
367  return 1;
368  }
369 
370  if (val > 0)
371  return UInt32ToDec(val, pdest);
372 
373  if (val == -0x80000000) {
374  strcpy(pdest, "-2147483648");
375  return strlen(pdest);
376  }
377 
378  *pdest++ = '-';
379  return 1 + UInt32ToDec(-val, pdest);
380 }
LIBCOM_API size_t cvtInt64ToHexString ( epicsInt64  val,
char *  pdest 
)

Definition at line 483 of file cvtFast.c.

484 {
485  if (val < 0)
486  *pdest++ = '-';
487 
488  *pdest++ = '0';
489  *pdest++ = 'x';
490 
491  if (val == 0) {
492  *pdest++ = '0';
493  *pdest = 0;
494  return 3;
495  }
496 
497  if (val > 0)
498  return 2 + UInt64ToBase(val, pdest, 16);
499 
500  if (val == -0x8000000000000000LL) {
501  strcpy(pdest, "8000000000000000");
502  return 19;
503  }
504 
505  return 3 + UInt64ToBase(-val, pdest, 16);
506 }
LIBCOM_API size_t cvtInt64ToString ( epicsInt64  val,
char *  pdest 
)

Definition at line 396 of file cvtFast.c.

397 {
398  if (val == 0) {
399  *pdest++ = '0';
400  *pdest = 0;
401  return 1;
402  }
403 
404  if (val > 0)
405  return UInt64ToDec(val, pdest);
406 
407  if (val == -0x8000000000000000LL) {
408  strcpy(pdest, "-9223372036854775808");
409  return strlen(pdest);
410  }
411 
412  *pdest++ = '-';
413  return 1 + UInt64ToDec(-val, pdest);
414 }
LIBCOM_API size_t cvtUInt32ToHexString ( epicsUInt32  val,
char *  pdest 
)

Definition at line 444 of file cvtFast.c.

445 {
446  *pdest++ = '0';
447  *pdest++ = 'x';
448 
449  if (val == 0) {
450  *pdest++ = '0';
451  *pdest = 0;
452  return 3;
453  }
454 
455  return 2 + UInt32ToBase(val, pdest, 16);
456 }
LIBCOM_API size_t cvtUInt32ToString ( epicsUInt32  val,
char *  pdest 
)

Definition at line 350 of file cvtFast.c.

351 {
352  if (val == 0) {
353  *pdest++ = '0';
354  *pdest = 0;
355  return 1;
356  }
357 
358  return UInt32ToDec(val, pdest);
359 }
LIBCOM_API size_t cvtUInt64ToHexString ( epicsUInt64  val,
char *  pdest 
)

Definition at line 509 of file cvtFast.c.

510 {
511  *pdest++ = '0';
512  *pdest++ = 'x';
513 
514  if (val == 0) {
515  *pdest++ = '0';
516  *pdest = 0;
517  return 3;
518  }
519 
520  return 2 + UInt64ToBase(val, pdest, 16);
521 }
LIBCOM_API size_t cvtUInt64ToString ( epicsUInt64  val,
char *  pdest 
)

Definition at line 384 of file cvtFast.c.

385 {
386  if (val == 0) {
387  *pdest++ = '0';
388  *pdest = 0;
389  return 1;
390  }
391 
392  return UInt64ToDec(val, pdest);
393 }