Fix integer_division warnings in sf_zero.f AMACH constants - #13
Open
d-diaz wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the first PR with a small example as part of a broader plan to help resolve the variety of warnings produced by compiling NVEL using
gfortran. The intent is to submit a small fix, but also to confirm that this kind of documentation to indicate the proposed change doesn't break existing behavior is acceptable.Summary
Fixes two
-Winteger-divisionwarnings insf_zero.f'sAMACHsubroutine. No numerical change — warning cleanup only.The warning
sf_zero.f:948:61: Warning: Integer division truncated to constant '-62' at (1) [-Winteger-division]
sf_zero.f:965:61: Warning: Integer division truncated to constant '-510' at (1) [-Winteger-division]
Both lines compute a
PARAMETER(compile-time constant) by halving an integer exponent (IM12/2,IM15/2) and then using that truncated result inside a real-valued exponentiation. gfortran flags this because integer division silently truncates, and it can't tell from the expression alone whether the truncation was intended.In this case it is intended — the surrounding comment says as much ("Weird subterfuges below are NECESSARY ... DON'T SIMPLIFY THEM"), and it exists to split an exponent into two halves without overflowing intermediate results. The fix makes the truncation explicit instead of leaving it implicit.
The fix
Before:
After:
IM12/2 (integer/integer) and INT(REAL(IM12)/2.0) (integer→real divide, then truncate back to integer) produce the same truncated-toward-zero result for any integer IM12 — the rewrite just performs the truncation with an explicit INT/IDINT call instead of relying on gfortran's implicit truncation rule for mixed integer arithmetic. Same reasoning for DM1 with IDINT/DBLE. The expd machine-constant parameters (not runtimevalues), so this is a one-time, compile-time equivalence, not something that could vary across inputs.
Test evidence
RM1/DM1 feed directly into R1MACH(1)/D1MACH(1) (the single/double precision underflow limits). Verified bit-identical output for indices 1-5 of bor the change. No existing regression case in this codebase happens to exercise those two indices, so a new test was added in the downstream fork of this repo to check for these two indices.
How to reproduce
Confirm the two warnings above are gone:
Additional context