summaryrefslogtreecommitdiff
path: root/src/mpfr-intmax.h
blob: 3a4934f987541b2dec141bf6c4e0acd91afea19e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* MPFR internal header related to intmax_t.

Copyright 2004-2021 Free Software Foundation, Inc.
Contributed by the AriC and Caramba projects, INRIA.

This file is part of the GNU MPFR Library.

The GNU MPFR Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

The GNU MPFR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */

/* If you need something defined here, do not include this header file
   directly, but define the MPFR_NEED_INTMAX_H macro before including
   "mpfr-impl.h" (or "mpfr-test.h" in the tests). This will ensure that
   this header file "mpfr-intmax.h" is included in a consistent way,
   thus avoiding the various cases that could otherwise be obtained on
   different platforms and compilation options. Note that in particular,
   it needs <limits.h> (always included first in "mpfr-impl.h") if
   <inttypes.h> or <stdint.h> does not exist or does not work. It also
   needs "config.h" if used (HAVE_CONFIG_H defined), but "config.h" is
   also included first in "mpfr-impl.h". */

#ifndef MPFR_NEED_INTMAX_H
# error "Never include mpfr-intmax.h directly; define MPFR_NEED_INTMAX_H instead."
#endif

#ifndef __MPFR_INTMAX_H__
#define __MPFR_INTMAX_H__

/* The ISO C99 standard specifies that in C++ implementations the
 * INTMAX_MAX, ... macros should only be defined if explicitly requested.
 */
#if defined __cplusplus
# define __STDC_LIMIT_MACROS
# define __STDC_CONSTANT_MACROS
#endif

/* The definition of MPFR_USE_INTMAX_T is needed on systems for which
 * the current (non-standard) macro tests in mpfr.h is not sufficient.
 * This will force the support of intmax_t/uintmax_t if <inttypes.h>
 * and/or <stdint.h> are available. This also avoids a failure in the
 * tests (replace the macro tests in mpfr.h by just
 *   #if defined (MPFR_USE_INTMAX_T)
 * to simulate such a system and reproduce the problem).
 * Note: if this makes the build fail on some systems (because these
 * headers are broken), we will need a configure test to undefine
 * HAVE_INTTYPES_H and HAVE_STDINT_H in such a case.
 */

#if HAVE_INTTYPES_H
# include <inttypes.h>
# define MPFR_USE_INTMAX_T
#endif

#if HAVE_STDINT_H
# include <stdint.h>
# define MPFR_USE_INTMAX_T
#endif

/* Largest integer type available and fully working for the MPFR build
   (may be smaller than intmax_t / uintmax_t if NPRINTF_J is defined). */
#if defined(MPFR_USE_INTMAX_T) && !defined(NPRINTF_J)
typedef uintmax_t mpfr_uintmax_t;
typedef intmax_t mpfr_intmax_t;
# define MPFR_UINTMAX_MAX UINTMAX_MAX
# define MPFR_INTMAX_MAX INTMAX_MAX
# define MPFR_INTMAX_MIN INTMAX_MIN
# define MPFR_INTMAX_FSPEC "j"
#elif defined(HAVE_LONG_LONG) && !defined(NPRINTF_LL)
typedef unsigned long long mpfr_uintmax_t;
typedef long long mpfr_intmax_t;
#if defined(ULLONG_MAX)
/* standard */
# define MPFR_UINTMAX_MAX ULLONG_MAX
# define MPFR_INTMAX_MAX LLONG_MAX
# define MPFR_INTMAX_MIN LLONG_MIN
#elif defined(ULONGLONG_MAX)
/* Silicon Graphics IRIX 6.5 with native /usr/bin/cc */
# define MPFR_UINTMAX_MAX ULONGLONG_MAX
# define MPFR_INTMAX_MAX LONGLONG_MAX
# define MPFR_INTMAX_MIN LONGLONG_MIN
#else
/* We do not know any platform in this case (but this case would be a bug).
   Let's give an error. A workaround should be possible, but it should be
   tested first. */
# error "Neither ULLONG_MAX nor ULONGLONG_MAX is defined."
#endif
# define MPFR_INTMAX_FSPEC "ll"
#else
typedef unsigned long mpfr_uintmax_t;
typedef long mpfr_intmax_t;
# define MPFR_UINTMAX_MAX ULONG_MAX
# define MPFR_INTMAX_MAX LONG_MAX
# define MPFR_INTMAX_MIN LONG_MIN
# define MPFR_INTMAX_FSPEC "l"
#endif

#endif