Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I would argue that

    double m_D{}; [...]

    if (m_D == 0) somethingNeedsInstantiation();
can avoid having to carry around, set and check some extra m_HasValueBeenSet booleans.

Of course, it might not be something you want to overload beginner programmers with.

 help



Yeah I'd argue that the beginner friendly version of the rule is probably "Never use exact == or != for floating point variables" and the slightly more advanced one is "Don't use it unless the value you are comparing to is the constant 0.0".

Before isnan() the Fortran test for NaN was (x .ne. x), assuming an IEEE 754 implementation.

I wish that (still) worked reliably, but it can unfortunately get one into trouble with some compilers and some optimization modes that assume that NaNs are undefined behavior.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: