home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / gnu / gcc / help / 1907 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  1.2 KB

  1. Path: sparky!uunet!stanford.edu!rutgers!cbmvax!schmid
  2. From: schmid@deneb.cbmvax.cbm.commodore.com (Bob Schmid)
  3. Newsgroups: gnu.gcc.help
  4. Subject: Question on optimizing "abs()"
  5. Message-ID: <34264@cbmvax.commodore.com>
  6. Date: 14 Aug 92 16:44:38 GMT
  7. Sender: news@cbmvax.commodore.com
  8. Distribution: gnu.gcc.help
  9. Organization: Commodore Technology West Chester, PA
  10. Lines: 33
  11.  
  12. I would like to write code for gcc 2.2 that will take the absolute
  13. value of a double in the fastest possible way (for a tight inner
  14. loop).
  15.  
  16. I currently do this
  17.  
  18.   double num;
  19.   if (num < 0)
  20.     num *= -1;
  21.  
  22. but it occurs to me that rather than doing the test, possibly followed
  23. by a multiply, it may be cheaper to just force the IEEE sign bit to be
  24. positive somehow (just one operation).  Any suggestions on how best to
  25. do this for a double, float or int will be most appreciated.
  26.  
  27. I'm running on a sun IPX, using gcc -O.
  28.  
  29.  
  30.  
  31. Thanks,
  32.  
  33. -Bob
  34.  
  35. ------------------------------------------------------
  36. R. Schmid     <uunet!cbmvax!schmid>
  37.               <schmid@cbmvax.cbm.commodore.com>
  38.  
  39. Robert Schmid
  40. VLSI Design
  41. Commodore Technology
  42. 1200 Wilson Drive
  43. West Chester, PA  19380
  44. ------------------------------------------------------
  45.