Mercurial > hg > fxanalyse
view future.c @ 248:eaac96094640
Minor style improvements
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 04 May 2015 17:46:52 +0200 |
parents | b955e35c07ae |
children |
line wrap: on
line source
/* welcome in the 2012 */ /* time functions */ #include <windows.h> #include <ansi_c.h> #include "future.h" /* an implementation of the C99 `round` function based on `floor` and `ceil` */ double round(double x) { if (x >= 0.0) { double y = floor(x); if (x - y >= 0.5) y += 1.0; return y; } else { double y = ceil(x); if (x - y >= 0.5) y -= 1.0; return y; } } /* implement high resolution time service */ int gettimeofday(struct timeval *tp, struct timezone *tzp) { /* difference between 1970-01-01 and 1601-01-01 in 100-nanoseconds intervals */ const unsigned __int64 shift = 116444736000000000ULL; union { FILETIME ft; unsigned __int64 integer; /* 100-nanoseconds since 1601-01-01 */ } now; /* retrive system time in UTC. the resolution is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds */ GetSystemTimeAsFileTime(&now.ft); /* shift to epoch and truncate to microseconds */ now.integer = (now.integer - shift) / 10LL; tp->tv_usec = (long)(now.integer % 1000000LL); tp->tv_sec = (long)(now.integer / 1000000LL); /* FIXME CVI redefines the epoch as seconds since 1900-01-01 ! */ tp->tv_sec += 2208988800; return 0; }