[PATCH v4] dix: add utility functions for double to/fro FP1616/FP3232 conversion

Mark Kettenis mark.kettenis at xs4all.nl
Sat Oct 15 06:57:33 PDT 2011


> From: Jeremy Huddleston <jeremyhu at apple.com>
> Date: Fri, 14 Oct 2011 18:44:55 -0700
> 
> Co-authored-by: Jeremy Huddleston <jeremyhu at apple.com>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
> Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
> ---
>  dix/inpututils.c     |   63 ++++++++++++++++++++++++
>  include/inpututils.h |    6 ++
>  test/input.c         |  128 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 197 insertions(+), 0 deletions(-)
> 
> diff --git a/dix/inpututils.c b/dix/inpututils.c
> index 0a3d3d8..cd45773 100644
> --- a/dix/inpututils.c
> +++ b/dix/inpututils.c
> @@ -759,3 +759,66 @@ input_option_set_value(InputOption *opt, const char *value)
>      if (value)
>          opt->value = strdup(value);
>  }
> +
> +
> +/* FP1616/FP3232 conversion functions.
> + * Fixed point types are encoded as signed integral and unsigned frac. So any
> + * negative number -n.m is encoded as floor(n) + (1 - 0.m).
> + */
> +double
> +fp1616_to_double(FP1616 in)
> +{
> +    double ret;
> +
> +    ret  = (double)(in >> 16);
> +    ret += (double)(in & 0xffff) * (1.0 / (1UL << 16)); /* Optimized: ldexp((double)(in & 0xffff), -16); */
> +    return ret;

Hmm, is it just me, or do others also think that this comment makes
very little sense?  The current implementation is a very readable
implementation of a fixed-point to floating-point conversion.  The one
with ldexp() is less obvious to me since I'd have to look up what
ldexp(3) does. The only benefit I can see that the ldexp(3) variant
has, is that it is more portable.  So I wouldn't call this an
optimization.  And the comment makes the line (too) long, so I would
just drop it.  Same for the other comments that are similar.

Either way.

Reviewed-by: Mark Kettenis <kettenis at openbsd.org>


More information about the xorg-devel mailing list