Might be a silly question, but is there any reason to use Math.Sign?
Is there a speed/optimization thing with using Math.Sign rather than just using an if statement? Perhaps just a best practice/code readability preference?
if (rayDirX < 0)
stepX = -1;
else
stepX = 1;
//----------
stepX = (rayDirX < 0) ? (-1) : (1);
//----------
stepX = Math.Sign(rayDirX);
I doubt there is a functional difference or much, if any, perf difference but the Math.Sign version is a little more visibly straight forward. Especially in your example where the Type of rayDirX is not declared. But it’s pretty subtle and I wouldn’t criticize you for using either.
EDIT:
And one other thing, your example above has a slight bug. In the case of
0Math.Sign will return0. Here is the decompiled code out of the framework for Math.Sign: