Mercurial > hg > fxanalyse
diff FXAnalyse.c @ 128:8a69c40f10b2
Fix thousands separators number formatting function.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 16 Dec 2013 19:50:20 +0100 |
parents | 2479ad53982b |
children | 24db0c2d5219 |
line wrap: on
line diff
--- a/FXAnalyse.c Fri Dec 13 17:04:28 2013 +0100 +++ b/FXAnalyse.c Mon Dec 16 19:50:20 2013 +0100 @@ -162,22 +162,23 @@ char * thousands(char *buffer, int size, char *fmt, double val) { // compute how many separators we need - int nsep = (int)(log10(fabs(val)+1.0))/3; + #pragma DisableFunctionRuntimeChecking log10 + int nsep = log10(fabs(val)) / 3; // format value int len = snprintf(buffer, size, fmt, val); - char *src = buffer + len + 1; + char *src = buffer + len; char *dst = src + nsep; // copy till decimal separator while (*src != '.') *dst-- = *src--; - // copy till the beginning inserting separators + // the next char is the decimal separator int n = -1; - while (1) { + // copy till src and dst point to the same location + while (src != dst) { *dst-- = *src--; + // insert separator if (isdigit(*src) && (++n) && ((n % 3) == 0)) *dst-- = ' '; - if (src == buffer) - break; } return buffer; }