Mercurial > hg > fxanalyse
view utils.c @ 234:b0b4b2aea43a
Correct normalization for Allan deviation plots
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 27 Oct 2014 18:15:47 +0100 |
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; }