I worked on the matrix transpose function NxN, which is stored in the floats array . My first implementation seemed to force the loop function endlessly, and I can't figure out why. Here is the source code:
for(int i = 0; i < numRows % 2 == 0 ? numRows / 2 : numRows / 2 + 1; i++)
{
for(int j = i + 1; j < numColumns; j++)
{
}
}
However, the function never returns. Having not received an error in my logic, I rephrased the expression and now I got the following working code:
int middleRow = numRows % 2 == 0 ? numRows / 2 : numRows / 2 + 1;
for(int i = 0; i < middleRow; i++)
{
for(int j = i + 1; j < numColumns; j++)
{
}
}
Does anyone help explain why the first version does not work, but seems to be equivalent to the second version?
source
share