wl_fixed_to_double() function only correct when fixed value is greater than zero

Pekka Paalanen ppaalanen at gmail.com
Tue Jan 17 15:27:19 UTC 2023


On Mon, 16 Jan 2023 14:43:43 +0800
"程安絮" <chenganxu2014 at sina.com> wrote:

> In file main.go is my implementation of FixedToFloat64 vs
> wl_fixed_to_double, the comments can help you to understand my codes.
> Since event wl_touch::orientation's orientation arg is fixed value
> and can be negative, I think this bug is not acceptable. Besides, I
> don't understand how wl_fixed_to_double works, can anyone illustrate
> that for me? 
> 
> --------------------------------程安絮

Hi,

that wl_fixed_to_double() implementation in C is a far too smart trick
for no other good reason than trying to be fast in a case where speed
is not needed.

The human readable conversion would be:

double wl_fixed_to_double(wl_fixed_t f)
{
        return (double)f / 256.0;
}

The trick code seems to be just fine through. I've attached a test
program that iterates through all possible wl_fixed_t values and
ensures the trivial conversion agrees with the trick conversion.

I cannot explain how it works, but it does seem to work.


Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fixed.c
Type: text/x-c++src
Size: 641 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20230117/dee462bf/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20230117/dee462bf/attachment.sig>


More information about the wayland-devel mailing list