Skip to content

Commit 5b0a606

Browse files
committed
fix: widen uniform-grid tolerance to sqrt(epsilon(h0)) for single-precision
The previous 1e-10 threshold was below machine epsilon for real(4) (~1.2e-7), causing uniform_grid to always be .false. in --single builds since FP-computed spacings deviate at ~1e-7 level. Using sqrt(epsilon(h0))*abs(h0) is precision-agnostic: ~1.5e-8 relative in double, ~3.5e-4 in single -- above FP noise in both modes.
1 parent daf8d8f commit 5b0a606

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/simulation/m_weno.fpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,13 @@ contains
847847
end if
848848
#:endfor
849849

850-
! Detect whether grid spacing is uniform (enables cancellation-free sum-of-squares beta)
850+
! Detect whether grid spacing is uniform (enables cancellation-free sum-of-squares beta). Tolerance uses sqrt(epsilon) so it
851+
! works in both double and single precision: ~1.5e-8 relative in double, ~3.5e-4 in single - above FP noise, below real
852+
! stretching.
851853
uniform_grid(weno_dir) = .true.
852854
h0 = (s_cb(s) - s_cb(0))/real(s, wp)
853855
do i = 0, s - 1
854-
if (abs((s_cb(i + 1) - s_cb(i)) - h0) > 1.0e-10_wp*abs(h0)) then
856+
if (abs((s_cb(i + 1) - s_cb(i)) - h0) > sqrt(epsilon(h0))*abs(h0)) then
855857
uniform_grid(weno_dir) = .false.
856858
exit
857859
end if

0 commit comments

Comments
 (0)