[PATCH 0/2] XIPropToInt and XIPropToFloat APIs

Roland Mainz roland.mainz at nrubsig.org
Wed Dec 17 16:44:33 PST 2008

Peter Hutterer wrote:
> These two patches add two new APIs to the server.
> XIPropToInt - convert the given property into an integer array
> XIPropToFloat - convert the given property into an float array
> More importantly, the second patch also adds XATOM_FLOAT as a server-defined
> property that drivers can use to denote float properties (the synaptics driver
> is waiting for exactly that, and so is property support for pointer
> acceleration).
> Requirement for this to work is that both client and server store floats in
> IEEE 754 format and that the client stores float in the same byte ordering as
> everything else. Which - unless I misunderstood the material - is more than
> likely.

Erm... I strongly suggest not trying that. This quickly runs into a vey
special hell where each platform interprets IEEE754-1985 in it's own
subtle way (IEEE754-2008 will clean this partially up but it will take
some years until we see support for this). In the best case it works, in
the worst case you'll get corrupt data, differenly sized float types or
a SIGFPE (for example some platforms have nasty behaviour for payloads
within NaN values) ...

... I suggest to follow C99/XPG6 in this case which defines a new format
option for |printf()|/|scanf()| called "%a" which provides a portable
hexadecimal floating-point ("hexfloat") representation which is portable
across all platforms, independent of endian/float encodings and
_guranteed_ to return the same output value for the serialied input
value (e.g. no rounding errors caused by base2--->base10--->base2

-- snip --
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int main(int ac, char *av[])
	char   buff[256];
        double x=1.1,
        sprintf(buff, "%a", x);
        printf("buff contains '%s'\n", buff);

        printf("y    contains '%g'\n", y);
        return EXIT_SUCCESS;
-- snip --
... should print:
-- snip --
buff contains '0x1.199999999999ap+0'
y    contains '1.1'
-- snip --



  __ .  . __
 (o.\ \/ /.o) roland.mainz at nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

More information about the xorg mailing list