#include "cl_sysdep.h"
// Specification.
-#include "cl_float_io.h"
+#include "cln/float_io.h"
// Implementation.
CL_REQUIRE(cl_F_ln2_var)
CL_REQUIRE(cl_F_ln10_var)
-#include <string.h>
-#include "cl_output.h"
+#include <cstring>
+#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:
// 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
// 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
// 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:
// 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ß?
}
}
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;
// 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) {
// 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');
print_integer(stream,10,expo);
}
// Fertig. Aufräumen.
- cl_free_hook(mantstring);
+ free_hook(mantstring);
}
+
+} // namespace cln