[PATCH] correcting mathematical nonsense

Alan Coopersmith alan.coopersmith at oracle.com
Thu Aug 13 18:37:25 PDT 2015


On 08/13/15 12:16 PM, Martin Burggraf wrote:
> ---
>   src/xkbtext.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

What git repo is this for?   libxkbfile?  (That's the only one
I found a src/xkbtext.c in.)

> diff --git a/src/xkbtext.c b/src/xkbtext.c
> index b5d4750..91abb86 100644
> --- a/src/xkbtext.c
> +++ b/src/xkbtext.c
> @@ -758,7 +758,7 @@ XkbGeomFPText(int val, unsigned format)
>       }
>       else {
>           whole = val / XkbGeomPtsPerMM;
> -        frac = val % XkbGeomPtsPerMM;
> +        frac = abs(val % XkbGeomPtsPerMM);
>           if (frac != 0)
>               snprintf(buf, bufsize, "%d.%d", whole, frac);
>           else
>

If this is for libxkbfile, then you've fixed part of the problem, but
not all of it - I extracted this out into a simple test program:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
     int val = atoi(argv[1]);
     int whole, frac, oldfrac;

     whole = val / 10;
     oldfrac = abs(val % 10);
     frac = abs(val % 10);
     printf("%d.%d   %d.%d\n", whole, oldfrac, whole, frac);

}

And this fixes it to no longer print the minus sign after the decimal
point, but loses track of whether a number between 0 & -1 is negative:

% ./abs -05
0.-5   0.5
% ./abs -10
-1.0   -1.0
% ./abs -15
-1.-5   -1.5

-- 
	-Alan Coopersmith-              alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc


More information about the xorg-devel mailing list