[Solved] Get the sign of a number in C# without conditional statement


is there a way to get the sign of a number (any kind, not just integer)

Not for any number type, no. For an integer, you can test the most significant bit: if it’s 1, the number is negative. You could theoretically do the same with a floating point number, but bitwise operators don’t work on float or double.

4

solved Get the sign of a number in C# without conditional statement