Always false float comparisons

Ecstatic Coder via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 29 22:38:51 PDT 2017


On Thursday, 29 June 2017 at 19:12:24 UTC, ag0aep6g wrote:
> On Thursday, 29 June 2017 at 18:03:39 UTC, Ecstatic Coder wrote:
>> I often do code like "x < array.length" where x needs to be a 
>> long to be able to handle negative values.
>>
>> I want my code to compile without warning, and therefore I'm 
>> against requiring "x < array.length.to!long()" to remove that 
>> warning.
>
> `x < array.length` and `x < array.length.to!long` have 
> different results when x is negative. That's why a 
> warning/error is in order.

I can perfectly understand that others may want to check their 
code in a "strict" mode.

So actually I'm not against a warning for signed/unsigned 
implicit conversions.

I'm just against putting it on by default, so that the current 
behavior is kept, because I don't see where is the language 
improvement in having to put these ugly manual conversion 
everywhere just because the string/array length was made unsigned.

I always use signed integers for string/array indices because 
unsigned indices become dangerous as soon as your algorithm 
starts to decrement it...

And as I said, I compile my D code with the 64-bit compiler, and 
2^63 characters/items is much more than needed for my personal 
use cases.

So until the day I will have a computer which can store a string 
of 16 million terabytes, at the moment I prefer to use long 
values for indices, instead of ulong, because negative indices 
can already occur right now with my current algorithms.


More information about the Digitalmars-d mailing list