# HG changeset patch # User Daniele Nicolodi # Date 1387219820 -3600 # Node ID 8a69c40f10b28d33adc1f0965694784122e9a3e5 # Parent 2479ad53982ba98f473ead7807e204edae9b9e68 Fix thousands separators number formatting function. diff -r 2479ad53982b -r 8a69c40f10b2 FXAnalyse.c --- 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; }