Always false float comparisons

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu May 12 00:32:41 PDT 2016


On 5/11/2016 2:24 AM, Manu via Digitalmars-d wrote:
>> Floating point behavior is so commonplace, I am wary of inventing new,
>> unusual semantics for it.
>
> Is it unusual to demote to the lower common precision?

Yes.


> I think it's the only reasonable solution.

It may be, but it is unusual and therefore surprising behavior.


> What is the problem with this behaviour I suggest?

Code will do one thing in C, and the same code will do something unexpectedly 
different in D.


> The reason I'm wary about emitting a warning is because people will
> encounter the warning *all the time*, and for a user who doesn't have
> comprehensive understanding of floating point (and probably many that
> do), the natural/intuitive thing to do would be to place an explicit
> cast of the lower precision value to the higher precision type, which
> is __exactly the wrong thing to do__.
> I don't think the warning improves the problem, it likely just causes
> people to emit the same incorrect code explicitly.

The warning is intended for people who understand, as then they will figure out 
what they actually wanted and implement that. People who randomly and without 
comprehension insert casts hoping to make the compiler shut up cannot be helped.



More information about the Digitalmars-d mailing list