On Thursday, 26 May 2016 at 15:48:18 UTC, Basile B. wrote:
On Thursday, 26 May 2016 at 15:34:50 UTC, ArturG wrote:
On Thursday, 26 May 2016 at 15:29:52 UTC, Basile B. wrote:


float.init is not equal to 0.0f. In D FP points values are initialized to nan (not a number).

By the way for strings it works, it's like the array case I described in the first answer).

yes i guess i tested all/most types and know that float.init is float.nan but why is nan true and not false?

Oh, I'm so sorry ! I totally missed the point of the Q.

float.nan is not a "unique" value. Several values verify "nan" (Look at std.math.isNan). So I suppose it's simpler to test for nullity. Though with the sign there's also two possible 0...

void main(string[] args)
{
    writeln(float.nan == float.init); // false
    import std.math: isNaN;
    writeln(isNaN(float.nan));  // true
    writeln(isNaN(float.init)); //true
}

So the shortcut in the compiler might be more simple, there is only a single test for "if(myFloat)"...
  • Why do some T.init evaluate t... ArturG via Digitalmars-d-learn
    • Re: Why do some T.init e... Basile B. via Digitalmars-d-learn
      • Re: Why do some T.in... Basile B. via Digitalmars-d-learn
        • Re: Why do some ... Basile B. via Digitalmars-d-learn
          • Re: Why do s... arturg via Digitalmars-d-learn
            • Re: Why... Basile B. via Digitalmars-d-learn
              • Re:... ArturG via Digitalmars-d-learn
                • ... Basile B. via Digitalmars-d-learn
                • ... ArturG via Digitalmars-d-learn
                • ... Basile B. via Digitalmars-d-learn
                • ... Basile B. via Digitalmars-d-learn
                • ... ArturG via Digitalmars-d-learn
                • ... Marc Schütz via Digitalmars-d-learn
                • ... ArturG via Digitalmars-d-learn
                • ... Adam D. Ruppe via Digitalmars-d-learn
                • ... ArturG via Digitalmars-d-learn
                • ... Adam D. Ruppe via Digitalmars-d-learn
                • ... ArturG via Digitalmars-d-learn
                • ... Adam D. Ruppe via Digitalmars-d-learn
                • ... ArturG via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn

Reply via email to