Mercurial > hg > fxanalyse
comparison utils.c @ 144:be87c8e78266
Code cleanup
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 14:45:24 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
143:09a4548e1436 | 144:be87c8e78266 |
---|---|
1 #include <ansi_c.h> | |
2 | |
3 const char * thousands(char *buffer, int size, char *fmt, double val) | |
4 { | |
5 /* compute how many separators we need */ | |
6 #pragma DisableFunctionRuntimeChecking log10 | |
7 int nsep = log10(fabs(val)); | |
8 nsep = (nsep > 0 ? nsep / 3 : 0); | |
9 /* format value */ | |
10 int len = snprintf(buffer, size, fmt, val); | |
11 char *src = buffer + len; | |
12 char *dst = src + nsep; | |
13 /* copy till decimal separator */ | |
14 while (*src != '.') | |
15 *dst-- = *src--; | |
16 /* the next char is the decimal separator */ | |
17 int n = -1; | |
18 /* copy till src and dst point to the same location */ | |
19 while (src != dst) { | |
20 *dst-- = *src--; | |
21 /* insert separator */ | |
22 if (isdigit(*src) && (++n) && ((n % 3) == 0)) | |
23 *dst-- = ' '; | |
24 } | |
25 return buffer; | |
26 } | |
27 | |
28 | |
29 double Peta(double x) | |
30 { | |
31 return 1.0e15 * x; | |
32 } | |
33 | |
34 double Tera(double x) | |
35 { | |
36 return 1.0e12 * x; | |
37 } | |
38 | |
39 double Giga(double x) | |
40 { | |
41 return 1.0e9 * x; | |
42 } | |
43 | |
44 double Mega(double x) | |
45 { | |
46 return 1.0e6 * x; | |
47 } | |
48 | |
49 double kilo(double x) | |
50 { | |
51 return 1.0e3 * x; | |
52 } | |
53 | |
54 double milli(double x) | |
55 { | |
56 return 1.0e-3 * x; | |
57 } | |
58 | |
59 double micro(double x) | |
60 { | |
61 return 1.0e-6 * x; | |
62 } | |
63 | |
64 double nano(double x) | |
65 { | |
66 return 1.0e-9 * x; | |
67 } | |
68 | |
69 double pico(double x) | |
70 { | |
71 return 1.e-12 * x; | |
72 } | |
73 | |
74 double femto(double x) | |
75 { | |
76 return 1.0e-15 * x; | |
77 } | |
78 |