[PATCH 02/27] Input: Add round_towards_zero helper

Daniel Stone daniel at fooishbar.org
Fri Jun 3 07:59:38 PDT 2011


lrint() exists to round _away_ from zero, but there's no equivalent for
rounding towards zero, aside from tediously calling fesetenv(), which
isn't hugely portable anyway, then lround().  Great.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 dix/inpututils.c |    9 +++++++++
 include/input.h  |    2 ++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 49e1758..bf8d093 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -584,3 +584,12 @@ void verify_internal_event(const InternalEvent *ev)
         FatalError("Wrong event type %d. Aborting server\n", ev->any.header);
     }
 }
+
+double
+round_towards_zero(double val)
+{
+    if (val >= 0.0)
+        return floor(val);
+    else
+        return ceil(val);
+}
diff --git a/include/input.h b/include/input.h
index 56847ed..a15623a 100644
--- a/include/input.h
+++ b/include/input.h
@@ -594,4 +594,6 @@ extern _X_EXPORT void valuator_mask_copy(ValuatorMask *dest,
                                          const ValuatorMask *src);
 extern _X_EXPORT int valuator_mask_get(const ValuatorMask *mask, int valnum);
 
+extern _X_EXPORT double round_towards_zero(double val);
+
 #endif /* INPUT_H */
-- 
1.7.5.3



More information about the xorg-devel mailing list