]> www.ginac.de Git - cln.git/blob - src/base/output/cl_output_dec.cc
3465bf124375ae1efbea7f3258f8e74a96e79dd3
[cln.git] / src / base / output / cl_output_dec.cc
1 // fprintdecimal().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_io.h"
8
9
10 // Implementation.
11
12 #if defined(CL_IO_STDIO)
13
14 void fprintdecimal (cl_ostream stream, unsigned long x)
15 {
16         fprintf(stream,"%lu",x);
17 }
18
19 void fprintdecimal (cl_ostream stream, long x)
20 {
21         fprintf(stream,"%ld",x);
22 }
23
24 #endif
25
26 #if defined(CL_IO_IOSTREAM)
27
28 // We don't use `stream << x' or `stream << dec << x', because an ostream
29 // carries so many attributes, and we don't want to modifies these attributes.
30
31 void fprintdecimal (cl_ostream stream, unsigned long x)
32 {
33         #define bufsize 20
34         var char buf[bufsize+1];
35         var char* bufptr = &buf[bufsize];
36         *bufptr = '\0';
37         do {
38                 unsigned long q = x / 10;
39                 unsigned long r = x % 10;
40                 *--bufptr = '0'+r;
41                 x = q;
42         } while (x > 0);
43         fprint(stream,bufptr);
44         #undef bufsize
45 }
46
47 void fprintdecimal (cl_ostream stream, long x)
48 {
49         if (x >= 0)
50                 fprintdecimal(stream,(unsigned long)x);
51         else {
52                 fprintchar(stream,'-');
53                 fprintdecimal(stream,(unsigned long)(-1-x)+1);
54         }
55 }
56
57 #endif