13 #include "cln/integer.h"
14 #include "cln/integer_io.h"
15 #include "cln/exception.h"
19 static const char * const cl_format_ones [20] = {
42 // gibt eine ganze Zahl >0, <1000 im Klartext auf englisch auf den stream aus.
43 // (arg=0 -> gibt nichts aus.)
44 static void format_small_cardinal (std::ostream& stream, uintL arg)
46 var uintL hundreds = floor(arg,100);
47 var uintL tens_and_ones = arg % 100;
49 fprint(stream,cl_format_ones[hundreds]);
50 fprint(stream," hundred");
52 if (tens_and_ones > 0) {
54 fprint(stream," and ");
55 var uintL tens = floor(tens_and_ones,10);
56 var uintL ones = tens_and_ones % 10;
58 fprint(stream,cl_format_ones[tens_and_ones]);
60 fprint(stream,cl_format_tens[tens]);
62 fprintchar(stream,'-');
63 fprint(stream,cl_format_ones[ones]);
69 void format_cardinal (std::ostream& stream, const cl_I& argument)
72 fprint(stream,"zero");
74 var cl_I arg = argument;
76 fprint(stream,"minus ");
79 // amerikanisch (billion=10^9)
80 static const char * const illions[] = {
105 var uintL small_pieces [sizeof(illions)/sizeof(illions[0])];
106 // Let the recursion begin.
107 var const char * const * illion_ptr = &illions[0];
108 var uintL * small_piece_ptr = &small_pieces[0];
110 if (*illion_ptr == NULL) {
111 std::ostringstream buf;
112 fprint(buf, "format_cardinal: argument too large: ");
113 fprint(buf, argument);
114 throw runtime_exception(buf.str());
116 var cl_I_div_t div = floor2(arg,1000);
117 var const cl_I& thousands = div.quotient;
118 var uintL small = cl_I_to_UL(div.remainder);
120 *small_piece_ptr++ = small;
123 // Roll back the recursion.
124 var bool first_piece = true;
126 var uintL small = *--small_piece_ptr;
127 var const char * illion = *--illion_ptr;
131 format_small_cardinal(stream,small);
132 fprint(stream,illion);
135 } until (illion_ptr == &illions[0]);