I have a simple utility method that takes a decimal inch value and returns a fraction (i.e. turns 1.5 into 1 1/2") for display purposes. This is working just fine but Resharper is telling me that every case in my switch is 'Heuristically Unreachable' and giving a warning, I can't figure out why. Here is the method:
static string FractionalInches(double decimalInches)
{
//Set initial variables
string fraction = "";
//Round to an integer for full inches
int test = (int)Math.Round(decimalInches, 0);
if (Math.Abs(decimalInches-test) < SharedData.FloatPointTolerance) //Even inches, no fractions here
{ return test.ToString(); }
//Has a fraction
var fullInches = decimalInches - test < 0 ? test - 1 : test;
//get the fraction - rounded to 16ths.
double sixteenths = Math.Abs(decimalInches - test) * 16;
int sixt = (int)Math.Round(sixteenths, 0);
switch (sixt)
{
case 1:
fraction = "1/16";
break;
case 2:
fraction = "1/8";
break;
case 3:
fraction = "3/16";
break;
case 4:
fraction = "1/4";
break;
case 5:
fraction = "5/16";
break;
case 6:
fraction = "3/8";
break;
case 7:
fraction = "7/16";
break;
case 8:
fraction = "1/2";
break;
case 9:
fraction = "9/16";
break;
case 10:
fraction = "5/8";
break;
case 11:
fraction = "11/16";
break;
case 12:
fraction = "3/4";
break;
case 13:
fraction = "13/16";
break;
case 14:
fraction = "7/8";
break;
case 15:
fraction = "15/16";
break;
case 16:
fraction = "";
fullInches += 1;
break;
}
//construct and return the final string
return fraction == "" ? fullInches.ToString() : fullInches + " " + fraction;
}
It gives me the unreachable warning on every case in the switch statement, but I know it gets hit because I can send in decimal values and they return the correct fractions... Anyone know why R# is giving this warning? I can ignore it easy enough but don't understand why it's there in the first place.