TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: KURT J. TISCHER
from: JAVIER KOHEN
date: 1997-07-18 16:54:00
subject: Signs of numbers

On 08-Jul-97, Kurt J. Tischer wrote to All about Signs of numbers.
 KJT> is it located and what is the name of the function?  If not, would 
 KJT> someone
 KJT> please show me a function to determine the sign of a number which would
 KJT> return 1 if positive, 0 if zero, and -1 if negative...?
// You'd maybe like to template this f()
int foo(int num)
{
        if (num) {
                if (num > 0) {
                        return 1;
                } else {
                        return -1;
                }
        } else {
                return 0;
        }
}
Or a HD saver version:
int foo(int num) { return num ? (num > 0 ? 1 : -1) : 0; }
Internet: jkohen@tough.com þ Javier Kohen/The_Crusher þ 
ttp://jkohen.base.org
Fidonet: 4:900/748.3  þ  Sk-Network: 200:201/126  þ  Rockernet: 33:300/100.3
PGP keyID: 3423EAA9
... No, Taco Bell is *not* the Mexican telephone company!
-!- CrusherTag 0.3.2.
--- Terminate 4.00/Pro
4:900/748.3)
---------------
* Origin: The King of The Ring BBS þ +54-1-OFF-LINE þ TLD 0 - 7

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™.