Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/top/dist Be more careful/explicit with FP round...
details: https://anonhg.NetBSD.org/src/rev/664ccf2f4b2d
branches: trunk
changeset: 347487:664ccf2f4b2d
user: dholland <dholland%NetBSD.org@localhost>
date: Sat Aug 27 18:48:30 2016 +0000
description:
Be more careful/explicit with FP rounding when converting floating time
to timeval. Also, don't truncate the seconds part to int for y2038.
I've had this patch sitting around since 2010 and I completely forget
what motivated it.
diffstat:
external/bsd/top/dist/utils.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diffs (25 lines):
diff -r deb9503a5134 -r 664ccf2f4b2d external/bsd/top/dist/utils.c
--- a/external/bsd/top/dist/utils.c Sat Aug 27 16:17:16 2016 +0000
+++ b/external/bsd/top/dist/utils.c Sat Aug 27 18:48:30 2016 +0000
@@ -41,6 +41,7 @@
#include "os.h"
#include <ctype.h>
+#include <math.h>
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#else
@@ -711,8 +712,11 @@
void
double2tv(struct timeval *tv, double d)
{
- tv->tv_sec = (int)d;
- tv->tv_usec = (d - tv->tv_sec) * 1000000;
+ double di;
+
+ di = floor(d);
+ tv->tv_sec = (time_t)di;
+ tv->tv_usec = (int)ceil((d - di) * 1000000.0);
}
static int debug_on = 0;
Home |
Main Index |
Thread Index |
Old Index