bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#13419: make 'eabs' act more like a function


From: Stefan Monnier
Subject: bug#13419: make 'eabs' act more like a function
Date: Sat, 12 Jan 2013 08:25:06 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]