source: project/release/3/srfi-19/trunk/srfi-19-common.scm @ 12020

Last change on this file since 12020 was 12020, checked in by Kon Lovett, 13 years ago

Save.

File size: 1.9 KB
Line 
1;;;; srfi-19-common.scm
2
3;; -- Miscellaneous Constants.
4
5(define-constant NS/MS  1000000)
6(define-constant NS/MuS 1000)
7
8(define-constant MS/S  1000)
9(define-constant MuS/S 1000000)
10(define-constant NS/S  1000000000)
11
12(define-constant SEC/DY   86400)    ; seconds in a day
13(define-constant SEC/DY/2 43200)    ; seconds in a half day
14(define-constant SEC/HR   3600)
15(define-constant SEC/MIN  60)
16
17(define-constant iNS/S    1000000000.0)
18(define-constant iSEC/DY  86400.0)
19
20(define-constant iONE-HALF  0.5)
21
22(define-constant HR/DY 24)
23
24(define-constant DY/WK 7)
25(define-constant DY/MN 31)  ;maximum days per month
26(define-constant DY/YR 365) ;normal days per year
27
28(define-constant MN/YR 12)
29
30; Daylight saving time offset from standard offset.
31; ("spring forward" add it, "fall back" subtract it)
32(define-constant DEFAULT-DST-OFFSET 3600)
33
34;;
35
36(define-inline (->boolean obj)
37  (and obj
38       #t) )
39
40(define-inline (fxabs x)
41  (if (fx< x 0) (fxneg x) x) )
42
43(define-inline (inexact-integer? x)
44  (and (inexact? x) (integer? x)) )
45
46;; For storage savings since some aritmetic routines do not
47;; return fixnums when possible.
48
49;; ##sys#number?
50;; returns #t for fixnum or flonum
51
52;; ##sys#double->number
53;; returns a fixnum for the flonum iff x isa integer in fixnum-range
54;; otherwise the flonum
55
56; When domain is integer and range is fixnum
57; Number MUST be a fixnum or flonum
58
59(define-inline (->fixnum x)
60  (if (fixnum? x) x (##sys#double->number x))
61  #;
62  (inexact->exact x) )
63
64; When domain is integer and range is flonum-integer
65; Conversion attemped only when number is a fixnum or flonum-integer
66; Others returned
67
68(define-inline (->fixnum* x)
69  (if (##sys#integer? x) (->fixnum x) x)
70  #;
71  (if (inexact-integer? x) (->fixnum x) x) )
72
73;;
74
75(define-inline (tm:days-before-first-week date day-of-week-starting-week)
76  (fxmod
77    (fx- day-of-week-starting-week (tm:week-day 1 1 (date-year date)))
78    DY/WK) )
Note: See TracBrowser for help on using the repository browser.