From d4d54185af6c2217316cab75dae5de26a34d7ae2 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 23 Aug 2010 22:53:11 +0200 Subject: add lout::misc::roundInt() for double -> int conversion Add lout::misc::roundInt() and use it for double -> int conversion instead of doing the + 0.5 trick all over the place. It was wrong for negative values and we might even replace roundInt() with rint() from libm in the future. Reported-by: corvid --- lout/misc.hh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lout') diff --git a/lout/misc.hh b/lout/misc.hh index 393bac0c..e78e7576 100644 --- a/lout/misc.hh +++ b/lout/misc.hh @@ -38,6 +38,11 @@ inline void assertNotReached () abort (); } +inline int roundInt(double d) +{ + return (int) ((d > 0) ? (d + 0.5) : (d - 0.5)); +} + /** * \brief Instances of a sub class of this interface may be compared (less, * greater). -- cgit v1.2.3