Repository navigation
r.sunmask, d.linegraph: Compute trig products in double - #7712
Merged
Merged
Conversation
In the borrowed NREL SOLPOS code, the radian/degree conversion constants and the local sine/cosine fields were float, so products like raddeg * angle were computed in float and only then widened to double for the trig calls. Widen degrad, raddeg, and the trigdata fields to double; this also lets the constants keep their full declared precision. In d.linegraph, widen xscale and yscale to double, which they are already computed as before being stored. Fixes 37 CodeQL cpp/integer-multiplication-cast-to-long alerts. The r.sunmask shadow raster is unchanged (verified bit-identical at several sun angles on nc_spm); only the reported solar position shifts by about 1e-5 degrees. The d.linegraph rendering is bit-identical.
petrasovaa
approved these changes
Jul 14, 2026
cwhite911
enabled auto-merge (squash)
July 14, 2026 18:47
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.
Fixes the final 37 CodeQL
cpp/integer-multiplication-cast-to-longalerts, the two clusters that are float-precision rather than integer-overflow (r.sunmask: 29, d.linegraph: 8). Together with #7704, #7705, #7706, and #7708 this closes out the entire 154-alert rule.Unlike the sibling PRs, these are
float * floatproducts widened todouble, so I fixed the root cause by widening the types rather than casting per site:solpos00.c, borrowed NREL SOLPOS code):degrad/raddegand the fivestruct trigdatasine/cosine fields werefloat, soraddeg * angleandcl * cdwere computed in float and only then widened todoublefor the trig calls. Widening these todoublecomputes the products in double and lets the two conversion constants (57.295779513,0.0174532925) keep their full declared precision instead of being truncated to float.main.c):xscaleandyscaleare computed asdouble(from(double)casts) and were then stored intofloat, losing precision before every plot coordinate multiplication. Widening them todoubleclears the alerts and removes the narrowing.Output impact, verified on nc_spm:
-sreported solar position changes, by about 1e-5 degrees, reflecting the now-full-precision constants.Because this touches borrowed SOLPOS code and nominally changes a printed value, I kept it separate from the mechanical integer-cast PRs so it can be reviewed on its own.
This is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.
Written with the assistance of Claude Code.