Skip to content

feat: exact rational DMS parsing and Degrees canonicalization#321

Open
yelliver wants to merge 1 commit into
cortex-js:mainfrom
yelliver:feat/exact-rational-dms
Open

feat: exact rational DMS parsing and Degrees canonicalization#321
yelliver wants to merge 1 commit into
cortex-js:mainfrom
yelliver:feat/exact-rational-dms

Conversation

@yelliver

Copy link
Copy Markdown

Summary

  • parseDMS: numeric DMS no longer collapses to floating-point degrees; it returns a reduced exact rational (3600·d + 60·m + s) / 3600 wrapped in Degrees.
  • Degrees canonical: exact conversion to radians now applies to any rational degree (e.g. 19/2°), not only integers.
  • DMS() canonical: builds degrees via ce.number([totalSec, 3600]) instead of a float sum, preserving exactness through the boxing pipeline.
  • Tests: updated raw-parse expectations to use reduced rationals; evaluation tests assert exact LaTeX via simplify().latex instead of floating-point approximations.

Motivation

DMS angles are naturally exact rationals of a degree: 9°30' is 19/2°, not 9.5 as a float. The old pipeline aggregated components with floating-point arithmetic at parse time (deg + min/60 + sec/3600), which introduced rounding error before canonicalization.

That mattered downstream: Degrees only had an exact rational→radian path for integer degrees. A parsed angle like 5°37'30" became a float, missed the exact branch, and expressions such as converting to radians and simplifying could not reduce to clean fractions (e.g. π/32).

This change keeps DMS exact end-to-end - parse as reduced rationals, box DMS() the same way, and extend Degrees canonicalization to all rational arguments - so degree-to-radian conversion stays symbolically correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant