It depends on how you use it.
If you're using double.MaxValue
as a token or sentinel value that has special semantics, then yes, it's just a bit pattern that you're comparing against. For example, you could use double.MaxValue
to indicate an "uninitialized" or "unknown" value. There are other ways to do this (e.g. with the nullable double?
), but using double.MaxValue
is also reasonable assuming the value doesn't naturally occur in your domain.
If you have some arbitrary double
value, though, and you want to see if it's "equal" to double.MaxValue
, then you'll want to see if the numbers are within some small range (epsilon) of each other since some precision could've been lost when computing your other double
value. The issue to be aware of here is with values that go beyond double.MaxValue
, creating an overflow situation.
float minA = float.MaxValue; foreach (float a ...) if (a < minA){ minA = a; ... }
I do this when I need to track other values that are associated with thosea
s. – Bulgaria