diff utils.c @ 144:be87c8e78266

Code cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 14:45:24 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils.c	Wed Jan 22 14:45:24 2014 +0100
@@ -0,0 +1,78 @@
+#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;
+}
+