#define SQR(X) ((X)*(X)) //Classic Square
#define Percent(X,Y) ((X/100)*(Y)) //Find the percentage: X is the inital value - Y is the percentage
#define BoostPercent(X,Y) (X+(X/100)*(Y)) //Boost a value by a percentage: Same structure as above
#define floor(x) round(x) //Rounds number down, toward zero, to the nearest multiple of significance.
#define ceil(x) (-round(-(x))) //Returns number rounded up, away from zero, to the nearest multiple of significance
#define OddOrEven(X) ((X & 1) != 0) //Returns true if a value is Odd, false if it's Even (up to 1e+010)
#define InRange(X,Y,Z) (X <= Y && Y <= Z) //Check if a value is in range: X is lowest parameter, Y is your value, Z is the highest parameter
I was just curious to see what common #define directives people used in their projects that could apply to others. These will obviously be calculations for the most part. Here are a few I often use -
|
#define DEBUG
Everything else is either something to do with the interface, or names or specific array values. |
Take a look at +Preprocess.dm here. Most of my programings (including libraries) have a file like that, so you can look at a lot of my stuff and see what I use.
|
Erm, your 'classic' square root define is actually x squared, not square root x.
I sometimes use defines for bit flags and the like, but I don't tend to define many functions. |
Oh, and now that I look at this, you're doing something very bad with your definitions here. Each preprocesser "argument" in the output-area-thingie should have parantheses around it, or else OoO could screw you over.
|
I know this doesn't matter but for OddEven you could also do the following:
#define OddEven(x) ((x%2)!=0) It's the same concept as in, it returns true if odd and false for even. also here are a couple of my definations from my projects: #define percentage2decimal(num,maxPercentage)(num/maxPercentage) #define decimal2percentage(num,maxPercentage)(num*maxPercentage) |
Because I'm so irritated with having to check if(m.client) for whatever reason.