[postgis-devel] strange behavoir of LW_ABS
Mateusz Loskot
Mateusz.Loskot at cadcorp.com
Wed Sep 16 04:55:28 PDT 2009
nicklas.aven at jordogskog.no wrote:
> Maybe this is my lack of c-knowledge, but i'm very confused of
> the behavior of LW_ABS
> The code below I thought would return -1, but i returns -3.
You mean positive 1.
> Is this expected behavior?
>
> Why do we have LW_ABS() instead of fabs() ?
>
>
> #include <stdio.h>
> #define LW_ABS(a) ((a) < (0) ? (-a) : (a))
> int main()
> {
> int d,e,f;
> d = 1;
> e = -2;
> f = LW_ABS(d+e);
Replace with:
f = LW_ABS( (d+e) );
And see if there is any difference.
Yet another example of evilness of macros ;-)
Best regards,
--
Mateusz Loskot
Senior Programmer, Cadcorp
http://www.cadcorp.com
****************************************************************************
This email is confidential and may be privileged and should not be used,
read or copied by anyone who is not the original intended recipient. If you
have received this email in error please inform the sender and delete it
from your mailbox or any other storage mechanism. Unless specifically
stated, nothing in this email constitutes an offer by Cadcorp and Cadcorp
does not warrant that any information contained in this email is accurate.
Cadcorp cannot accept liability for any statements made which are clearly
the sender's own and not expressly made on behalf of Cadcorp or one of its
agents. Please rely on your own virus check. No responsibility is taken by
Cadcorp for any damage arising out of any bug or virus infection.
****************************************************************************
More information about the postgis-devel
mailing list