On Wednesday, June 22, 2016 05:04:42 Tofu Ninja via Digitalmars-d-learn wrote: > Is this intended behavior? I can't seem to find it documented > anywhere, I would think the loss in precision would atleast be a > warning. > > real x = 10; > float y = x; // No error or warning > > real to double and double to float also work.
Well, that particular value should probably work thanks to VRP (value range propagation), since 10 can fit into float with no loss of precision. However, what's far more disconcerting is that real x = real.max; float y = x; compiles. real to float is a narrowing conversion, which should be an error barring the compiler detecting that the value will fit in the target type even if it's a narrowing conversion (which only happens with VRP). That's not the sort of thing that I would have expected to be broken such that it begs the question as to whether it's intentional, but given that narrowing conversions without a cast are illegal everywhere else, this definitely seems broken. - Jonathan M Davis