Subject: Re: bug#61460: 30.0.50; Calendar shows eclipse for quarter moon

From: Ulrich Müller <[email-masked]>
Date: Tue, 14 Feb 2023 11:22:56 +0100

Next round: The following simplifies the calculation and IMHO makes it
much easier to understand. Results are identical, and tests pass.

Alternatively, we could leave the result in degrees (as all other
calculations in lunar.el are in degrees) and change the values in the
final cond to 13.9 and 21.2 degrees. This would also get rid of the
excessive number of digits.

>From 32609db770004aa787c05753a1f90fe906c07c60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ulrich=20M=C3=BCller?= <[email-masked]>
Date: Tue, 14 Feb 2023 11:12:29 +0100
Subject: [PATCH] ; Simplify eclipse calculation in calendar/lunar.el

* lisp/calendar/lunar.el (eclipse-check): Calculate moon-lat in
degrees, then convert to radians.
---
 lisp/calendar/lunar.el | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/lisp/calendar/lunar.el b/lisp/calendar/lunar.el
index 8ced4144105..ec31ea596ea 100644
--- a/lisp/calendar/lunar.el
+++ b/lisp/calendar/lunar.el
@@ -155,14 +155,11 @@ remainder mod 4 gives the phase: 0 new moon, 1 first quarter, 2 full moon,
 ;; from "Astronomy with your Personal Computer", Subroutine Eclipse
 ;; Line 7000 Peter Duffett-Smith Cambridge University Press 1990
 (defun eclipse-check (moon-lat phase)
-  (let* ((moon-lat (* (/ float-pi 180) moon-lat))
-         ;; For positions near the ascending or descending node,
-         ;; calculate the absolute angular distance from that node.
-         (moon-lat (abs (- moon-lat (* (floor (/ moon-lat float-pi))
-                                       float-pi))))
-         (moon-lat (if (> moon-lat 0.37) ; FIXME (* 0.5 float-pi)
-                       (- float-pi moon-lat)
-                     moon-lat))
+  (let* ((moon-lat (mod moon-lat 180))
+         ;; Calculate the absolute angular distance from the ascending
+         ;; or descending node, whichever is nearer.
+         (moon-lat (min moon-lat (- 180 moon-lat)))
+         (moon-lat (degrees-to-radians moon-lat))
          (phase-name (cond ((= phase 0) "Solar")
                            ((= phase 2) "Lunar")
                            (t ""))))
-- 
2.39.1