From 7c776b600a048be404ca8331f99c5efc3fc211f0 Mon Sep 17 00:00:00 2001 From: schwarze Date: Fri, 8 Aug 2014 16:02:55 +0000 Subject: [PATCH] Fix floating point handling: When converting double to size_t, properly round to the nearest M (=0.001m), which is the smallest available unit. This avoids weirdness like (size_t)(0.6 * 10.0) == 5 by instead calculating (size_t)(0.6 * 10.0 + 0.0005) == 6, and so it fixes the indentation of the readline(3) manual. --- usr.bin/mandoc/term.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index fc8743ed3c6..8a27aea0f35 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.86 2014/08/08 16:00:23 schwarze Exp $ */ +/* $Id: term.c,v 1.87 2014/08/08 16:02:55 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -789,7 +789,7 @@ term_vspan(const struct termp *p, const struct roffsu *su) if (r < 0.0) r = 0.0; - return((size_t)r); + return((size_t)(r + 0.0005)); } size_t @@ -800,5 +800,5 @@ term_hspan(const struct termp *p, const struct roffsu *su) v = (*p->hspan)(p, su); if (v < 0.0) v = 0.0; - return((size_t)v); + return((size_t)(v + 0.0005)); } -- 2.20.1