Project Elvis

Nemanja Boric 4burgos at gmail.com
Sun Oct 29 19:10:11 UTC 2017


On Sunday, 29 October 2017 at 18:02:25 UTC, Jonathan M Davis 
wrote:
> On Sunday, October 29, 2017 17:35:25 Nemanja Boric via 
> Digitalmars-d wrote:
>> On Sunday, 29 October 2017 at 17:19:44 UTC, Jonathan M Davis
>>
>> wrote:
>> > On Sunday, October 29, 2017 16:44:39 Ola Fosheim Grøstad via
>> >
>> > Digitalmars-d wrote:
>> >> On Sunday, 29 October 2017 at 16:29:57 UTC, Jonathan M Davis
>> >>
>> >> wrote:
>> >> > valid using ?:, I would think that you'd want to be doing 
>> >> > the same check with stuff like if statements anyway. So, 
>> >> > it sounds to me like overloading opCast!bool would work 
>> >> > just fine.
>> >>
>> >> If you try to do:
>> >>
>> >> some_float ?: 0.0
>> >>
>> >> then it will do nothing as cast(bool)std.math.NaN(0) => true
>> >
>> > NaN is supposed to always be false.
>>
>> OT, but I had to :-)
>>
>> ```
>> void main()
>> {
>>   import std.stdio;
>>
>>   float x;
>>   x? writeln("Oh no, a NaN!") : writeln("All good.");
>> }
>> ```
>>
>> Same happens for assert(float.nan) - it doesn't fail.
>
> Sounds like a bug to me. NaN is supposed to be false whenever 
> it's used in a comparison. If it it's true when cast directly 
> to bool, then that's inconsistent.
>
> - Jonathan M Davis

We've already reported this as a bug (I actually got quite burned 
on it, trusting assert(float_value) to prevent NaN's escaping the 
function), but there were different opinions on this, so it never 
got anywhere: https://issues.dlang.org/show_bug.cgi?id=13489


More information about the Digitalmars-d mailing list