home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!rutgers!cbmvax!schmid
- From: schmid@deneb.cbmvax.cbm.commodore.com (Bob Schmid)
- Newsgroups: gnu.gcc.help
- Subject: Question on optimizing "abs()"
- Message-ID: <34264@cbmvax.commodore.com>
- Date: 14 Aug 92 16:44:38 GMT
- Sender: news@cbmvax.commodore.com
- Distribution: gnu.gcc.help
- Organization: Commodore Technology West Chester, PA
- Lines: 33
-
- I would like to write code for gcc 2.2 that will take the absolute
- value of a double in the fastest possible way (for a tight inner
- loop).
-
- I currently do this
-
- double num;
- if (num < 0)
- num *= -1;
-
- but it occurs to me that rather than doing the test, possibly followed
- by a multiply, it may be cheaper to just force the IEEE sign bit to be
- positive somehow (just one operation). Any suggestions on how best to
- do this for a double, float or int will be most appreciated.
-
- I'm running on a sun IPX, using gcc -O.
-
-
-
- Thanks,
-
- -Bob
-
- ------------------------------------------------------
- R. Schmid <uunet!cbmvax!schmid>
- <schmid@cbmvax.cbm.commodore.com>
-
- Robert Schmid
- VLSI Design
- Commodore Technology
- 1200 Wilson Drive
- West Chester, PA 19380
- ------------------------------------------------------
-