#include <string.h>
#include <limits.h>
#include "cvtFast.h"
#include "epicsMath.h"
#include "epicsStdio.h"
Go to the source code of this file.
|
int | cvtFloatToString (float flt_value, char *pdest, epicsUInt16 precision) |
|
int | cvtDoubleToString (double flt_value, char *pdest, epicsUInt16 precision) |
|
int | cvtFloatToExpString (float val, char *pdest, epicsUInt16 precision) |
|
int | cvtFloatToCompactString (float val, char *pdest, epicsUInt16 precision) |
|
int | cvtDoubleToExpString (double val, char *pdest, epicsUInt16 precision) |
|
int | cvtDoubleToCompactString (double val, char *pdest, epicsUInt16 precision) |
|
size_t | cvtUInt32ToString (epicsUInt32 val, char *pdest) |
|
size_t | cvtInt32ToString (epicsInt32 val, char *pdest) |
|
size_t | cvtUInt64ToString (epicsUInt64 val, char *pdest) |
|
size_t | cvtInt64ToString (epicsInt64 val, char *pdest) |
|
size_t | cvtInt32ToHexString (epicsInt32 val, char *pdest) |
|
size_t | cvtUInt32ToHexString (epicsUInt32 val, char *pdest) |
|
size_t | cvtInt32ToOctalString (epicsInt32 val, char *pdest) |
|
size_t | cvtInt64ToHexString (epicsInt64 val, char *pdest) |
|
size_t | cvtUInt64ToHexString (epicsUInt64 val, char *pdest) |
|
int cvtDoubleToCompactString |
( |
double |
val, |
|
|
char * |
pdest, |
|
|
epicsUInt16 |
precision |
|
) |
| |
Definition at line 243 of file cvtFast.c.
245 if ((val < 1.e4 && val > 1.e-4) ||
246 (val > -1.e4 && val < -1.e-4) ||
int cvtDoubleToString(double flt_value, char *pdest, epicsUInt16 precision)
int cvtDoubleToExpString(double val, char *pdest, epicsUInt16 precision)
int cvtDoubleToExpString |
( |
double |
val, |
|
|
char * |
pdest, |
|
|
epicsUInt16 |
precision |
|
) |
| |
Definition at line 230 of file cvtFast.c.
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
int cvtDoubleToString |
( |
double |
flt_value, |
|
|
char * |
pdest, |
|
|
epicsUInt16 |
precision |
|
) |
| |
Definition at line 110 of file cvtFast.c.
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));
unsigned short epicsUInt16
int cvtFloatToCompactString |
( |
float |
val, |
|
|
char * |
pdest, |
|
|
epicsUInt16 |
precision |
|
) |
| |
Definition at line 213 of file cvtFast.c.
215 if ((val < 1.e4 && val > 1.e-4) ||
216 (val > -1.e4 && val < -1.e-4) ||
int cvtFloatToExpString(float val, char *pdest, epicsUInt16 precision)
int cvtFloatToString(float flt_value, char *pdest, epicsUInt16 precision)
int cvtFloatToExpString |
( |
float |
val, |
|
|
char * |
pdest, |
|
|
epicsUInt16 |
precision |
|
) |
| |
Definition at line 201 of file cvtFast.c.
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
int cvtFloatToString |
( |
float |
flt_value, |
|
|
char * |
pdest, |
|
|
epicsUInt16 |
precision |
|
) |
| |
Definition at line 31 of file cvtFast.c.
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));
size_t cvtInt32ToHexString |
( |
epicsInt32 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 418 of file cvtFast.c.
433 return 2 + UInt32ToBase(val, pdest, 16);
435 if (val == -0x80000000) {
436 strcpy(pdest,
"80000000");
440 return 3 + UInt32ToBase(-val, pdest, 16);
size_t cvtInt32ToOctalString |
( |
epicsInt32 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 459 of file cvtFast.c.
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);
size_t cvtInt32ToString |
( |
epicsInt32 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 362 of file cvtFast.c.
371 return UInt32ToDec(val, pdest);
373 if (val == -0x80000000) {
374 strcpy(pdest,
"-2147483648");
375 return strlen(pdest);
379 return 1 + UInt32ToDec(-val, pdest);
size_t cvtInt64ToHexString |
( |
epicsInt64 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 483 of file cvtFast.c.
498 return 2 + UInt64ToBase(val, pdest, 16);
500 if (val == -0x8000000000000000LL) {
501 strcpy(pdest,
"8000000000000000");
505 return 3 + UInt64ToBase(-val, pdest, 16);
size_t cvtInt64ToString |
( |
epicsInt64 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 396 of file cvtFast.c.
405 return UInt64ToDec(val, pdest);
407 if (val == -0x8000000000000000LL) {
408 strcpy(pdest,
"-9223372036854775808");
409 return strlen(pdest);
413 return 1 + UInt64ToDec(-val, pdest);
size_t cvtUInt32ToHexString |
( |
epicsUInt32 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 444 of file cvtFast.c.
455 return 2 + UInt32ToBase(val, pdest, 16);
size_t cvtUInt32ToString |
( |
epicsUInt32 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 350 of file cvtFast.c.
358 return UInt32ToDec(val, pdest);
size_t cvtUInt64ToHexString |
( |
epicsUInt64 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 509 of file cvtFast.c.
520 return 2 + UInt64ToBase(val, pdest, 16);
size_t cvtUInt64ToString |
( |
epicsUInt64 |
val, |
|
|
char * |
pdest |
|
) |
| |
Definition at line 384 of file cvtFast.c.
392 return UInt64ToDec(val, pdest);