1 // I/O of rational numbers.
2 
3 #ifndef _CL_RATIONAL_IO_H
4 #define _CL_RATIONAL_IO_H
5 
6 #include "cln/number_io.h"
7 #include "cln/rational.h"
8 
9 namespace cln {
10 
11 // Undocumented input functions
12 
13 // Wandelt eine Zeichenkette mit Rational-Syntax in eine rationale Zahl um.
14 // read_rational(base,sign,string,index1,index3,index2)
15 // > base: Lesebasis (>=2, <=36)
16 // > sign: Vorzeichen (/=0 falls negativ)
17 // > string: Simple-String (enthält Ziffern mit Wert <base und Bruchstrich)
18 // > index1: Index der ersten Ziffer
19 // > index3: Index von '/'
20 // > index2: Index nach der letzten Ziffer
21 //   (also index3-index1 Zähler-Ziffern, index2-index3-1 Nenner-Ziffern)
22 // < ergebnis: rationale Zahl
23 extern const cl_RA read_rational (unsigned int base,
24                    cl_signean sign, const char * string, uintC index1, uintC index3, uintC index2);
25 
26 // The following does strictly the same as the general read_complex.
27 // It is here only so that you don't need the complex and float number
28 // readers in order to read an rational number. ("Treeshaking")
29 extern const cl_RA read_rational (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse);
30 extern const cl_RA read_rational (std::istream& stream, const cl_read_flags& flags);
31 
32 // Documented input functions
33 
34 inline std::istream& operator>> (std::istream& stream, cl_RA& result)
35 {
36 	extern cl_read_flags cl_RA_read_flags;
37 	result = read_rational(stream,cl_RA_read_flags);
38 	return stream;
39 }
40 
41 
42 // Undocumented output functions
43 
44 // Gibt eine rationale Zahl aus.
45 // print_rational(stream,base,z);
46 // > z: rationale Zahl
47 // > base: Basis (>=2, <=36)
48 // > stream: Stream
49 extern void print_rational (std::ostream& stream, unsigned int base, const cl_RA& z);
50 
51 
52 // Documented output functions
53 
54 // Gibt eine Zahl aus.
55 // print_rational(stream,flags,z);
56 // > z: Zahl
57 // > stream: Stream
58 // > flags: Ausgabe-Parameter
59 extern void print_rational (std::ostream& stream, const cl_print_flags& flags, const cl_RA& z);
60 extern void print_rational (std::ostream& stream, const cl_print_number_flags& flags, const cl_RA& z);
61 extern void print_rational (std::ostream& stream, const cl_print_real_flags& flags, const cl_RA& z);
62 extern void print_rational (std::ostream& stream, const cl_print_rational_flags& flags, const cl_RA& z);
63 
64 // The following does strictly the same as the general `fprint' for numbers.
65 // It is here only so that you don't need the complex and long-float number
66 // printers in order to print an integer. ("Treeshaking")
67 
fprint(std::ostream & stream,const cl_RA & x)68 inline void fprint (std::ostream& stream, const cl_RA& x)
69 {
70 	extern cl_print_flags default_print_flags;
71 	print_rational(stream,default_print_flags,x);
72 }
73 
74 CL_DEFINE_PRINT_OPERATOR(cl_RA)
75 
76 }  // namespace cln
77 
78 #endif /* _CL_RATIONAL_IO_H */
79