|
@ -11,6 +11,8 @@ |
|
|
|
|
|
|
|
|
#define BIN_INC_SIZE 2048 |
|
|
#define BIN_INC_SIZE 2048 |
|
|
|
|
|
|
|
|
|
|
|
#define FLOAT_BUFLEN (LDBL_DIG*2) |
|
|
|
|
|
|
|
|
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) |
|
|
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) |
|
|
|
|
|
|
|
|
#define MAYBE_PRETTY(e) \ |
|
|
#define MAYBE_PRETTY(e) \ |
|
@ -396,17 +398,17 @@ enc_double(Encoder* e, double val) |
|
|
size_t len; |
|
|
size_t len; |
|
|
size_t i; |
|
|
size_t i; |
|
|
|
|
|
|
|
|
if(!enc_ensure(e, 32)) { |
|
|
|
|
|
|
|
|
if(!enc_ensure(e, FLOAT_BUFLEN)) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
start = &(e->p[e->i]); |
|
|
start = &(e->p[e->i]); |
|
|
|
|
|
|
|
|
// try to encode doubles using the fewest digits possible... |
|
|
// try to encode doubles using the fewest digits possible... |
|
|
if (snprintf(start, 32, "%.*g", DBL_DIG, val) > FLT_DIG) |
|
|
|
|
|
|
|
|
if (snprintf(start, FLOAT_BUFLEN, "%.*g", DBL_DIG, val) > FLT_DIG) |
|
|
{ |
|
|
{ |
|
|
// ...fall back to full expansion to be safe |
|
|
// ...fall back to full expansion to be safe |
|
|
snprintf(start, 32, "%.*g", LDBL_DIG, val); |
|
|
|
|
|
|
|
|
snprintf(start, FLOAT_BUFLEN, "%.*g", LDBL_DIG, val); |
|
|
} |
|
|
} |
|
|
len = strlen(start); |
|
|
len = strlen(start); |
|
|
|
|
|
|
|
@ -416,7 +418,7 @@ enc_double(Encoder* e, double val) |
|
|
goto done; |
|
|
goto done; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(len > 29) return 0; |
|
|
|
|
|
|
|
|
if(len >= FLOAT_BUFLEN-2) return 0; |
|
|
|
|
|
|
|
|
// Force a decimal point |
|
|
// Force a decimal point |
|
|
start[len++] = '.'; |
|
|
start[len++] = '.'; |
|
|