GNU bug report logs - #13419
make 'eabs' act more like a function

Previous Next

Package: emacs;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Sat, 12 Jan 2013 06:51:01 UTC

Severity: minor

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 13419 <at> debbugs.gnu.org
Subject: bug#13419: make 'eabs' act more like a function
Date: Sat, 12 Jan 2013 08:25:06 -0500
> This patch doesn't fix any bugs, it's just a code cleanup.

[...]

> -/* We used to use `abs', but that clashes with system headers on some
> -   platforms, and using a name reserved by Standard C is a bad idea
> -   anyway.  */
> -#if !defined (eabs)
> -#define eabs(x)         ((x) < 0 ? -(x) : (x))
> +/* Return the absolute value of X, without evaluating X more than once.
> +   X should be a signed integer, and X's absolute value should not
> +   exceed the maximum for its promoted type.
> +
> +   If _Generic or typeof works, speed things up a bit by avoiding the
> +   conversion to intmax_t.  The "~" promotes X's type, and checks that
> +   X is an integer.  */
> +#if HAVE_C__GENERIC
> +# define eabs(x) \
> +    (_Generic (~ (x), int: abs, long: labs, long long: llabs, default: imaxabs) \
> +     (x))
> +#elif HAVE_TYPEOF
> +# define eabs(x) ({ typeof (~ (x)) eabsx = x; eabsx < 0 ? -eabsx : eabsx; })
> +#else
> +# define eabs(x) imaxabs (x)
>  #endif
 
Huh?  Do you really consider this code cleaner?  It's hideous and
impenetrable.  Not cool!


        Stefan




This bug report was last modified 12 years and 209 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.