Skip to content

Comments

Change glevel 1 and 2 to ints to prevent floating point equality checks#275

Open
islas wants to merge 1 commit intowrf-model:developfrom
islas:fix_fpequality_check
Open

Change glevel 1 and 2 to ints to prevent floating point equality checks#275
islas wants to merge 1 commit intowrf-model:developfrom
islas:fix_fpequality_check

Conversation

@islas
Copy link
Contributor

@islas islas commented Jun 12, 2025

All comparisons to glevel1 and glevel2 are against integer values, relying on implicit conversion during the check if done somewhat correctly. When implicit conversion is not done, the floating point to integer .eq. check can easily fail for values that should normally succeed.

Whilst the calculations to generate glevel1 and glevel2 use floating point math, assigning into an integer variable guarantees a float to int conversion is done before the comparison, thus preventing instances where instead of float to int compilers may other arithmetic operations for comparison such as int to float.

All comparisons to glevel1 and glevel2 are against
integer values, relying on implicit conversion
during the check if done somewhat correctly. When
implicit conversion is not done, the floating point
to integer .eq. check can easily fail for values
that should normally succeed.

Whilst the calculations to generate glevel1 and
glevel2 use floating point math, assigning into an
integer variable guarantees a float to int
conversion is done before the comparison, thus
preventing instances where instead of float to int
compilers may other arithmetic operations for
comparison such as int to float.
@islas
Copy link
Contributor Author

islas commented Jun 12, 2025

More details can be found in this thread:
https://forum.mmm.ucar.edu/threads/subsoil-level-not-found-in-ungrib-file.21884/post-53661

@HathewayWill
Copy link

@islas will this be updated?

@HathewayWill
Copy link

@islas

@islas islas requested a review from mgduda January 5, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants