X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=src%2Ffloat%2Foutput%2Fcl_F_dprint.cc;h=79d182c1052aa237995b4b25b7091d99b66a6f3e;hb=c84c6db5d56829d69083c819688a973867694a2a;hp=8159e32318dd7c323d2f39b6a67baa73a300e3b6;hpb=dd9e0f894eec7e2a8cf85078330ddc0a6639090b;p=cln.git diff --git a/src/float/output/cl_F_dprint.cc b/src/float/output/cl_F_dprint.cc index 8159e32..79d182c 100644 --- a/src/float/output/cl_F_dprint.cc +++ b/src/float/output/cl_F_dprint.cc @@ -4,7 +4,7 @@ #include "cl_sysdep.h" // Specification. -#include "cl_float_io.h" +#include "cln/float_io.h" // Implementation. @@ -30,18 +30,20 @@ CL_REQUIRE(cl_F_ln2_var) CL_REQUIRE(cl_F_ln10_var) -#include -#include "cl_output.h" +#include +#include "cln/output.h" #include "cl_sstring.h" -#include "cl_float.h" +#include "cln/float.h" #include "cl_F.h" #include "cl_LF.h" #include "cl_F_tran.h" -#include "cl_rational.h" -#include "cl_integer.h" -#include "cl_integer_io.h" +#include "cln/rational.h" +#include "cln/integer.h" +#include "cln/integer_io.h" #include "cl_I.h" +namespace cln { + // Hauptfunktion zur Umwandlung von Floats ins Dezimalsystem: // Zu einem Float x werden ein String as und drei Integers k,e,s // berechnet mit folgenden Eigenschaften: @@ -78,7 +80,7 @@ static const cl_decimal_decoded_float decode_float_decimal (const cl_F& x) // x/=0, also ist sign das Vorzeichen von x und // |x| = 2^binexpo * float(binmant,x) . Ab jetzt oBdA x>0. // Also x = 2^binexpo * float(binmant,x) . - var uintL l = integer_length(binmant); // Anzahl der Bits von binmant, >=3 + var uintC l = integer_length(binmant); // Anzahl der Bits von binmant, >=3 var cl_I binmant2 = ash(binmant,1); // 2*binmant var cl_I oben = plus1(binmant2); // obere Intervallgrenze ist // (x+x2)/2 = 2^(binexpo-1) * oben @@ -99,7 +101,7 @@ static const cl_decimal_decoded_float decode_float_decimal (const cl_F& x) // Wandle dazu 2^e := 2^(binexpo-1) ins Dezimalsystem um. var cl_I e = binexpo - 1; var bool e_gross = (abs(e) > ash(l,1)); // Ist |e| recht groß, >2*l ? - var uintL g; // Hilfsvariablen für den Fall, daß |e| groß ist + var uintC g; // Hilfsvariablen für den Fall, daß |e| groß ist var cl_I f; // var cl_I zehn_d; // Hilfsvariable 10^|d| für den Fall, daß |e| klein ist var cl_I d; // Ergebnisvariablen @@ -144,7 +146,7 @@ static const cl_decimal_decoded_float decode_float_decimal (const cl_F& x) // e*log(2)-d*log(10) nötig. Dazu mit l'=integerlength(e) // für log(2): g+7+l' Bits abs. Gen., g+7+l' Bits rel. Gen., // für log(10): g+7+l' Bits abs. Gen., g+7+l'+2 Bist rel. Gen. - var cl_float_format_t gen = (cl_float_format_t)(g + integer_length(e) + 9); // Genauigkeit + var float_format_t gen = (float_format_t)(g + integer_length(e) + 9); // Genauigkeit var cl_F f2g = exp(The(cl_F)(e * cl_ln2(gen)) - The(cl_F)(d * cl_ln10(gen))); // f/2^g // Das so berechnete f/2^g ist >1, <100. // Mit 2^g multiplizieren und auf eine ganze Zahl runden: @@ -315,7 +317,7 @@ static const cl_decimal_decoded_float decode_float_decimal (const cl_F& x) // Nun a in einen Dezimalstring umwandeln // und dann Nullen am Schluß streichen: var char* as = cl_decimal_string(a); // Ziffernfolge zu a>0 - var uintL las = strlen(as); // Länge der Ziffernfolge + var uintL las = ::strlen(as); // Länge der Ziffernfolge var uintL k = las; // Länge ohne die gestrichenen Nullen am Schluß var cl_I ee = k+d; // a * 10^d = a * 10^(-k+ee) while (as[k-1] == '0') // eine 0 am Schluß? @@ -353,13 +355,13 @@ static const cl_decimal_decoded_float decode_float_decimal (const cl_F& x) } } var char* as = cl_decimal_string(a); // Ziffernfolge zu a>0 - var uintL k = strlen(as); + var uintL k = ::strlen(as); ASSERT(as[k-1] != '0'); return cl_decimal_decoded_float(as,k,k+d,sign); } // Ausgabefunktion: -void print_float (cl_ostream stream, const cl_print_float_flags& flags, const cl_F& z) +void print_float (std::ostream& stream, const cl_print_float_flags& flags, const cl_F& z) { var cl_decimal_decoded_float z_decoded = decode_float_decimal(z); var char * & mantstring = z_decoded.a; @@ -388,13 +390,13 @@ void print_float (cl_ostream stream, const cl_print_float_flags& flags, const cl // erst Null und Punkt, dann -expo Nullen, dann alle Ziffern fprintchar(stream,'0'); fprintchar(stream,'.'); - for (uintL i = -FN_to_L(expo); i > 0; i--) + for (uintV i = -FN_to_V(expo); i > 0; i--) fprintchar(stream,'0'); fprint(stream,mantstring); expo = 0; // auszugebender Exponent ist 0 } else { // "fixed-point notation" mit expo > 0 oder "scientific notation" - var uintL scale = (flag ? FN_to_L(expo) : 1); + var uintV scale = (flag ? FN_to_V(expo) : 1); // Der Dezimalpunkt wird um scale Stellen nach rechts geschoben, // d.h. es gibt scale Vorkommastellen. scale > 0. if (scale < mantlen) { @@ -410,7 +412,7 @@ void print_float (cl_ostream stream, const cl_print_float_flags& flags, const cl // scale>=mantlen -> es bleibt nichts für die Nachkommastellen. // alle Ziffern, dann scale-mantlen Nullen, dann Punkt und Null fprint(stream,mantstring); - for (uintL i = mantlen; i < scale; i++) + for (uintV i = mantlen; i < scale; i++) fprintchar(stream,'0'); fprintchar(stream,'.'); fprintchar(stream,'0'); @@ -438,5 +440,7 @@ void print_float (cl_ostream stream, const cl_print_float_flags& flags, const cl print_integer(stream,10,expo); } // Fertig. Aufräumen. - cl_free_hook(mantstring); + free_hook(mantstring); } + +} // namespace cln