Re: 12c date range Message #33 Posted by Thomas Klemm on 17 Nov 2010, 12:01 a.m., in response to message #11 by Don Shepherd
Quote:
Does anyone have access to it?
If you build nonpareil with the option has_debugger_gui=1 you will get an additional tab labeled "Debug". One of the choices in the menu is "Trace". If enabled you get 3 lines for each executed machine instruction:
03462: 0456 a=a+b w
cycle 17711 P=7 q=8 carry=0 stat=...3..........
a=01200000000000 b=01200000000000 c=03060009999999
I haven't analyzed the whole program yet but this algorithm is used:
if m <= 2:
m = m + 12
y = y - 1
jd = int(365.25*y)
- int(y/100)
+ int(y/400)
+ int(30.6001*(m+1))
+ d
- 478164
This maps 15-10-1582 to 100000 and 25-11-4046 to 999999.
For both limits I compared the trace-output with that of the date just one day beyond the limit to find the point where they diverge:
14-10-1582 15-10-1582
1582 * 365.25 = 577825.5 577825 1582 * 365.25 = 577825.5 577825
1582 -> 15 - 15 1582 -> 15 - 15
577810 577810
15.82 / 4 = 3.955 + 3 15.82 / 4 = 3.955 + 3
577813 577813
11 * 30.6001 = 336.6011 + 336 11 * 30.6001 = 336.6011 + 336
578149 578149
14 + 14 15 + 15
578163 578164
- 478164 - 478164
99999 100000
cycle 4161 P=c q=8 carry=0 stat=...3.......... cycle 4968 P=c q=8 carry=0 stat=...3..........
a=00999990000000 b=05781630000000 c=05781630000005 a=01000000000000 b=05781640000000 c=05781640000005
03363: 1502 ? a<>0 p 03363: 1502 ? a<>0 p
cycle 4162 P=c q=8 carry=0 stat=...3.......... cycle 4969 P=c q=8 carry=1 stat=...3..........
Here P=c which means it points to nibble 12 (i.e. the 2nd from left).
Still I don't understand why the lower limit 100000 was chosen. Using 0 instead leads to negative numbers for dates earlier than 15-10-1582. This sets the carry-bit and is easy to detect.
25-11-4046 26-11-4046
4046 * 365.25 = 14778015.5 1477801 4046 * 365.25 = 14778015.5 1477801
4046 -> 40 - 40 4046 -> 40 - 40
1477761 1477761
40.46 / 4 = 10.115 + 10 40.46 / 4 = 10.115 + 10
1477771 1477771
12 * 30.6001 = 367.2012 + 367 12 * 30.6001 = 367.2012 + 367
1478138 1478138
25 + 25 26 + 26
1478163 1478164
- 478164 - 478164
999999 1000000
cycle 18292 P=c q=8 carry=0 stat=...3.......... cycle 4145 P=c q=8 carry=0 stat=...3..........
a=01478163000005 b=14781630000000 c=09999990000000 a=01478164000005 b=14781640000000 c=10000000000000
03325: 1376 ? c<>0 s 03325: 1376 ? c<>0 s
cycle 18293 P=c q=8 carry=0 stat=...3.......... cycle 4146 P=c q=8 carry=1 stat=...3..........
Here the sign of register c is checked and thus a date outside the range will be detected.
Quote:
The second date is determined by internal register limitations
There's enough space. All the numbers could be shifted one place to the right. I don't see the limitation.
Cheers
Thomas
|