Hacker News new | ask | show | jobs
by PopePompus 1570 days ago
I love NaNs, especially their "infectious" quality. Initializing float variable to NaNs before first assignment can make a lot of errors immediately obvious. I wish there were a NaN for integers.
2 comments

What about a “nullable” double? In C#, you’d use `double?`, Rust would be Option<f64>, C++ would be std::optional<double>. Then any operation would throw upon an unset value?
That would required every operation on a floating point value to return an optional, which you’d then need to unwrap and branch on.
Don’t initialize them and turn on UBSan :)