Open inobelar opened 1 year ago
Seems like a good idea to add a comment. I'll turn this into a proper comment when I get chance, but the short answer to why only positive infinity is that it's being used as a value for the "growth limit" for track (row/column) sizes. These start at zero, and the algorithm progressively increases their size up to (and sometimes beyond) their growth limit (there are also some special cases where infinite limits are handled differently, such as a step when any tracks with finite growth limits are increased up to their limit). A negative infinity limit wouldn't make any sense (we'd be better off using 0), and as you note, the limit only becomes infinite by being explicitly set to f32::INFINITY
.
The use of f32::INFINITY
also directly corresponds to the use of "infinite growth limit" or "growth limit of infinity" in the spec.
During reading sources in https://github.com/DioxusLabs/taffy/blob/main/src/compute/grid/track_sizing.rs I found a lot of direct checks for
f32::INFINITY
.This is the place where this comparison is used most often . We can easily check it:
I found this "unusual", as it is generally considered a "safe" check for
inf
viaf32::is_infinite()
orisinf()
in C++ or C. This pattern is similar to: "usingis_nan()
better then direct comparation with NaN" - that's why it caught my attention here.After more detailed consideration of what is happening in the code, I came to the conclusion that a current direct comparison with
f32::INFINTIY
is still a better option (overf32::is_infinite()
) - it does not take into account negative infinity, because in such places checks are performed for a special "marker" or "flag", which is only positive infinity, so these are checks NOT forinf
produced by division-by-zero somewhere.@nicoburns I can not comprehend what is happening in that file - as the owner of sacred knowledge, can you add a descriptive comment (for example: at the beginning of the file, somewhere after
mod
imports, before functions declaration)? - With description like:so after reading it no one tries to "fix it", and it does not attract attention :)