delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/09/30/14:55:34

To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: abs()olutely hopeless?
Date: Wed, 30 Sep 92 12:41:50 MST
From: mpsears AT newton DOT cs DOT sandia DOT gov

williams AT herky DOT cs DOT uiowa DOT edu (Kent Williams)

suggests using

#define ABS(x) ((x) < 0 ? -x : x)

which is almost right but will produce some obscure bugs. I suggest instead

#define ABS(x) ((x) < 0 ? -(x) : (x))

so that e.g. ABS(-a+b) works correctly. 

Mark Sears


- Raw text -


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