diff options
Diffstat (limited to 'doubletotimespec.c')
-rw-r--r-- | doubletotimespec.c | 12 |
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; + } } |