_limits.h revision 99129
199129Sobrien/*
299129Sobrien * Copyright (c) 1988, 1993
399129Sobrien *	The Regents of the University of California.  All rights reserved.
499129Sobrien *
599129Sobrien * Redistribution and use in source and binary forms, with or without
699129Sobrien * modification, are permitted provided that the following conditions
799129Sobrien * are met:
899129Sobrien * 1. Redistributions of source code must retain the above copyright
999129Sobrien *    notice, this list of conditions and the following disclaimer.
1099129Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1199129Sobrien *    notice, this list of conditions and the following disclaimer in the
1299129Sobrien *    documentation and/or other materials provided with the distribution.
1399129Sobrien * 3. All advertising materials mentioning features or use of this software
1499129Sobrien *    must display the following acknowledgement:
1599129Sobrien *	This product includes software developed by the University of
1699129Sobrien *	California, Berkeley and its contributors.
1799129Sobrien * 4. Neither the name of the University nor the names of its contributors
1899129Sobrien *    may be used to endorse or promote products derived from this software
1999129Sobrien *    without specific prior written permission.
2099129Sobrien *
2199129Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2299129Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2399129Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2499129Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2599129Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2699129Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2799129Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2899129Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2999129Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3099129Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3199129Sobrien * SUCH DAMAGE.
3299129Sobrien *
3399129Sobrien *	@(#)limits.h	8.3 (Berkeley) 1/4/94
3499129Sobrien *	From: NetBSD: limits.h,v 1.3 1997/04/06 08:47:31 cgd Exp
3599129Sobrien * 	From: FreeBSD: src/sys/alpha/include/limits.h,v 1.8 2001/11/02
3699129Sobrien * $FreeBSD: head/sys/amd64/include/_limits.h 99129 2002-06-30 08:57:17Z obrien $
3799129Sobrien */
3899129Sobrien
3999129Sobrien#ifndef	_MACHINE_LIMITS_H_
4099129Sobrien#define	_MACHINE_LIMITS_H_
4199129Sobrien
4299129Sobrien#define	CHAR_BIT	8		/* number of bits in a char */
4399129Sobrien#define	MB_LEN_MAX	6		/* Allow 31 bit UTF2 */
4499129Sobrien
4599129Sobrien/*
4699129Sobrien * According to ANSI (section 2.2.4.2), the values below must be usable by
4799129Sobrien * #if preprocessing directives.  Additionally, the expression must have the
4899129Sobrien * same type as would an expression that is an object of the corresponding
4999129Sobrien * type converted according to the integral promotions.  The subtraction for
5099129Sobrien * INT_MIN, etc., is so the value is not unsigned; e.g., 0x80000000 is an
5199129Sobrien * unsigned int for 32-bit two's complement ANSI compilers (section 3.1.3.2).
5299129Sobrien * These numbers are for the default configuration of gcc.  They work for
5399129Sobrien * some other compilers as well, but this should not be depended on.
5499129Sobrien */
5599129Sobrien#define	SCHAR_MAX	0x7f		/* max value for a signed char */
5699129Sobrien#define	SCHAR_MIN	(-0x7f-1)	/* min value for a signed char */
5799129Sobrien
5899129Sobrien#define	UCHAR_MAX	0xffU		/* max value for an unsigned char */
5999129Sobrien#define	CHAR_MAX	0x7f		/* max value for a char */
6099129Sobrien#define	CHAR_MIN	(-0x7f-1)	/* min value for a char */
6199129Sobrien
6299129Sobrien#define	USHRT_MAX	0xffffU		/* max value for an unsigned short */
6399129Sobrien#define	SHRT_MAX	0x7fff		/* max value for a short */
6499129Sobrien#define	SHRT_MIN	(-0x7fff-1)	/* min value for a short */
6599129Sobrien
6699129Sobrien#define	UINT_MAX	0xffffffffU	/* max value for an unsigned int */
6799129Sobrien#define	INT_MAX		0x7fffffff	/* max value for an int */
6899129Sobrien#define	INT_MIN		(-0x7fffffff-1)	/* min value for an int */
6999129Sobrien
7099129Sobrien#define	ULONG_MAX	0xffffffffffffffffUL	/* max for an unsigned long */
7199129Sobrien#define	LONG_MAX	0x7fffffffffffffffL	/* max for a long */
7299129Sobrien#define	LONG_MIN	(-0x7fffffffffffffffL-1) /* min for a long */
7399129Sobrien
7499129Sobrien/* Long longs and longs are the same size on the alpha. */
7599129Sobrien					/* max for an unsigned long long */
7699129Sobrien#define	ULLONG_MAX	0xffffffffffffffffULL
7799129Sobrien#define	LLONG_MAX	0x7fffffffffffffffLL	/* max for a long long */
7899129Sobrien#define	LLONG_MIN	(-0x7fffffffffffffffLL-1) /* min for a long long */
7999129Sobrien
8099129Sobrien#if !defined(_ANSI_SOURCE)
8199129Sobrien#define	SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
8299129Sobrien
8399129Sobrien#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
8499129Sobrien#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t */
8599129Sobrien
8699129Sobrien#define	OFF_MAX		LONG_MAX	/* max value for a off_t */
8799129Sobrien#define	OFF_MIN		LONG_MIN	/* min value for a off_t */
8899129Sobrien
8999129Sobrien/* Quads and longs are the same on the alpha.  Ensure they stay in sync. */
9099129Sobrien#define	UQUAD_MAX	(ULONG_MAX)	/* max value for a uquad_t */
9199129Sobrien#define	QUAD_MAX	(LONG_MAX)	/* max value for a quad_t */
9299129Sobrien#define	QUAD_MIN	(LONG_MIN)	/* min value for a quad_t */
9399129Sobrien
9499129Sobrien#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
9599129Sobrien/*
9699129Sobrien * ISO/IEC 9899:1999
9799129Sobrien * 7.18.2.1 Limits of exact-width integer types
9899129Sobrien */
9999129Sobrien/* Minimum values of exact-width signed integer types. */
10099129Sobrien#define	INT8_MIN	(-0x7f-1)
10199129Sobrien#define	INT16_MIN	(-0x7fff-1)
10299129Sobrien#define	INT32_MIN	(-0x7fffffff-1)
10399129Sobrien#define	INT64_MIN	(-0x7fffffffffffffffL-1)
10499129Sobrien
10599129Sobrien/* Maximum values of exact-width signed integer types. */
10699129Sobrien#define	INT8_MAX	0x7f
10799129Sobrien#define	INT16_MAX	0x7fff
10899129Sobrien#define	INT32_MAX	0x7fffffff
10999129Sobrien#define	INT64_MAX	0x7fffffffffffffffL
11099129Sobrien
11199129Sobrien/* Maximum values of exact-width unsigned integer types. */
11299129Sobrien#define	UINT8_MAX	0xff
11399129Sobrien#define	UINT16_MAX	0xffff
11499129Sobrien#define	UINT32_MAX	0xffffffffU
11599129Sobrien#define	UINT64_MAX	0xffffffffffffffffUL
11699129Sobrien
11799129Sobrien/*
11899129Sobrien * ISO/IEC 9899:1999
11999129Sobrien * 7.18.2.2  Limits of minimum-width integer types
12099129Sobrien */
12199129Sobrien/* Minimum values of minimum-width signed integer types. */
12299129Sobrien#define	INT_LEAST8_MIN	SCHAR_MIN
12399129Sobrien#define	INT_LEAST16_MIN	SHRT_MIN
12499129Sobrien#define	INT_LEAST32_MIN	INT_MIN
12599129Sobrien#define	INT_LEAST64_MIN	LONG_MIN
12699129Sobrien
12799129Sobrien/* Maximum values of minimum-width signed integer types. */
12899129Sobrien#define	INT_LEAST8_MAX	SCHAR_MAX
12999129Sobrien#define	INT_LEAST16_MAX	SHRT_MAX
13099129Sobrien#define	INT_LEAST32_MAX	INT_MAX
13199129Sobrien#define	INT_LEAST64_MAX	LONG_MAX
13299129Sobrien
13399129Sobrien/* Maximum values of minimum-width unsigned integer types. */
13499129Sobrien#define	UINT_LEAST8_MAX	 UCHAR_MAX
13599129Sobrien#define	UINT_LEAST16_MAX USHRT_MAX
13699129Sobrien#define	UINT_LEAST32_MAX UINT_MAX
13799129Sobrien#define	UINT_LEAST64_MAX ULONG_MAX
13899129Sobrien
13999129Sobrien/*
14099129Sobrien * ISO/IEC 9899:1999
14199129Sobrien * 7.18.2.3  Limits of fastest minimum-width integer types
14299129Sobrien */
14399129Sobrien/* Minimum values of fastest minimum-width signed integer types. */
14499129Sobrien#define	INT_FAST8_MIN	INT_MIN
14599129Sobrien#define	INT_FAST16_MIN	INT_MIN
14699129Sobrien#define	INT_FAST32_MIN	INT_MIN
14799129Sobrien#define	INT_FAST64_MIN	LONG_MIN
14899129Sobrien
14999129Sobrien/* Maximum values of fastest minimum-width signed integer types. */
15099129Sobrien#define	INT_FAST8_MAX	INT_MAX
15199129Sobrien#define	INT_FAST16_MAX	INT_MAX
15299129Sobrien#define	INT_FAST32_MAX	INT_MAX
15399129Sobrien#define	INT_FAST64_MAX	LONG_MAX
15499129Sobrien
15599129Sobrien/* Maximum values of fastest minimum-width unsigned integer types. */
15699129Sobrien#define	UINT_FAST8_MAX	UINT_MAX
15799129Sobrien#define	UINT_FAST16_MAX	UINT_MAX
15899129Sobrien#define	UINT_FAST32_MAX	UINT_MAX
15999129Sobrien#define	UINT_FAST64_MAX	ULONG_MAX
16099129Sobrien
16199129Sobrien/*
16299129Sobrien * ISO/IEC 9899:1999
16399129Sobrien * 7.18.2.4  Limits of integer types capable of holding object pointers
16499129Sobrien */
16599129Sobrien#define	INTPTR_MIN	LONG_MIN
16699129Sobrien#define	INTPTR_MAX	LONG_MAX
16799129Sobrien#define	UINTPTR_MAX	ULONG_MAX
16899129Sobrien
16999129Sobrien/*
17099129Sobrien * ISO/IEC 9899:1999
17199129Sobrien * 7.18.2.5  Limits of greatest-width integer types
17299129Sobrien */
17399129Sobrien#define	INTMAX_MIN	LONG_MIN
17499129Sobrien#define	INTMAX_MAX	LONG_MAX
17599129Sobrien#define	UINTMAX_MAX	ULONG_MAX
17699129Sobrien
17799129Sobrien/*
17899129Sobrien * ISO/IEC 9899:1999
17999129Sobrien * 7.18.3  Limits of other integer types
18099129Sobrien */
18199129Sobrien/* Limits of ptrdiff_t. */
18299129Sobrien#define	PTRDIFF_MIN	LONG_MIN
18399129Sobrien#define	PTRDIFF_MAX	LONG_MAX
18499129Sobrien
18599129Sobrien/* Limits of sig_atomic_t. */
18699129Sobrien#define	SIG_ATOMIC_MIN	INT_MIN
18799129Sobrien#define	SIG_ATOMIC_MAX	INT_MAX
18899129Sobrien
18999129Sobrien/* Limit of size_t. */
19099129Sobrien#define	SIZE_MAX	ULONG_MAX
19199129Sobrien
19299129Sobrien#ifndef WCHAR_MIN /* Also possibly defined in <wchar.h> */
19399129Sobrien/* Limits of wchar_t. */
19499129Sobrien#define	WCHAR_MIN	INT_MIN
19599129Sobrien#define	WCHAR_MAX	INT_MAX
19699129Sobrien
19799129Sobrien/* Limits of wint_t. */
19899129Sobrien#define	WINT_MIN	INT_MIN
19999129Sobrien#define	WINT_MAX	INT_MAX
20099129Sobrien#endif
20199129Sobrien#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
20299129Sobrien#endif /* !_POSIX_SOURCE && !_XOPEN_SOURCE */
20399129Sobrien#endif /* !_ANSI_SOURCE */
20499129Sobrien
20599129Sobrien#if (!defined(_ANSI_SOURCE)&&!defined(_POSIX_SOURCE)) || defined(_XOPEN_SOURCE)
20699129Sobrien#define	LONG_BIT	64
20799129Sobrien#define	WORD_BIT	32
20899129Sobrien
20999129Sobrien#define	DBL_DIG		15
21099129Sobrien#define	DBL_MAX		1.7976931348623157E+308
21199129Sobrien#define	DBL_MIN		2.2250738585072014E-308
21299129Sobrien
21399129Sobrien#define	FLT_DIG		6
21499129Sobrien#define	FLT_MAX		3.40282347E+38F
21599129Sobrien#define	FLT_MIN		1.17549435E-38F
21699129Sobrien#endif
21799129Sobrien
21899129Sobrien#endif /* !_MACHINE_LIMITS_H_ */
219