qmcpack
qmcpack copied to clipboard
Intel LLVM compiler warning: floating-point comparison
Describe the bug Intel LLVM compiler is more aggressive on warnings. I got the following warning in a mixed precision build.
/home/yeluo/opt/qmcpack/src/Numerics/SplineSolvers.h:37:23: warning: floating-point comparison is always true; constant cannot be represented exactly in type 'float' [-Wliteral-range]
T bc_start2 = ((yp0 < 9.9000000000000002e+29) ? (x[0] - x[1]) : (0));
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
/home/yeluo/opt/qmcpack/src/Numerics/SplineSolvers.h:38:23: warning: floating-point comparison is always true; constant cannot be represented exactly in type 'float' [-Wliteral-range]
T bc_end1 = ((ypn < 9.9000000000000002e+29) ? (x[n - 1] - x[n - 2]) : (0));
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
/home/yeluo/opt/qmcpack/src/Numerics/SplineSolvers.h:39:23: warning: floating-point comparison is always true; constant cannot be represented exactly in type 'float' [-Wliteral-range]
T bc_end2 = ((ypn < 9.9000000000000002e+29) ? (2 * x[n - 1] - 2 * x[n - 2]) : (1));
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
/home/yeluo/opt/qmcpack/src/Numerics/SplineSolvers.h:41:13: warning: floating-point comparison is always true; constant cannot be represented exactly in type 'float' [-Wliteral-range]
((yp0 < 9.9000000000000002e+29) ? (6 * yp0 + 6 * y[0] / (-x[0] + x[1]) - 6 * y[1] / (-x[0] + x[1])) : (0));
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
/home/yeluo/opt/qmcpack/src/Numerics/SplineSolvers.h:42:21: warning: floating-point comparison is always true; constant cannot be represented exactly in type 'float' [-Wliteral-range]
T rhs_end = ((ypn < 9.9000000000000002e+29)
~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
To Reproduce
cmake -DCMAKE_C_COMPILER=mpicc -DCMAKE_CXX_COMPILER=mpicxx -DENABLE_OFFLOAD=ON -DENABLE_SYCL=ON -DQMC_MIXED_PRECISION=ON ~/opt/qmcpack
On JLSE
Expected behavior No warning.
This is sort of correct as of clangs docs
<h3><a class="toc-backref" href="https://clang.llvm.org/docs/DiagnosticsReference.html#id454">-Wliteral-range</a><a class="headerlink" href="https://clang.llvm.org/docs/DiagnosticsReference.html#wliteral-range" title="Permalink to this headline"></a></h3>
<p>This diagnostic is enabled by default.</p>
<p><strong>Diagnostic text:</strong></p>
warning: floating-point comparison is always | true false | true | false | ; constant cannot be represented exactly in type B
-- | -- | -- | -- | --
true
false
[-Wliteral-range](https://clang.llvm.org/docs/DiagnosticsReference.html#id454)
This diagnostic is enabled by default.
Diagnostic text:
warning: floating-point comparison is always
true
false
; constant cannot be represented exactly in type B
warning: magnitude of floating-point constant too large for type A; maximum is B
warning: magnitude of floating-point constant too small for type A; minimum is B
I don't know about the comparison being always true, but the constant can't be represented in single precision. The closest you can get (I think) 9.90000007341205185E+29 which is pretty far from 9.9000000000000002E+29 Which actually can be represented out to that many places as a double. 9.90000007341205185E+29 can be represented by either precision.
Since the stated goal is just to cut things before yp0 > 1e30 it seems like that would be just as good.
Another option is to change the function so the constant isn't necessary, but that would be a more involved change.