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:
Daniel Stone 2012-05-08 17:17:25 +01:00 committed by Kristian Høgsberg
parent c49f632dae
commit c5aba11acc
6 changed files with 81 additions and 3 deletions

View file

@ -20,6 +20,7 @@
* OF THIS SOFTWARE.
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@ -287,6 +288,13 @@ validate_demarshal_h(struct marshal_data *data,
close(data->value.h);
}
static void
validate_demarshal_f(struct marshal_data *data,
struct wl_object *object, wl_fixed_t f)
{
assert(data->value.i == f);
}
static void
demarshal(struct marshal_data *data, const char *format,
uint32_t *msg, void (*func)(void))
@ -335,6 +343,12 @@ TEST(connection_demarshal)
memcpy(&msg[3], data.value.s, msg[2]);
demarshal(&data, "s", msg, (void *) validate_demarshal_s);
data.value.i = wl_fixed_from_double(-90000.2390);
msg[0] = 400200;
msg[1] = 12;
msg[2] = data.value.i;
demarshal(&data, "f", msg, (void *) validate_demarshal_f);
release_marshal_data(&data);
}
@ -400,6 +414,18 @@ TEST(connection_marshal_demarshal)
marshal_demarshal(&data, (void *) validate_demarshal_h,
8, "h", data.value.h);
data.value.i = wl_fixed_from_double(1234.5678);
marshal_demarshal(&data, (void *) validate_demarshal_f,
12, "f", data.value.i);
data.value.i = wl_fixed_from_double(-90000.2390);
marshal_demarshal(&data, (void *) validate_demarshal_f,
12, "f", data.value.i);
data.value.i = wl_fixed_from_double((1 << 23) - 1 + 0.0941);
marshal_demarshal(&data, (void *) validate_demarshal_f,
12, "f", data.value.i);
release_marshal_data(&data);
}