From 8ac43ac5b8a505ffe77a673dc560c2d6eac40174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Sun, 15 Dec 2013 17:47:45 +0100 Subject: [PATCH] Export li_fixed_to_(int|double) converters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Ã…dahl --- src/libinput.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/libinput.h b/src/libinput.h index b591bd0e..e63e36c4 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -163,6 +163,45 @@ struct libinput_event_pointer_button; struct libinput_event_pointer_axis; struct libinput_event_touch_touch; +/** + * @defgroup fixed_point Fixed point utilities + */ + +/** + * @ingroup fixed_point + * + * Convert li_fixed_t to a double + * + * @param f fixed point number + * @return Converted double + */ +static inline double +li_fixed_to_double (li_fixed_t f) +{ + union { + double d; + int64_t i; + } u; + + u.i = ((1023LL + 44LL) << 52) + (1LL << 51) + f; + + return u.d - (3LL << 43); +} + +/** + * @ingroup fixed_point + * + * Convert li_fixed_t to a int. The fraction part is discarded. + * + * @param f fixed point number + * @return Converted int + */ +static inline int +li_fixed_to_int(li_fixed_t f) +{ + return f / 256; +} + /** * @defgroup event Acessing and destruction of events */