//Title: Miscellaneous Logical Utilities Snippet
//Credit to: Jtgibson
//Contributed by: Jtgibson
/*
These are a couple of logical number operations that are useful in some circum-
stances. You use them in if() statements for the most part, though you might be
able to find creative uses for them as well.
*/
#define ispos(num) ((num) >= 0)
#define isneg(num) ((num) < 0)
#define iseven(num) !((num) % 2)
#define isodd(num) ((num) % 2)
/*
//Testing code/sample implementation:
mob/verb/test_logic(num as num)
if(ispos(num))
if(iseven(num))
usr << "Your number is positive and even."
//if(isodd(num)) isn't necessary, but I'm demonstrating the use
else if(isodd(num))
usr << "Your number is positive and odd."
else if(isneg(num))
if(iseven(num))
usr << "Your number is negative and even."
else if(isodd(num))
usr << "Your number is negative and odd."
*/
ID:195150
Nov 21 2006, 6:55 am
|
|