aboutsummaryrefslogtreecommitdiffstats
path: root/doubletotimespec.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-26 12:49:12 +0200
committerMattias Andrée <maandree@kth.se>2018-08-26 12:49:12 +0200
commitf2378869e1a3b1cb44b5c7973e0a9acfb2559d0f (patch)
treee8caadeb4359bb62c7ba0b13ce94704220dd9ac7 /doubletotimespec.c
parentTests and minor improvements (diff)
downloadlibsimple-f2378869e1a3b1cb44b5c7973e0a9acfb2559d0f.tar.gz
libsimple-f2378869e1a3b1cb44b5c7973e0a9acfb2559d0f.tar.bz2
libsimple-f2378869e1a3b1cb44b5c7973e0a9acfb2559d0f.tar.xz
Fixes, more test, and add minimise_number_string
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'doubletotimespec.c')
-rw-r--r--doubletotimespec.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/doubletotimespec.c b/doubletotimespec.c
index e74f04a..a71d662 100644
--- a/doubletotimespec.c
+++ b/doubletotimespec.c
@@ -3,7 +3,7 @@
void
-libsimple_doubletotimespec(struct timespec *ts, double d) /* TODO test */
+libsimple_doubletotimespec(struct timespec *ts, double d)
{
double ns = (long long int)d;
long int nsi;
@@ -16,7 +16,17 @@ libsimple_doubletotimespec(struct timespec *ts, double d) /* TODO test */
nsi = 0;
d += 1;
}
+ } else 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;
+ if (ts->tv_nsec < 0) {
+ ts->tv_sec -= 1;
+ ts->tv_nsec += 1000000000L;
+ }
}