Using "special values" is usually bad practice. I would prefer to use an object with some kind of status code, and then double (/ float / whatever), which is populated only if the status is not exclusive.
public class CalcNumber { public CalcNumberStatus Status {get; private set;} public double Value {get; private set;} public CalcNumber(double value) { Status = CalcNumberStatus.Normal; Value = value; } public CalcNumber(CalcNumberStatus status) { if(status == CalcNumberStatus.Normal) { throw new Exception("Cannot create a normal CalcNumber without a value"); } Status = status; Value = 0; } } public enum CalcNumberStatus { Normal, Error }
You can even do some fancy operator overloading to simplify the conversion and arithmetic if you need to.
As for accuracy problems, since it seems that you are not planning to do arithmetic on this number, therefore, you should not encounter accuracy problems that interfere with equality checking to work.
source share