]> www.ginac.de Git - cln.git/blob - src/base/output/cl_output_hex.cc
64-bit mingw port: Extend fprintdecimal and fprinthexadecimal up to 'long long'.
[cln.git] / src / base / output / cl_output_hex.cc
1 // fprinthexadecimal().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "cln/io.h"
8
9
10 // Implementation.
11
12 namespace cln {
13
14 void fprinthexadecimal_impl (std::ostream& stream, uintptr_t x)
15 {
16         #define bufsize (sizeof(uintptr_t)*2)
17         var char buf[bufsize+1];
18         var char* bufptr = &buf[bufsize];
19         *bufptr = '\0';
20         do {
21                 uintptr_t q = x / 16;
22                 uintptr_t r = x % 16;
23                 *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
24                 x = q;
25         } while (x > 0);
26         fprint(stream,bufptr);
27         #undef bufsize
28 }
29
30 void fprinthexadecimal_impl (std::ostream& stream, intptr_t x)
31 {
32         if (x >= 0)
33                 fprintdecimal(stream,(uintptr_t)x);
34         else {
35                 fprintchar(stream,'-');
36                 fprintdecimal(stream,(uintptr_t)(-1-x)+1);
37         }
38 }
39
40 #if defined(HAVE_LONGLONG) && (long_long_bitsize > pointer_bitsize)
41
42 void fprinthexadecimal (std::ostream& stream, unsigned long long x)
43 {
44         #define bufsize (sizeof(unsigned long long)*2)
45         var char buf[bufsize+1];
46         var char* bufptr = &buf[bufsize];
47         *bufptr = '\0';
48         do {
49                 unsigned long long q = x / 16;
50                 unsigned long long r = x % 16;
51                 *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
52                 x = q;
53         } while (x > 0);
54         fprint(stream,bufptr);
55         #undef bufsize
56 }
57
58 void fprinthexadecimal (std::ostream& stream, long long x)
59 {
60         if (x >= 0)
61                 fprintdecimal(stream,(unsigned long long)x);
62         else {
63                 fprintchar(stream,'-');
64                 fprintdecimal(stream,(unsigned long long)(-1-x)+1);
65         }
66 }
67
68 #endif
69
70 }  // namespace cln