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

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

Release.

File size: 3.0 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#else
16# define LONG_LONG_SIZE           -1
17#endif
18#if defined(UNSIGNED_LONG_LONG_SIZE) && UNSIGNED_LONG_LONG_SIZE
19# define UNSIGNED_LONG_LONG_SIZE  sizeof( unsigned long long )
20#else
21# define UNSIGNED_LONG_LONG_SIZE  -1
22#endif
23
24*define MOST_POSITIVE_INT32 ((int32_t)(0x7fffffffUL))
25*define MOST_POSITIVE_INT64 ((int64_t)(0x7fffffffffffffffLL))
26<#
27
28
29;;; int-limits
30
31(module int-limits (;export
32  ;
33  machine-word-bits machine-word-precision
34  maximum-unsigned-machine-word
35  most-negative-machine-word most-positive-machine-word
36  ;
37  unsigned-integer32-size
38  maximum-unsigned-integer32
39  most-negative-integer32 most-positive-integer32
40  ;
41  unsigned-integer64-size
42  maximum-unsigned-integer64
43  most-negative-integer64 most-positive-integer64
44  ;
45  char-size       unsigned-char-size
46  short-size      unsigned-short-size
47  int-size        unsigned-int-size
48  long-size       unsigned-long-size
49  long-long-size  unsigned-long-long-size )
50
51(import scheme chicken foreign)
52
53;; machine-word
54
55(define machine-word-bits (foreign-value "C_WORD_SIZE" int))
56(define machine-word-precision (foreign-value "(C_WORD_SIZE - 1)" int))
57(define maximum-unsigned-machine-word (foreign-value "C_UWORD_MAX" unsigned-long))
58(define most-negative-machine-word (foreign-value "C_WORD_MIN" long))
59(define most-positive-machine-word (foreign-value "C_WORD_MAX" long))
60
61;; integer32
62
63(define unsigned-integer32-size (foreign-value "sizeof( uint32_t )" int))
64(define maximum-unsigned-integer32 (foreign-value "((uint32_t)(~0UL))" unsigned-integer32))
65(define most-negative-integer32 (foreign-value "(-MOST_POSITIVE_INT32 - 1)" integer32))
66(define most-positive-integer32 (foreign-value "MOST_POSITIVE_INT32" integer32))
67
68;; integer64
69
70(define unsigned-integer64-size (foreign-value "sizeof( uint64_t )" int))
71(define maximum-unsigned-integer64 (foreign-value "((uint64_t)(~0ULL))" unsigned-integer64))
72(define most-negative-integer64 (foreign-value "(-MOST_POSITIVE_INT64 - 1)" integer64))
73(define most-positive-integer64 (foreign-value "MOST_POSITIVE_INT64" integer64))
74
75;; char
76
77(define unsigned-char-size (foreign-value "sizeof( unsigned char )" int))
78(define char-size (foreign-value "sizeof( unsigned char )" int))
79
80;; short
81
82(define unsigned-short-size (foreign-value "sizeof( unsigned short )" int))
83(define short-size (foreign-value "sizeof( unsigned short )" int))
84
85;; int
86
87(define unsigned-int-size (foreign-value "sizeof( unsigned int )" int))
88(define int-size (foreign-value "sizeof( unsigned int )" int))
89
90;; long
91
92(define unsigned-long-size (foreign-value "sizeof( unsigned long )" int))
93(define long-size (foreign-value "sizeof( unsigned long )" int))
94
95;; long-long
96
97(define unsigned-long-long-size (foreign-value "UNSIGNED_LONG_LONG_SIZE" int))
98(define long-long-size (foreign-value "LONG_LONG_SIZE" int))
99
100) ;module int-limits
Note: See TracBrowser for help on using the repository browser.