source: project/release/4/number-limits/tags/2.0.0/int-limits.scm @ 13699

Last change on this file since 13699 was 13699, checked in by Kon Lovett, 11 years ago

*define fix.

File size: 2.9 KB
Line 
1;;;; int-limits.scm
2;;;; Kon Lovett, Mar '09
3
4;;; Prelude
5
6(declare
7        (usual-integrations)
8  (inline)
9  (local)
10        (number-type fixnum) )
11
12#>
13#if defined(HAVE_LONG_LONG) && HAVE_LONG_LONG
14# define LONG_LONG_SIZE           sizeof( long long )
15# define UNSIGNED_LONG_LONG_SIZE  sizeof( unsigned long long )
16#else
17# define LONG_LONG_SIZE           -1
18# define UNSIGNED_LONG_LONG_SIZE  -1
19#endif
20
21#define MOST_POSITIVE_INT32 ((int32_t) 0x7fffffffL)
22#if 0
23#define MOST_POSITIVE_INT64 ((int64_t) 0x7fffffffffffffffLL)
24#endif
25<#
26
27
28;;; int-limits
29
30(module int-limits (;export
31  ;
32  machine-word-bits machine-word-precision
33  maximum-unsigned-machine-word
34  most-negative-machine-word most-positive-machine-word
35  ;
36  unsigned-integer32-size
37  maximum-unsigned-integer32
38  most-negative-integer32 most-positive-integer32
39  ;
40  ;;unsigned-integer64-size
41  ;;maximum-unsigned-integer64
42  ;;most-negative-integer64 most-positive-integer64
43  ;
44  char-size       unsigned-char-size
45  short-size      unsigned-short-size
46  int-size        unsigned-int-size
47  long-size       unsigned-long-size
48  long-long-size  unsigned-long-long-size )
49
50(import scheme chicken foreign)
51
52;; machine-word
53
54(define machine-word-bits (foreign-value "C_WORD_SIZE" int))
55(define machine-word-precision (foreign-value "(C_WORD_SIZE - 1)" int))
56(define maximum-unsigned-machine-word (foreign-value "C_UWORD_MAX" unsigned-long))
57(define most-negative-machine-word (foreign-value "C_WORD_MIN" long))
58(define most-positive-machine-word (foreign-value "C_WORD_MAX" long))
59
60;; integer32
61
62(define unsigned-integer32-size (foreign-value "sizeof( uint32_t )" int))
63(define maximum-unsigned-integer32 (foreign-value "((uint32_t)(~0UL))" unsigned-integer32))
64(define most-negative-integer32 (foreign-value "(-MOST_POSITIVE_INT32 - 1)" integer32))
65(define most-positive-integer32 (foreign-value "MOST_POSITIVE_INT32" integer32))
66
67;; integer64
68
69;;(define unsigned-integer64-size (foreign-value "sizeof( uint64_t )" int))
70;;(define maximum-unsigned-integer64 (foreign-value "((uint64_t)(~0ULL))" unsigned-integer64))
71;;(define most-negative-integer64 (foreign-value "(-MOST_POSITIVE_INT64 - 1)" integer64))
72;;(define most-positive-integer64 (foreign-value "MOST_POSITIVE_INT64" integer64))
73
74;; char
75
76(define unsigned-char-size (foreign-value "sizeof( unsigned char )" int))
77(define char-size (foreign-value "sizeof( unsigned char )" int))
78
79;; short
80
81(define unsigned-short-size (foreign-value "sizeof( unsigned short )" int))
82(define short-size (foreign-value "sizeof( unsigned short )" int))
83
84;; int
85
86(define unsigned-int-size (foreign-value "sizeof( unsigned int )" int))
87(define int-size (foreign-value "sizeof( unsigned int )" int))
88
89;; long
90
91(define unsigned-long-size (foreign-value "sizeof( unsigned long )" int))
92(define long-size (foreign-value "sizeof( unsigned long )" int))
93
94;; long-long
95
96(define unsigned-long-long-size (foreign-value "UNSIGNED_LONG_LONG_SIZE" int))
97(define long-long-size (foreign-value "LONG_LONG_SIZE" int))
98
99) ;module int-limits
Note: See TracBrowser for help on using the repository browser.