source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Fix floating point handling: When converting double to size_t,
@ 2014-08-01 19:38 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-08-01 19:38 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        term.c

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.225
retrieving revision 1.226
diff -Lterm.c -Lterm.c -u -p -r1.225 -r1.226
--- term.c
+++ term.c
@@ -793,7 +793,7 @@ term_vspan(const struct termp *p, const 
 
 	if (r < 0.0)
 		r = 0.0;
-	return((size_t)r);
+	return((size_t)(r + 0.0005));
 }
 
 size_t
@@ -804,5 +804,5 @@ term_hspan(const struct termp *p, const 
 	v = (*p->hspan)(p, su);
 	if (v < 0.0)
 		v = 0.0;
-	return((size_t)v);
+	return((size_t)(v + 0.0005));
 }
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-08-01 19:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 19:38 mdocml: Fix floating point handling: When converting double to size_t, schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).