aboutsummaryrefslogtreecommitdiffstats
path: root/doubletotimeval.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 /doubletotimeval.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 '')
-rw-r--r--doubletotimeval.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/doubletotimeval.c b/doubletotimeval.c
index c86c771..5396897 100644
--- a/doubletotimeval.c
+++ b/doubletotimeval.c
@@ -3,7 +3,7 @@
void
-libsimple_doubletotimeval(struct timeval *tv, double d) /* TODO test */
+libsimple_doubletotimeval(struct timeval *tv, double d)
{
double ns = (long long int)d;
long int nsi;
@@ -16,7 +16,17 @@ libsimple_doubletotimeval(struct timeval *tv, double d) /* TODO test */
nsi = 0;
d += 1;
}
+ } else if (2 * (ns - (double)nsi) <= -1) {
+ nsi -= 1;
+ if (nsi == -1000000L) {
+ nsi = 0;
+ d -= 1;
+ }
}
tv->tv_sec = (time_t)d;
tv->tv_usec = nsi;
+ if (tv->tv_usec < 0) {
+ tv->tv_sec -= 1;
+ tv->tv_usec += 1000000L;
+ }
}