Support type generic precision#94
Open
langestefan wants to merge 6 commits into
Open
Conversation
Make solar_position compute at the precision of the input Observer{T}, for all
five algorithms (PSA, NOAA, Walraven, USNO, SPA), from Float16 up to BigFloat.
Keystone is a type-generic time base (src/Positioning/timebase.jl): instead of
the always-Float64 datetime2julian, derive the small Julian-century / day-count
quantities at precision T. PSA/NOAA/Walraven use an integer-split form that is
both Float64-exact and magnitude-safe for low precision; USNO/SPA use a T-typed
julian_date that reproduces the original Float64 arithmetic bit-for-bit (so the
existing 1e-8 reference pins are preserved unchanged).
Also: generic calculate_deltat(::Type{T}, ...), generic default refraction
constructors (HUGHES{T}/BENNETT{T}/SG2{T}) fixing NOAA default refraction for
non-Float64, and per-element T() accumulation in the SPA periodic sums so the
Float64 coefficient tables no longer pin the result to Float64.
Adds test-typestability.jl (@inferred across types x algorithms) and
test-precision.jl (BigFloat convergence, Float64 vs BigFloat, Float32 usable).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Switch SPA (_compute_spa_srt_parameters) and USNO from the T-typed full Julian date to the integer-split julian_day_j2000 / fractional_hour time base, so they keep full intra-day resolution at low precision. Float32 SPA goes from ~10 deg error (Julian-date magnitude under-resolved) to ~0.2 deg; USNO and the other algorithms reach ~1e-2 deg. Remove the now-unused julian_date helper. This makes our Float64 output more accurate than the external solposx Float64 references for USNO/SPA (which carry a ~1e-7 Julian-date intra-day artifact in the sidereal terms), so relax those two reference comparisons to atol 1e-6 in test-usno.jl, test-spa.jl and test-mtk.jl (PSA/NOAA/Walraven stay at 1e-8). The solposx reference values themselves are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mean_sidereal_time multiplied the day-count by 360.98564736629, reaching ~3.5e6 and costing Float32 ~0.2 deg. Pass the day-count split into exact integer days and a full-precision [0,1) fraction (julian_day_j2000_split): the 360*n_int whole rotations vanish mod 360, so only the 0.98564736629 deg/day drift is kept at magnitude. Float32 SPA improves from ~0.2 deg to ~0.01 deg (worst case over 174 yr); Float64 is unchanged within the solposx 1e-6 tolerance, BigFloat still converges, and throughput is unaffected (~1.45x faster than Float64, 2x less memory). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
Benchmark Results (Julia vpre)Time benchmarks
Memory benchmarks
|
Benchmark Results (Julia vlts)Time benchmarks
Memory benchmarks
|
Direction cosines fed to asin/acos can round just past ±1 in Float16/Float32, throwing a DomainError (e.g. NOAA and Walraven threw on a full-year Float32 sweep). Clamp those arguments to [-1, 1] via a small unit_clamp helper at the 13 asin/acos sites across the five algorithms. The clamp only activates outside the valid range, which Float64 never reaches for the reference conditions, so Float64 output (and the solposx references) are unchanged. All algorithms now run crash-free at Float32. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The time-base helpers are internal (not exported), but their docstrings tripped Documenter's strict missing_docs check (they are not in the manual). Convert them to plain `#` comments, matching the convention for other internal helpers (sum_periodic_terms, mean_sidereal_time, ...). Fixes the docs CI build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #94 +/- ##
===========================================
- Coverage 100.00% 99.85% -0.15%
===========================================
Files 17 18 +1
Lines 666 683 +17
===========================================
+ Hits 666 682 +16
- Misses 0 1 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Cover the new public-API surface that algorithms don't exercise internally: the
calculate_deltat(::Type{T}, …) methods for the (year, month) and ZonedDateTime
signatures, and the HUGHES{T}()/BENNETT{T}()/SG2{T}() parametric default
constructors. Restores patch coverage.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
No description provided.