TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: KURT J. TISCHER
from: MIGUEL ANGEL SCAPOLLA
date: 1997-07-14 06:05:00
subject: RE: Signs of numbers

KT>       Does Visual C++ have a similar function?  If so, in what header 
ile
KT>is it located and what is the name of the function?  If not, would someone
KT>please show me a function to determine the sign of a number which would
KT>return 1 if positive, 0 if zero, and -1 if negative...?
This function is implemented with a ternary operator:
int sign = (value > 0) ? 1 : ((value < 0) ? -1 : 0);
This is equivalent to:
int sign;
if (value > 0)
   sign = 1;
else if (value < 0)
   sign = -1;
else
   sign = 0;
Or implement this function via macro definition:
#define SIGN(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))
And use this:
int z = SIGN (y);
        Miguel
========================================================
 Miguel Scapolla             miguelo@blader.com (email)
 Coronado City           miguelo@canopus.com.ar (email)
 Argentina                         4:901/148.30 (fido)
========================================================
--- MjrFIDO 3.25
--- Squish/386 v1.11
---------------
* Origin: ISP CANOPUS (BBS) * Bs.As.- ARGENTINA * +54 1 554-2222 (4:90/90)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.