//Title: Bound Constraint Snippet
//Credit to: Jtgibson
//Contributed by: Jtgibson
/*
A very simple preprocessor macro designed to make life a lot easier. It
restricts a number to a low and high bound -- numbers over or under those bounds
are automatically set to equal the minimum or maximum bound respectively.
*/
#define CONSTRAIN(lo,X,hi) (((X)>(hi))?(hi):(((X)<(lo))?(lo):(X)))
///*
//Testing code/sample implementation
mob/verb/test_constrain(num as num)
usr << "Your num is constrained to a minimum of 0 and a maximum of 100."
usr << CONSTRAIN(0,num,100)
//*/
ID:195155
Nov 21 2006, 5:42 am (Edited on Mar 9 2007, 1:26 pm)
|
|