Update x86_64 ULps for AMD K10
[glibc.git] / sysdeps / generic / _itoa.h
blob8e0ab6ffeb6363f57e8bef442ad579d35620a69c
1 /* Internal function for converting integers to ASCII.
2 Copyright (C) 1994-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _ITOA_H
20 #define _ITOA_H
22 #include <limits.h>
24 /* When long long is different from long, by default, _itoa_word is
25 provided to convert long to ASCII and _itoa is provided to convert
26 long long. A sysdeps _itoa.h can define _ITOA_NEEDED to 0 and define
27 _ITOA_WORD_TYPE to unsigned long long int to override it so that
28 _itoa_word is changed to convert long long to ASCII and _itoa is
29 mapped to _itoa_word. */
31 #ifndef _ITOA_NEEDED
32 # define _ITOA_NEEDED (LONG_MAX != LLONG_MAX)
33 #endif
34 #ifndef _ITOA_WORD_TYPE
35 # define _ITOA_WORD_TYPE unsigned long int
36 #endif
39 /* Convert VALUE into ASCII in base BASE (2..36).
40 Write backwards starting the character just before BUFLIM.
41 Return the address of the first (left-to-right) character in the number.
42 Use upper case letters iff UPPER_CASE is nonzero. */
44 extern char *_itoa (unsigned long long int value, char *buflim,
45 unsigned int base, int upper_case);
47 extern const char _itoa_upper_digits[];
48 extern const char _itoa_lower_digits[];
49 #if !defined NOT_IN_libc || defined IS_IN_rtld
50 hidden_proto (_itoa_upper_digits)
51 hidden_proto (_itoa_lower_digits)
52 #endif
54 #ifndef NOT_IN_libc
55 extern char *_itoa_word (_ITOA_WORD_TYPE value, char *buflim,
56 unsigned int base, int upper_case);
57 #else
58 static inline char * __attribute__ ((unused, always_inline))
59 _itoa_word (_ITOA_WORD_TYPE value, char *buflim,
60 unsigned int base, int upper_case)
62 const char *digits = (upper_case
63 ? _itoa_upper_digits
64 : _itoa_lower_digits);
66 switch (base)
68 # define SPECIAL(Base) \
69 case Base: \
70 do \
71 *--buflim = digits[value % Base]; \
72 while ((value /= Base) != 0); \
73 break
75 SPECIAL (10);
76 SPECIAL (16);
77 SPECIAL (8);
78 default:
80 *--buflim = digits[value % base];
81 while ((value /= base) != 0);
83 return buflim;
85 # undef SPECIAL
86 #endif
88 /* Similar to the _itoa functions, but output starts at buf and pointer
89 after the last written character is returned. */
90 extern char *_fitoa_word (_ITOA_WORD_TYPE value, char *buf,
91 unsigned int base,
92 int upper_case) attribute_hidden;
93 extern char *_fitoa (unsigned long long value, char *buf, unsigned int base,
94 int upper_case) attribute_hidden;
96 #if !_ITOA_NEEDED
97 /* No need for special long long versions. */
98 # define _itoa(value, buf, base, upper_case) \
99 _itoa_word (value, buf, base, upper_case)
100 # define _fitoa(value, buf, base, upper_case) \
101 _fitoa_word (value, buf, base, upper_case)
102 #endif
104 #endif /* itoa.h */