Fix CPR NL() off-by-one at the 87 deg polar boundary#65
Merged
Conversation
The topmost transition latitude (87°) is the only NL boundary that lands exactly on an L0 lattice point. Arrays.binarySearch matched it inclusively, so NL() returned 2 at exactly |lat| == 87°, whereas DO-260B and the NASA cpr reference require NL == 1 for |lat| >= 87° (polar cap). Make the top boundary exclusive for the NL=2 zone. Validated by an exhaustive lattice check (406 points across all 58 NL boundaries) confirming this was the only divergence from NASA, and a 1M random airborne+surface position cross-check against the NASA fixed-point reference. Adds L0LatitudeTest covering the boundary; full suite 164 tests pass. Co-Authored-By: Claude Opus 4.8 <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.
Fixes an off-by-one in
L0Latitude.NL()at exactly |lat| = 87.0 deg.Problem
The topmost transition latitude
T_LAT[57]rounds to exactly 87.0 deg andbinarySearchmatched it inclusively, soNL()returned 2 at |lat| = 87.0 deg, where the DO-260B standard (and the NASA/cpr formally-verified reference) require NL = 1 (polar cap). This changes longitude decoding for positions landing exactly on the 87 deg lattice point.Fix
Treat the top transition latitude as exclusive for the NL=2 zone:
Only the topmost boundary changes (it is the only NL transition latitude landing exactly on an exact integer-lattice point); the other 57 already matched NASA at every lattice point.
Validation
cpr/L0LatitudeTest.java: NL==1 at +/-87/88.5/90 deg, NL==2 just below 87 deg, NL==59 at the equator.Commit: 08b5ec6