ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/09/30/15:53:41

Date: Wed, 30 Sep 92 14:18:37 CDT
From: "George Jetson" <pynq AT midway DOT uchicago DOT edu>
To: mpsears AT newton DOT cs DOT sandia DOT gov
Subject: Re: abs()olutely hopeless?
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

You wrote:
>#define ABS(x) ((x) < 0 ? -(x) : (x))
>so that e.g. ABS(-a+b) works correctly. 
>Mark Sears

Should that not actually be:

	#define ABS(x) \
		({typedef _tx = (x); \
			_tx _x = (x); \
			_x < 0 ? -_x : _x; })

(cribbed from the official #definition of max())

This yields the correct result when you do:

	foo = abs(bar += 17);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019