view utils.c @ 265:da38cbbc7ec8

Add DDS clients test code To verify the portabiolity of the clients code and to make testing easier the test code is independent of the CVI environment and runtime.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Sun, 21 Jun 2015 14:44:33 +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;
}