On Tue, 12 Nov 2024 18:12:50 +0100
David Brown via Gcc <gcc@gcc.gnu.org> wrote:

> Under what circumstances would you have code that :
...
> d) Would be perfectly happy with "x" having the value 2.225e-307 (or 
> perhaps a little larger) and doing the division with that.
> 
> I think what you really want to check is if "x" is a reasonable value
> - checking only for exactly 0.0 is usually a lazy and useless attempt
> at such checks.  

In quantitative research, "x" may be initialized from a database.
Yesterday that database might have been fine, and today there's a row
with a zero in it.  If it's a problem, it's better to report the
problem as "x is 0 for foo" than as a divide-by-zero error later on.  

In fact, division might not be the issue.  A coefficient of zero might
indicate, say, an error upstream in the model parameter output.  

It's also not unusual to start with "x" statically initialized to zero,
and use that as an indication to invoke the initialization routine.  

When we have floating point numbers initialized from small integer
constants, comparison with == is both valid and safe.  Whether 0 itself
is the concern, or near-zeroes like 2.225e-307, is depends on context,
something the programmer knows and the compiler does not.  

--jkl

Reply via email to