From 67a395794b678d7da053c3daf61eb12d3f9437f2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 12 Nov 2017 14:44:35 +0100 Subject: Split into multiple units MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- doubletotimespec.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 doubletotimespec.c (limited to 'doubletotimespec.c') diff --git a/doubletotimespec.c b/doubletotimespec.c new file mode 100644 index 0000000..8b2cccd --- /dev/null +++ b/doubletotimespec.c @@ -0,0 +1,22 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" + + +void +libsimple_doubletotimespec(struct timespec *ts, double d) +{ + double ns = (long long int)d; + long int nsi; + ns = d - ns; + ns *= (double)1000000000L; + nsi = (long int)ns; + if (2 * (ns - (double)nsi) >= 1) { + nsi += 1; + if (nsi == 1000000000L) { + nsi = 0; + d += 1; + } + } + ts->tv_sec = (time_t)d; + ts->tv_nsec = nsi; +} -- cgit v1.2.3-70-g09d2