12 #include "cl_integer.h"
13 #include "cl_integer_io.h"
16 static const char * const cl_format_ones [20] = {
39 // gibt eine ganze Zahl >0, <1000 im Klartext auf englisch auf den stream aus.
40 // (arg=0 -> gibt nichts aus.)
41 static void format_small_cardinal (cl_ostream stream, uintL arg)
43 var uintL hundreds = floor(arg,100);
44 var uintL tens_and_ones = arg % 100;
46 fprint(stream,cl_format_ones[hundreds]);
47 fprint(stream," hundred");
49 if (tens_and_ones > 0) {
51 fprint(stream," and ");
52 var uintL tens = floor(tens_and_ones,10);
53 var uintL ones = tens_and_ones % 10;
55 fprint(stream,cl_format_ones[tens_and_ones]);
57 fprint(stream,cl_format_tens[tens]);
59 fprintchar(stream,'-');
60 fprint(stream,cl_format_ones[ones]);
66 void format_cardinal (cl_ostream stream, const cl_I& argument)
69 fprint(stream,"zero");
71 var cl_I arg = argument;
73 fprint(stream,"minus ");
76 // amerikanisch (billion=10^9)
77 static const char * const illions[] = {
102 var uintL small_pieces [sizeof(illions)/sizeof(illions[0])];
103 // Let the recursion begin.
104 var const char * const * illion_ptr = &illions[0];
105 var uintL * small_piece_ptr = &small_pieces[0];
107 if (*illion_ptr == NULL) {
108 fprint(cl_stderr, "format_cardinal: argument too large: ");
109 fprint(cl_stderr, argument);
110 fprint(cl_stderr, "\n");
113 var cl_I_div_t div = floor2(arg,1000);
114 var const cl_I& thousands = div.quotient;
115 var uintL small = cl_I_to_UL(div.remainder);
117 *small_piece_ptr++ = small;
120 // Roll back the recursion.
121 var cl_boolean first_piece = cl_true;
123 var uintL small = *--small_piece_ptr;
124 var const char * illion = *--illion_ptr;
128 format_small_cardinal(stream,small);
129 fprint(stream,illion);
130 first_piece = cl_false;
132 } until (illion_ptr == &illions[0]);