Skip to content

Commit 767b1cb

Browse files
Fix #1057: be more cautious as rising converges
1 parent 55ad886 commit 767b1cb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

skyfield/almanac.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,13 @@ def normalize_plus_or_minus_pi(radians):
443443
ha_adjustment = desired_ha - ha.radians
444444
ha_adjustment = (ha_adjustment + pi) % tau - pi
445445

446-
# Figure out how fast the target's HA is changing.
447-
ha_diff = normalize(ha.radians - old_ha_radians)
448-
t_diff = t - old_t
449-
ha_per_day = ha_diff / t_diff
446+
# Figure out how fast the target's HA is changing. After two
447+
# iterations, just keep using the same value, in case t_diff
448+
# gets so small that ha_diff drops to zero.
449+
if i < 2:
450+
ha_diff = normalize(ha.radians - old_ha_radians)
451+
t_diff = t - old_t
452+
ha_per_day = ha_diff / t_diff
450453

451454
# Remember this iteration's HA and `t` for the next iteration.
452455
old_ha_radians = ha.radians

0 commit comments

Comments
 (0)