Is there any reason this isn't redundant code?
-
27-09-2019 - |
Question
I came across this code in some existing codebase:
double rad = ComputeCurviness();
double off = Math.Abs(rad);
if (rad < 0) off = -off;
It seems to be basically just making off
equal to rad
. The variables are used interchangeably later in the code. Is there any reason to leave this code in?
Solution
If rad
is -0.0, off
will be +0.0. You'd have to inspect the code to see whether this would actually make a difference. The two are equivalent when it comes to calculations and comparisons, but -0.0 is negative, which you can detect if you try hard enough.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow