   Mathematical problem. Get next size dividable by a certain number.
  (I guess this is more of a math question than anything else..)Let's pretend we have a grid that needs to be at least as large as a specific area. If the grid is 256x256 in size and each grid square has to be 8x8 in size, that easily fits and we can do 32x32 squares.But if the grid is 257x257 or some other number that we can't divide evenly, and we still want to maintain the square size - what do I do from here?(It doesn't matter if the grid is slightly larger than the area, it just needs to cover it..)This "solves" it, but it's ugly as sin.int xSize = 257;int ySize = 257;int x = 0;while (x < xSize)    x += 8;int y = 0;while (y < xSize)    y += 8;I would love to see a mathematical solution to it without the loops. I can't figure it out though.Any takers?   
  How about:x = ceil(xSize/8.0)*8; // ceil rounds upor if you think ceil is slower than an extra row/columnx = (xSize/8+1)*8; //since everything is int, the quotient is rounded down//This means you will have and unnecessary extra row/column if xSize can be divided with 8 without remainder   ;Quote:Original post by szecsHow about:x = ceil(xSize/8.0) // ceil rounds upor if you think ceil is slower than an extra row/columnx = xSize/8+1Hi Szecs, thanks for your suggestion! :)On one hand, that's not what I wanted to do. I wanted to increase the grid size. But on the other hand, your suggestion is perfectly valid for that too!Edit: Either you edited your post while I was editing, or I misread. In any case, your solution is perfect. ;) ++!float newX = ceil(xSize/8.0) * 8.0;Thank you!   ;  Edited.I think the second solution (the one without ceil) is much faster.   ;x = xSize + (8 - xSize % 8);;  CaspianB, your snippit assumes that square size and grid size are integers. They are in the code I posted, but in reality it should be able to handle anything the user throws at it. Sorry about that, I was vague. Thanks though!   ;  Using all integer arithmetic, n*(x+n-1)/ne.g.8*(257+7)/8 = 264   