]> www.ginac.de Git - cln.git/blob - src/base/output/cl_output_dec.cc
* Add table of contents in TeX output.
[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 "cln/io.h"
8
9
10 // Implementation.
11
12 namespace cln {
13
14 // We don't use `stream << x' or `stream << dec << x', because an ostream
15 // carries so many attributes, and we don't want to modifies these attributes.
16
17 void fprintdecimal (std::ostream& stream, unsigned long x)
18 {
19         #define bufsize 20
20         var char buf[bufsize+1];
21         var char* bufptr = &buf[bufsize];
22         *bufptr = '\0';
23         do {
24                 unsigned long q = x / 10;
25                 unsigned long r = x % 10;
26                 *--bufptr = '0'+r;
27                 x = q;
28         } while (x > 0);
29         fprint(stream,bufptr);
30         #undef bufsize
31 }
32
33 void fprintdecimal (std::ostream& stream, long x)
34 {
35         if (x >= 0)
36                 fprintdecimal(stream,(unsigned long)x);
37         else {
38                 fprintchar(stream,'-');
39                 fprintdecimal(stream,(unsigned long)(-1-x)+1);
40         }
41 }
42
43 }  // namespace cln