Mercurial > hg > fxanalyse
view utils.c @ 258:5296f3bcd160
Implement DDS clients reconnect
On network send() failures try to reconnect to the server before
returning an error. This allows to restart the network servers
controlling the DDSes wiothout having to restart the clients.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 16 Jun 2015 14:31:35 +0200 |
parents | be87c8e78266 |
children |
line wrap: on
line source
#include <ansi_c.h> const char * thousands(char *buffer, int size, char *fmt, double val) { /* compute how many separators we need */ #pragma DisableFunctionRuntimeChecking log10 int nsep = log10(fabs(val)); nsep = (nsep > 0 ? nsep / 3 : 0); /* format value */ int len = snprintf(buffer, size, fmt, val); char *src = buffer + len; char *dst = src + nsep; /* copy till decimal separator */ while (*src != '.') *dst-- = *src--; /* the next char is the decimal separator */ int n = -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-- = ' '; } return buffer; } double Peta(double x) { return 1.0e15 * x; } double Tera(double x) { return 1.0e12 * x; } double Giga(double x) { return 1.0e9 * x; } double Mega(double x) { return 1.0e6 * x; } double kilo(double x) { return 1.0e3 * x; } double milli(double x) { return 1.0e-3 * x; } double micro(double x) { return 1.0e-6 * x; } double nano(double x) { return 1.0e-9 * x; } double pico(double x) { return 1.e-12 * x; } double femto(double x) { return 1.0e-15 * x; }