- From: L. David Baron via GitHub <sysbot+gh@w3.org>
- Date: Tue, 29 Mar 2022 00:54:08 +0000
- To: public-css-archive@w3.org
As someone who's spent a bit of time over the past year debugging assertion failures (`DCHECK` failure) that involved `NaN` values being introduced into code that didn't expect them (very little code does, really), I'd like add one note about `NaN` values: The typical sources of `NaN` values are more diverse than portrayed above. Sources that I've seen include (with variations in sign): * `0.0 / 0.0` * `0.0 * Infinity` * `sin(Infinity)`, `cos(Infinity)`, `tan(Infinity)`, etc. * `Infinity - Infinity` (which can come from `Infinity - floor(Infinity)`) This, of course, assumes IEEE 754 (a.k.a. IEC 559) floating point behavior. Note that this is *not* guaranteed by C++, though I think many browser implementations written in C++ assume it. In C++ it can be tested with `std::numeric_limits<float>::is_iec559`, `std::numeric_limits<double>::is_iec559`, etc. Most of these things are formally undefined behavior in C++, as I understand things. ----- As far as the proposed solutions go, I'd note that I weakly dislike introducing Infinity values where not necessary, since Infinity values (see a few paragraphs up) have a strong tendency to produce NaN values further down the line, which tend to lead to more bugs than the Infinity values alone do. Once you have `NaN` values, they tend to break a lot of developer assumptions (e.g., again assuming IEEE 754 / IEC 559), such as breaking the assumption that one of a < b, a == b, and a > b is true. On the other hand, implementation *should* be avoiding bugs in these cases since there are other ways to produce Infinity values -- it's just sending more cases down codepaths that are likely to be buggy. (For example, with transform matrices, the easiest way to get `NaN`s is to multiply a bunch of very large numbers until you exceed the range of the relevant floating point type and get an `Infinity`, and then multiply that by a `0`. (Most components of the transform matrix are usually zero, so once you have infinities in transform matrices you very quickly get `NaN`s, and then you're often just a few multiplies away from a matrix that's just all `NaN`s.) -- GitHub Notification of comment by dbaron Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7067#issuecomment-1081291228 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Tuesday, 29 March 2022 00:54:10 UTC