Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 08:08:31

0001 // I/O of integers.
0002 
0003 #ifndef _CL_INTEGER_IO_H
0004 #define _CL_INTEGER_IO_H
0005 
0006 #include "cln/number_io.h"
0007 #include "cln/integer_class.h"
0008 
0009 namespace cln {
0010 
0011 // Input functions
0012 
0013 // Wandelt eine Zeichenkette mit Integer-Syntax in ein Integer um.
0014 // Punkte werden überlesen.
0015 // read_integer(base,sign,string,index1,index2)
0016 // > base: Lesebasis (>=2, <=36)
0017 // > sign: Vorzeichen (/=0 falls negativ)
0018 // > string: Simple-String (enthält Ziffern mit Wert <base und evtl. Punkt)
0019 // > index1: Index der ersten Ziffer
0020 // > index2: Index nach der letzten Ziffer
0021 //   (also index2-index1 Ziffern, incl. evtl. Dezimalpunkt am Schluß)
0022 // < ergebnis: Integer
0023 extern const cl_I read_integer (unsigned int base,
0024                   cl_signean sign, const char * string, uintC index1, uintC index2);
0025 
0026 // The following does strictly the same as the general read_complex.
0027 // It is here only so that you don't need the rational, complex and float number
0028 // readers in order to read an integer. ("Treeshaking")
0029 extern const cl_I read_integer (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse);
0030 extern const cl_I read_integer (std::istream& stream, const cl_read_flags& flags);
0031 
0032 inline std::istream& operator>> (std::istream& stream, cl_I& result)
0033 {
0034     extern cl_read_flags cl_I_read_flags;
0035     result = read_integer(stream,cl_I_read_flags);
0036     return stream;
0037 }
0038 
0039 
0040 // Output functions
0041 
0042 // Liefert zu einem Integer >=0  (write-to-string integer :base 10 :radix nil),
0043 // also die Ziffernfolge als String.
0044 // Mit malloc_hook() alloziert, mit free_hook() freizugeben.
0045 extern char * cl_decimal_string (const cl_I& x);
0046 
0047 // Gibt ein Integer aus.
0048 // print_integer(stream,base,z);
0049 // > z: Integer
0050 // > base: Basis (>=2, <=36)
0051 // > stream: Stream
0052 extern void print_integer (std::ostream& stream, unsigned int base, const cl_I& z);
0053 // Dasselbe als String. Mit malloc_hook() alloziert, mit free_hook() freizugeben.
0054 extern char * print_integer_to_string (unsigned int base, const cl_I& z);
0055 
0056 inline void fprintdecimal (std::ostream& stream, const cl_I& x)
0057 {
0058     print_integer(stream,10,x);
0059 }
0060 
0061 inline void fprintbinary (std::ostream& stream, const cl_I& x)
0062 {
0063     print_integer(stream,2,x);
0064 }
0065 
0066 inline void fprintoctal (std::ostream& stream, const cl_I& x)
0067 {
0068     print_integer(stream,8,x);
0069 }
0070 
0071 inline void fprinthexadecimal (std::ostream& stream, const cl_I& x)
0072 {
0073     print_integer(stream,16,x);
0074 }
0075 
0076 // Gibt eine Zahl aus.
0077 // print_integer(stream,flags,z);
0078 // > z: Zahl
0079 // > stream: Stream
0080 // > flags: Ausgabe-Parameter
0081 extern void print_integer (std::ostream& stream, const cl_print_flags& flags, const cl_I& z);
0082 extern void print_integer (std::ostream& stream, const cl_print_number_flags& flags, const cl_I& z);
0083 extern void print_integer (std::ostream& stream, const cl_print_real_flags& flags, const cl_I& z);
0084 extern void print_integer (std::ostream& stream, const cl_print_rational_flags& flags, const cl_I& z);
0085 
0086 // The following does strictly the same as the general `fprint' for numbers.
0087 // It is here only so that you don't need the rational number printer
0088 // in order to print an integer. ("Treeshaking")
0089 
0090 inline void fprint (std::ostream& stream, const cl_I& x)
0091 {
0092     extern cl_print_flags default_print_flags;
0093     print_integer(stream,default_print_flags,x);
0094 }
0095 
0096 CL_DEFINE_PRINT_OPERATOR(cl_I)
0097 
0098 }  // namespace cln
0099 
0100 #endif /* _CL_INTEGER_IO_H */