Two methods for finding a sprite in sprite sheet C++, which is better? I have two snippets of code that I would like you to look at. I can't figure out which of the two is most efficient (or better practice, if applicable). I'm currently finding the row and column of a sprite in a sprite sheet in order to render it to the screen; which works find and dandy. However, I now have two algorithms:

const double Testvalue = 155.0f; //This values changes, could be any natural number.
const double imageWidth = 614.0f; 
const double SpriteAverageSize = 34.0f; //floor(value / spriteAverageSize) gives us max rows (which is this case is 18).

double numRows = floor(imageWidth / SpriteAverageSize);
double RowValue = ceil(Testvalue / numRows);
double ColumnValue = numRows - ((numRows  * RowValue) - Testvalue);

//This will do the following operation: 
//numRows = floor(614.0/ 34.0) -&gt; floor(18.05..) -&gt; 18.0.
//RowValue = ceil(155.0/ 18.0) -&gt; ceil(8.611..) -&gt; 9.0.
//ColumnValue = 18.0 - ((18.0 * 9.0) - 155.0) -&gt; 18.0 - (162.0 - 155.0) -&gt; 18.0 - 7.0 -&gt; 11.0.

//Row: 9 ; Column: 11.


or

const double Testvalue = 155.0f;
const double imageWidth = 614.0f;
const double SpriteAverageSize = 34.0f;

double RowValue = ceil(Testvalue / floor(imageWidth / SpriteAverageSize));
double ColumnValue = floor(imageWidth / SpriteAverageSize) - ((floor(imageWidth / SpriteAverageSize) * RowValue) - Testvalue);

//This will do the following operation:
//RowValue = ceil(155.0 / floor(614.0 / 34.0)) -&gt; ceil(155.0 / floor(18.05..)) -&gt; ceil(155.0 / 18.0) -&gt; ceil(8,61..) -&gt; 9.0.
//ColumnValue = floor(614.0 / 34.0) - ((floor(614.0 / 34.0) * 9.0) - 155.0) -&gt; floor(18.05..) - ((floor(18.05..) * 9.0) - 155.0) -&gt; 18.0 - ((18.0 * 9.0) - 155.0) -&gt; 18.0 - 7.0 -&gt; 11.0.

//Row: 9 ; Column: 11


To clarify, these two work perfectly (I have also implemented it as a method in my class to do the operation as I get the data from an XML file), I get the right row and column value as I've tested several times and implementing it works too. I would just like some tips on which of the two algorithms you'd prefer in a block of code and which of the two is more efficient?
I prefer the first one, because having the named variable numRows:


Certainly makes the code more "self-documenting": it's easier for me (the programmer) to understand what the algorithm is doing
May make the code faster: because you only do the floor(imageWidth / SpriteAverageSize) calculation once instead of three times (although it's possible that an optimizing compiler might be able to make that optimization itself, even without your 'hint' that it's a reused sub-expression)