I have read the sequence of contributions to this thread with more dismay than 
usual.   Working with leap seconds poses no particular difficulties, and in 
particular Paul Gilmartin's suggestions are otiose.  (I single him out only 
because he almost always knows what he is talking about, even when I disagree 
strongly with him.)   
 
A table is needed but IBM supplies one, which it updates well in advance of the 
effective insertion time of a new leap second, indeed almost as soon as the 
BIPM issues its notification that an insertion will occur. Currently, the table 
takes the (somewhat edited, but substantively correct) form 





year

m

dom

doy

Σls

STCKE (9 high bytes)


1900

1

1

1

0

x'000000000000000000'


1972

1

1

1

0

x'008126d60e46000000'


1972

7

1

183

1

x'00820ba9811e240000'


1973

1

1

1

2

x'0082f300eee2480000'


1974

1

1

1

3

x'0084bde971446c0000'


1975

1

1

1

4

x'008688d23346900000'


1976

1

1

1

5

x'008853baf578b40000'


1977

1

1

1

6

x'008a1fe59520d80000'


1978

1

1

1

7

x'008beace5752fc0000'


1979

1

1

1

8

x'008db5b71985200000'


1980

1

1

1

9

x'008f809fdbb7440000'


1981

7

1

182

10

x'0092305c0fcd680000'


1982

7

1

182

11

x'0093fb44d1ff8c0000'


1983

7

1

182

12

x'0095c62f9431b00000'


1985

7

1

182

13

x'00995d40f517d00000'


1988

1

1

1

14

x'009dda69a557f80000'


1990

1

1

1

15

x'00a1117d063e1c0000'


1991

1

1

1

16

x'00a33c65c780400000'


1992

7

1

182

17

x'00a3ec21fc86640000'


1993

7

1

182

18

x'00a7b70abeb8880000'


1994

7

1

182

19

x'00a981f380eaac0000'


1996

1

1

1

20

x'00ac34336fecd00000'


1997

7

1

182

21

x'00aee3efa40df40000'


1999

1

1

1

22

x'00b1962f9305180000'


2005

1

1

1

23

 x'00BE251097973C0000'
 
Suppose now that we have a copy of this table, call it T, and a (truncated) 
STCKE value, call it S, for which we need the corresponding cumulative 
leap-seconds-inserted value.  Traditional match-seeking binary search in this 
table is unavailable to us because we need not a match for but a greatest lower 
bound (glb), which may occasionally also be a match, on S. A binary-search 
scheme that I devised long ago for evaluating tabular step functions can, 
however, be used for this purpose. A PL/I version of it, specialized for this 
use, is leapsecs: procedure(Tp, S, cumLS)  /* cumulative LSs for STCKE */  
returns(aligned bit)  reorder ;    /* returns '1'b with cumLS set if S is 
bounded in T; returns '0'b,     false, if S is not bounded in T. */      /* 
parameters */    declare (Tp pointer,  /* table pointer */    S aligned 
bit(72))  /* search argument, truncated STCKE */    parameter nonassignable,    
cumLS signed binary fixed(31,0) /* cumulative leap seconds */    parameter 
assignable ;        /* table to search */    declare 1 T based(Tp), /* table */ 
   2 tls  /* low table subscript */      signed binary fixed(31,0),    2 ths  
/* high table subscript */      signed binary fixed(31,0),    2 tab 
dimension(ls refer(T.tls); hs refer(T.ths),      3 year signed binary 
fixed(31,0),  /* Gregorian year */      3 moy  signed binary fixed(7,0),  /* 
month of year */      3 dom  signed binary fixed(7,0),  /* day of month */      
3 doy  signed binary fixed(15,0),  /* day of year */      3 cls  signed binary 
fixed(31,0),  /* cumulative LSs */      3 STCKE9 aligned bit(72),   /* STCKE 
value */      3 * character(3) ;   /* DW alignment */          /* named 
constants */    declare (F1 value (1b), F2 value(10b))    signed binary 
fixed(31,0) ;      /* LIFO scratch storage */    declare (h,   /* high search 
subscript */    l,    /* low search subscript */    m,   /* middling search 
subscript */    hmin,  /* minimal bounding subscript */    (ls, hs))  /* unused 
dynamic-allocation values */    signed binary fixed(31,0),    (bounded,   /* is 
S bounded in T? */    search,   /* table not yet exhausted? */    
search_higher)  /* search following T.STCKE9(m)? */    aligned bit ;      l, 
hmin = T.tls ;    h = T.ths ;    do search = (l <= h) while(search) ;      m = 
l + (h - l)/F2 ;  /* fixedoverflow! */      search_higher = (S >= T.STCKE9(m)) 
;      if search_higher then l = m + F1 ;      else h = m - F1 ;    end ;    
bounded = (h >= hmin) ;    if bounded then cumLS = T.cls(h) ;        
return(bounded) ;       end leapsecs ; Here no STCKE value can be without a glb 
in T, but I have left the code that deals with search arguments smaller than 
the smallest table value in place to illustrate how the algorithm works for 
such values.  In general, of course, the smallest element in a table like T may 
be greater than some search argument value S; and in this case S has no glb in 
T and this procedure returns '0'b, false.    The elements of a table T may 
comprise either an ordered set of unique elements or a partially ordered 
multiset that in general contains duplicate elements; and one of the merits of 
this scheme is that it yields unequivocal results for such multisets. John 
Gilmore 
Ashland, MA 01721-1817
USA
_________________________________________________________________
See how Windows connects the people, information, and fun that are part of your 
life.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to