Real implicitly converts to float?

Ola Fosheim Grøstad via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 24 01:52:48 PDT 2016


On Thursday, 23 June 2016 at 15:25:49 UTC, Steven Schveighoffer 
wrote:
> On 6/23/16 11:16 AM, Tofu Ninja wrote:
>> On Thursday, 23 June 2016 at 13:57:57 UTC, Steven 
>> Schveighoffer wrote:
>>> Whenever you work with floating point, the loss of precision 
>>> must be
>>> expected -- a finite type cannot represent an infinite 
>>> precision number.
>>
>> The loss in precision should still be a warning. If I am using 
>> reals
>> then I obviously needed a certain level of precision, I don't 
>> want to
>> accidentally lose that precision somewhere because the 
>> compiler decided
>> it was not important enough to warn me about it.
>
> I disagree. I've used languages where converting floating point 
> types is not implicit, and it's painful. Most of the time, the 
> loss in precision isn't important.

This is so wrong. _especially_ when you have parameter 
overloading/templates. It means that you accidentally can trash a 
computation by getting the wrong function. That is not type-safe 
in my book.

Jonathan's max-value example is a good one. The distinction 
between infinity and a large actual value is an important one.



More information about the Digitalmars-d-learn mailing list