Same question can be asked of float… or of MinValue.
I am thinking of using it as a special value. Will i see bugs due to precision? I don’t expect to do arithmetic with these numbers, just set them and that’s it.
Clarification: I am using this for a sentinel value.
Is it something that’s described in a C# spec?
It depends on how you use it.
If you’re using
double.MaxValueas 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 usedouble.MaxValueto indicate an “uninitialized” or “unknown” value. There are other ways to do this (e.g. with the nullabledouble?), but usingdouble.MaxValueis also reasonable assuming the value doesn’t naturally occur in your domain.If you have some arbitrary
doublevalue, though, and you want to see if it’s “equal” todouble.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 otherdoublevalue. The issue to be aware of here is with values that go beyonddouble.MaxValue, creating an overflow situation.