So why double to float conversion is implicit ?

Jerry hurricane at hereiam.com
Sun Oct 22 15:45:29 UTC 2017


On Sunday, 22 October 2017 at 10:57:24 UTC, NX wrote:
> On Sunday, 22 October 2017 at 02:25:44 UTC, codephantom wrote:
>> On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote:
>>> Interestingly enough, I realized that atan() returns double 
>>> (in this case) but wait, it's assigned to a float variable! 
>>> Compiler didn't even emit warnings, let alone errors.
>>>
>>
>> There a few lessons here.
>>
>> (1) D is not Java ;-)
>
> D is not C/C++ either. I fail to see how does it help to be C++ 
> compliant. It's absolutely trivial to tell the compiler that 
> conversion is on purpose by explicitly casting and it immensely 
> helps to reduce bugs (since we are humans after all).

It is pretty close, I converted a C++ project by copying and 
pasting most of the code.

A bigger issue is how CTFE uses "real" for everything, even at 
times you specify it not to use it. If you use an enum and 
specify "double" or "float", it might very well store it as a 
"real" in memory. That's the more troubling implicit conversion 
happening with D that has no real benefit or purpose, other than 
someone thought it was a good idea cause real's have more 
precision so they should be the default.




More information about the Digitalmars-d mailing list