In most recent versions of languages floating point literals are interpreted as type double if no type specifier is supplied.In the second case, the compiler stores the number as a single precision floating point. Then when the assignment is executed, it changes the representation from a single to a double precision number.
Not at all. The first four (non-commented) expressions were NOT done using doubles.Interesting, it looks like it does arithmetic in double always.
This is why I said that there were missing examples that would be instructive.You don’t know that. The fact that it prints in lower precision is because it was assigned to a float variable, which cannot hold double precision. It is possible that they took into account the left side when doing the operation, I as a compiler developer, doubt it. If it was a C compiler, the results would not confirn to the language specification.
That's the crux of my curiosity. Most languages do not specify the order in which subexpressions have to be evaluated, but they also don't specify the order in which operands have to be evaluated except in specific situations, such as when short-circuiting is possible. But C# explicitly requires that the 'a' and 'b' operands MUST be evaluated before 'c' and 'd'. If they are going to go to the trouble of requiring that, I'm suspicious that they also give no leeway in the order in which subexpressions are evaluated and that I just couldn't find where that requirement is laid out in the language spec. In the C language spec, the fact that the order is not specified is explicitly stated; I could not find any similar statement in the C# spec. But then there's a LOT of spec there and I only spent a few minutes skimming it.In your second example, c+d can be evaluated before a+b as long as they have no side effects.
The ordering operands is to make the order of the side effects predictable. For instance, if each of the operands is a function call, and the functions have side effects, then you cannot change the order in which those functions are called.That's the crux of my curiosity. Most languages do not specify the order in which subexpressions have to be evaluated, but they also don't specify the order in which operands have to be evaluated except in specific situations, such as when short-circuiting is possible. But C# explicitly requires that the 'a' and 'b' operands MUST be evaluated before 'c' and 'd'. If they are going to go to the trouble of requiring that, I'm suspicious that they also give no leeway in the order in which subexpressions are evaluated and that I just couldn't find where that requirement is laid out in the language spec. In the C language spec, the fact that the order is not specified is explicitly stated; I could not find any similar statement in the C# spec. But then there's a LOT of spec there and I only spent a few minutes skimming it.
by Jake Hertz
by Aaron Carman
by Jake Hertz