12 #include "cln/integer.h"
13 #include "cln/integer_io.h"
14 #include "cln/abort.h"
18 static const char * const cl_format_ones [20] = {
41 // gibt eine ganze Zahl >0, <1000 im Klartext auf englisch auf den stream aus.
42 // (arg=0 -> gibt nichts aus.)
43 static void format_small_cardinal (cl_ostream stream, uintL arg)
45 var uintL hundreds = floor(arg,100);
46 var uintL tens_and_ones = arg % 100;
48 fprint(stream,cl_format_ones[hundreds]);
49 fprint(stream," hundred");
51 if (tens_and_ones > 0) {
53 fprint(stream," and ");
54 var uintL tens = floor(tens_and_ones,10);
55 var uintL ones = tens_and_ones % 10;
57 fprint(stream,cl_format_ones[tens_and_ones]);
59 fprint(stream,cl_format_tens[tens]);
61 fprintchar(stream,'-');
62 fprint(stream,cl_format_ones[ones]);
68 void format_cardinal (cl_ostream stream, const cl_I& argument)
71 fprint(stream,"zero");
73 var cl_I arg = argument;
75 fprint(stream,"minus ");
78 // amerikanisch (billion=10^9)
79 static const char * const illions[] = {
104 var uintL small_pieces [sizeof(illions)/sizeof(illions[0])];
105 // Let the recursion begin.
106 var const char * const * illion_ptr = &illions[0];
107 var uintL * small_piece_ptr = &small_pieces[0];
109 if (*illion_ptr == NULL) {
110 fprint(stderr, "format_cardinal: argument too large: ");
111 fprint(stderr, argument);
112 fprint(stderr, "\n");
115 var cl_I_div_t div = floor2(arg,1000);
116 var const cl_I& thousands = div.quotient;
117 var uintL small = cl_I_to_UL(div.remainder);
119 *small_piece_ptr++ = small;
122 // Roll back the recursion.
123 var cl_boolean first_piece = cl_true;
125 var uintL small = *--small_piece_ptr;
126 var const char * illion = *--illion_ptr;
130 format_small_cardinal(stream,small);
131 fprint(stream,illion);
132 first_piece = cl_false;
134 } until (illion_ptr == &illions[0]);