13 #define isfinite _finite
15 #define isfinite std::isfinite
18#if defined __cplusplus
23#define numberOfStaticDoubles ( 100 * 1000 )
25static nfu_status nfu_stringToListOfDoubles2(
char const *str, int64_t *numberConverted,
double **doublePtr,
char **endCharacter );
33 return( nfu_stringToListOfDoubles2( str, numberConverted, doublePtr, endCharacter ) );
38static nfu_status nfu_stringToListOfDoubles2(
char const *str, int64_t *numberConverted,
double **doublePtr,
char **endCharacter ) {
40 int64_t i1, i2, numberConverted_initial = *numberConverted;
45 staticDoubles[i1] = strtod( str, endCharacter );
46 if( str == (
char const *) *endCharacter ) {
47 if( *numberConverted > 0 ) {
48 if( ( *doublePtr = (
double *)
nfu_malloc( (
size_t) *numberConverted *
sizeof(
double ) ) ) == NULL ) status =
nfu_mallocError;
52 str = (
char const *) *endCharacter;
55 if( ( status ==
nfu_Okay ) && ( *doublePtr == NULL ) ) status = nfu_stringToListOfDoubles2( str, numberConverted, doublePtr, endCharacter );
56 if( *doublePtr != NULL ) {
57 double *doublePtr2 = &((*doublePtr)[numberConverted_initial]);
59 for( i2 = 0; i2 < i1; i2++, doublePtr2++ ) *doublePtr2 = staticDoubles[i2];
68 int n1, ne, nf, digitsRightOfPeriod_f, exponent;
69 char Str_e[512], Str_f[512], *Str_r = Str_e, Fmt[32], *e1, *e2;
70 const char *sign =
"";
75 snprintf( Fmt,
sizeof Fmt,
"%%%sf", sign );
76 snprintf( Str_e,
sizeof Str_e, Fmt, value );
77 return( strdup( Str_e ) );
81 if( significantDigits < 0 ) significantDigits = 0;
82 if( significantDigits > 24 ) significantDigits = 24;
84 snprintf( Fmt,
sizeof Fmt,
"%%%s.%de", sign, significantDigits );
85 snprintf( Str_e,
sizeof Str_e, Fmt, value );
87 e1 = strchr( Str_e,
'e' );
88 if( significantDigits == 0 ) {
89 if( *(e1 - 1) !=
'.' ) {
94 for( ; e2 != e1; e2--, e3-- ) *e3 = *e2;
99 n1 = (int) strlen( Str_e ) - 1;
107 exponent = (int) strtol( e1, &e2, 10 );
108 if( exponent != 0 ) {
109 for( e1 = Str_e; *e1 != 0; e1++ ) ;
110 snprintf( e1,
sizeof Str_e,
"e%d", exponent );
112 digitsRightOfPeriod_f = significantDigits - exponent;
113 if( ( digitsRightOfPeriod_f > 25 ) || ( exponent > 50 ) )
return( strdup( Str_r ) );
114 if( digitsRightOfPeriod_f < 0 ) digitsRightOfPeriod_f = 0;
116 snprintf( Fmt,
sizeof Fmt,
"%%%s.%df", sign, digitsRightOfPeriod_f );
117 snprintf( Str_f,
sizeof Str_f, Fmt, value );
119 ne = (int) strlen( Str_e );
120 nf = (int) strlen( Str_f );
121 if( strchr( Str_f,
'.' ) != NULL ) {
123 if( Str_f[nf-1] ==
'.' ) {
134 if( ( nf + favorEFormBy ) < ne ) Str_r = Str_f;
136 return( strdup( Str_r ) );
139#if defined __cplusplus
#define numberOfStaticDoubles
#define nf_floatToShortestString_includeSign
enum nfu_status_e nfu_status
#define nf_floatToShortestString_trimZeros
nfu_status nfu_stringToListOfDoubles(char const *str, int64_t *numberConverted, double **doublePtr, char **endCharacter)
void * nfu_malloc(size_t size)
#define nf_floatToShortestString_keepPeriod
char * nf_floatToShortestString(double value, int significantDigits, int favorEFormBy, int flags)