Edit(Third time): Responding to the answers so far, let me clear something:
- @Lưu Vĩnh Phúc as he acutely pointed out, in my original expression,
the precision of an arithmetic operation is decided by the precision of the less precise operand.
I should use accuracy instead of precision. I.e.
the accuracy of an arithmetic operation is decided by the accuracy of the less accurate operand.
YES, I accidentally used precision instead of accuracy, and continued to use it in many of my argument. I apologize for my stupid mistake and corresponding confusion.
So the question is restated:
For example:
auto test=100. *3.f;
Then, the variable test is of double type.
I am puzzled by this choice. Because mathematically speaking, the accuracy of an arithmetic operation is decided by the accuracy of the less accurate operand. In our case, 3.f has already been unable to guarantee its accuracy after at most 8 digits, what's the point of storing test as a double with a possibly misleading impression of 15-digit precision?
My guess is it is possibly related to the exponent, but in this case, the result is 300 which doesn't fall out of the range of float. Or is there any historical reason?
Many thanks,
I apologize again for my stupidity.
To summarize the answers so far: 1, yes, it's about range; 2, when double*float->double, there is a lot of truncation.