Sometimes I want to add more types of security around raw doubles. One idea that appears a lot would be to add information about unit types. For instance,
struct AngleRadians {
public readonly double Value;
}
In a case like the one above, where there is only one field, can the JIT optimize this abstraction in all cases? What situations, if any, will lead to additional generated machine instructions compared to similar code using a deployed double?
Any mention of premature optimization will be reduced. I am interested to know the truth.
Edit: To narrow down the questions, here are a few scenarios of particular interest ...
var angleRadians = new AngleRadians(myDouble);
var myDouble2 = myDouble;
var myDouble2 = angleRadians.Value;
var myDouble2 = myDouble;
static void DoNaught(AngleRadians angle){}
static void DoNaught(double angle){}
, . , , @EricLippert, , . , , , , , JIT , , ,