On Sun, 2025-06-29 at 11:42 -0400, Richard Kimberly Heck wrote:
> 
> Most of these seem harmless, though it wouldn't be a terrible thing to 
> squash the warnings by doing an explicit cast. However:

The warnings are not due to the implicit cast conversion but to the floating
point arithmetic properties.

For example 4./3+1./3 != 5./3 (I am using the dot to make the value real).
We can see this in python (C++ is the same because they use the same standard
for gloating point arithmetic):

$ ipython
Python 3.13.5 (main, Jun 12 2025, 00:00:00) [GCC 15.1.1 20250521 (Red Hat
15.1.1-2)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.36.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 4/3+1/3-5/3
Out[1]: -2.220446049250313e-16

The warning in the compiler that Scott refers to corresponds to this kind of
operations. What happens is that if we do not operate on the values then the
comparisons do what we expect them to do.

> > /home/scott/lyxbuilds/master-master/repo/src/mathed/MathSupport.cpp:704:18:
> > warning: implicit conversion turns floating-point number into integer:
> > 'const double' to 'bool' [-Wfloat-conversion]
> >     704 |         for (int i = 0; d[i]; ) {
> >         |         ~~~             ^~~~
> 
> This looks somewhat suspicious. If this is meant to be d[i] != 0, then 
> maybe that should be explicit.

Looking into the code we can that the 0 is used as sentinel and thus the
comparison is adequate.

Yes it can be made more explicit as you suggest.

BTW if you want more floating point fun, as defined by the IEEE 754 standard,
notice the following:

In [1]: import numpy as np

In [2]: np.nan == np.nan
Out[2]: False

The `nan` (not a number) number is different from itself. This is mandated by
the standard itself. :-D

https://en.wikipedia.org/wiki/IEEE_754

-- 
José Abílio
-- 
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to