Always false float comparisons

Manu via Digitalmars-d digitalmars-d at puremagic.com
Thu May 12 03:30:28 PDT 2016


On 12 May 2016 at 17:32, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 5/11/2016 2:24 AM, Manu via Digitalmars-d wrote:
>
>> 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.

But they can easily be helped by implementing behaviour that makes sense.
If you're set on a warning, at least make the warning recommend
down-casting the higher precision term to the lower precision?


More information about the Digitalmars-d mailing list