mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-04 13:29:51 -05:00
Add support for signed 24.8 decimal numbers
'fixed' is a signed decimal type which offers a sign bit, 23 bits of integer precision, and 8 bits of decimal precision. This is exposed as an opaque struct with conversion helpers to and from double and int on the C API side. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
parent
c49f632dae
commit
c5aba11acc
6 changed files with 81 additions and 3 deletions
|
|
@ -27,6 +27,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
|
@ -165,6 +166,29 @@ void wl_array_release(struct wl_array *array);
|
|||
void *wl_array_add(struct wl_array *array, size_t size);
|
||||
void wl_array_copy(struct wl_array *array, struct wl_array *source);
|
||||
|
||||
typedef int32_t wl_fixed_t;
|
||||
#define WL_FIXED_INVALID_VALUE ~0L
|
||||
|
||||
static inline double wl_fixed_to_double(wl_fixed_t f)
|
||||
{
|
||||
return (double) f / 256.0;
|
||||
};
|
||||
static inline wl_fixed_t wl_fixed_from_double(double d)
|
||||
{
|
||||
if (d >= (1 << 23))
|
||||
return WL_FIXED_INVALID_VALUE;
|
||||
return (wl_fixed_t) round (d * 256.0);
|
||||
};
|
||||
|
||||
static inline int wl_fixed_to_int(wl_fixed_t f)
|
||||
{
|
||||
return f / 256;
|
||||
}
|
||||
static inline wl_fixed_t wl_fixed_from_int(int i)
|
||||
{
|
||||
return wl_fixed_from_double(i);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue