Skip to content

Commit 619ee7c

Browse files
committed
Use x /= x test for NaN detection (ieee_is_nan failing)
CI evidence shows ieee_is_nan() is NOT detecting NaN values: - No diagnostic messages appeared in output - NaN still present at node 1303 - This indicates compiler optimization breaking ieee_is_nan Root cause: Compiler flag -ffast-math or similar breaks IEEE 754 compliance, making ieee_is_nan() unreliable. Solution: Use mathematical property of NaN - NaN is the ONLY value where (x /= x) returns TRUE - This works even with aggressive compiler optimizations - Combined with ieee_is_nan as belt-and-suspenders approach Detection now uses: if (ieee_is_nan(x) .or. x /= x) then x = 0.0 end if This should catch NaN regardless of compiler flags.
1 parent e2635e4 commit 619ee7c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/gen_ic3d.F90

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,12 @@ SUBROUTINE do_ic3d(tracers, partit, mesh)
554554
nan_count_local = 0
555555
do n=1, partit%myDim_nod2d + partit%eDim_nod2D
556556
do i=1, mesh%nl-1
557-
if (ieee_is_nan(tracers%data(current_tracer)%values(i,n))) then
557+
! Use multiple NaN detection methods for robustness
558+
! Method 1: ieee_is_nan (may fail with some compilers/flags)
559+
! Method 2: x /= x (NaN is only value not equal to itself)
560+
! Method 3: Check against itself in comparison
561+
if (ieee_is_nan(tracers%data(current_tracer)%values(i,n)) .or. &
562+
tracers%data(current_tracer)%values(i,n) /= tracers%data(current_tracer)%values(i,n)) then
558563
tracers%data(current_tracer)%values(i,n) = 0.0_WP
559564
nan_count_local = nan_count_local + 1
560565
end if

0 commit comments

Comments
 (0)