Promotion rules ... why no float?

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 6 00:20:16 PDT 2016


On Tuesday, 6 September 2016 at 07:04:24 UTC, Sai wrote:
> Consider this:
>
> import std.stdio;
> void main()
> {
> 	byte a = 6, b = 7;
> 	auto c = a + b;
> 	auto d = a / b;
> 	writefln("%s, %s", typeof(c).stringof, c);
> 	writefln("%s, %s", typeof(d).stringof, d);
> }
>
> Output :
> int, 13
> int, 0
>
> I really wish d gets promoted to a float. Besides C 
> compatibility, any reason why d got promoted only to int even 
> at the risk of serious bugs and loss of precision?
>
> I know I could have typed "auto a = 6.0" instead, but still it 
> feels like an half-baked promotion rules.

Because implicit conversion to float on every division is bad bad 
bad.


More information about the Digitalmars-d mailing list