I'm a real dolt when it comes to solving maths problems. I've made a function that returns the nearest specified multiple of a specified value, including a specified offset. I think it's pretty good, but I was hoping that someone could see if I'm doing it as efficiently as possible.
By offsets, I mean offsetting a series of multiples. For example, if the multiple is 5 and the offset is 2, the series will go like this:Code:int nMult(int value, int mult, int offset) { return ((mult*round((float)(value-offset)/mult))+offset); } int round(float value) { if ((value-int(value))<.5) return int(value); else return int(value)+1; }
2,7,12,17,22,27 etc.
The reason I made the function is that list box heights in Win32 operate with multiple 16, offset 6. Any height specified for the height of a list box is rounded to the nearest multiple and offset. This caused me problems, so I made a function to round my window height appropriately.



LinkBack URL
About LinkBacks


