So why double to float conversion is implicit ?

NX nightmarex1337 at hotmail.com
Sat Oct 21 20:17:12 UTC 2017


I was working on some sort of math library for use in graphical 
computing and I wrote something like this:

const float PiOver2 = (atan(1.0) * 4) / 2;

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.

I see no reason as to why would this be legal in this century, 
especially in D.
So can someone tell me what's the argument against this?
Why type conversions differ between integral and floating types?
Why can't I assign a long to an int but it's fine when assigning 
double to float?

I think this is a serious topic and needs clarification.


More information about the Digitalmars-d mailing list