Use std::iostream functions instead of EOF and cl_EOF macros.
This enables us to get rid of the freadchar and funreadchar functions.
While at it, removed the extra signatures introduced for CLN-1.2.0
compatibilty. After all, the soname has been bumped.
Also updated largest known Mersenne prime in examples/perfnum.cc.
-ABI Issues:
-
-Remove extra signatures in cl_FF_from_float.cc, cl_DF_from_double.cc,
-cl_F_readparsed.cc, cl_I_readparsed.cc, and cl_RA_readparsed.cc.
-
-
Algorithms:
Niels Moeller's subquadratic GCD
@node Input functions
@section Input functions
-Including @code{<cln/io.h>} defines a number of simple input functions
-that read from @code{std::istream&}:
-
-@table @code
-@item int freadchar (std::istream& stream)
-Reads a character from @code{stream}. Returns @code{cl_EOF} (not a @samp{char}!)
-if the end of stream was encountered or an error occurred.
-
-@item int funreadchar (std::istream& stream, int c)
-Puts back @code{c} onto @code{stream}. @code{c} must be the result of the
-last @code{freadchar} operation on @code{stream}.
-@end table
-
-Each of the classes @code{cl_N}, @code{cl_R}, @code{cl_RA}, @code{cl_I},
-@code{cl_F}, @code{cl_SF}, @code{cl_FF}, @code{cl_DF}, @code{cl_LF}
-defines, in @code{<cln/@var{type}_io.h>}, the following input function:
-
-@table @code
-@item std::istream& operator>> (std::istream& stream, @var{type}& result)
-Reads a number from @code{stream} and stores it in the @code{result}.
-@end table
-
-The most flexible input functions, defined in @code{<cln/@var{type}_io.h>},
-are the following:
+Including @code{<cln/io.h>} defines flexible input functions:
@table @code
@item cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
int main ()
{
- // previous ones were 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583, 25964951, 30402457
- int p = 32582657;
+ // previous ones were 1257787, 1398269, 2976221, 3021377, 6972593,
+ // 13466917, 20996011, 24036583, 25964951, 30402457, 32582657, 37156667
+ int p = 43112609;
cl_I x = (((cl_I)1 << p) - 1) << (p-1);
cout << x << endl;
}
extern std::ostream* cl_debugout_stream;
#define cl_debugout (*cl_debugout_stream)
-// Elementary operations on std::istream&
-
-#define cl_EOF (-1)
-
-inline int freadchar (std::istream& stream)
-{
- char c;
- if (stream.get(c))
- return c;
- else
- // EOF or error
- return cl_EOF;
-}
-
-inline int funreadchar (std::istream& stream, int c)
-{
- if (c != cl_EOF)
- stream.putback((char)c);
- return c;
-}
-
// Elementary operations on std::ostream&
inline void fprintchar (std::ostream& stream, char c)
const cl_string cl_fget (std::istream& stream, char delim)
{
var cl_spushstring buffer;
- // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
+ // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) {
var int c = stream.get();
- if (c==EOF)
- break; // std::ios::eofbit already set
+ if (stream.eof())
+ break;
if (c==delim) {
stream.unget();
break;
const cl_string cl_fget (std::istream& stream, int n, char delim)
{
var cl_spushstring buffer;
- // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
+ // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) {
var int c = stream.get();
- if (c==EOF)
- break; // ios::eofbit already set
+ if (stream.eof())
+ break;
if (c==delim) {
stream.unget();
break;
const cl_string cl_fgetline (std::istream& stream, char delim)
{
var cl_spushstring buffer;
- // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
+ // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) {
var int c = stream.get();
- if (c==EOF)
- break; // std::ios::eofbit already set
+ if (stream.eof())
+ break;
if (c==delim)
break;
buffer.push(c);
const cl_string cl_fgetline (std::istream& stream, int n, char delim)
{
var cl_spushstring buffer;
- // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
+ // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) {
var int c = stream.get();
- if (c==EOF)
- break; // std::ios::eofbit already set
+ if (stream.eof())
+ break;
if (c==delim)
break;
if (--n <= 0) {
{
var cl_spushstring buffer;
var int n = stream.width();
- // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
+ // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
int c;
// Skip whitespace.
while (stream.good()) {
c = stream.get();
- if (c==EOF)
+ if (stream.eof())
break;
if (!isspace(c)) {
if (--n == 0) {
// Read non-whitespace.
while (stream.good()) {
c = stream.get();
- if (c==EOF)
+ if (stream.eof())
break;
if (isspace(c)) {
stream.unget();
var int c;
// Skip whitespace at the beginning.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n'))
continue;
else
buffer.push(c);
// Read some digits, then a letter, then a list or token.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
buffer.push(c);
if ((c >= '0') && (c <= '9'))
continue;
}
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1;
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
if (c == '(') {
var uintL paren_level = 0;
loop {
if (c == '(') paren_level++;
else if (c == ')') paren_level--;
if (paren_level == 0) goto done;
- c = freadchar(stream);
- if ((c == cl_EOF) || (c == '\n')) goto syntax;
+ c = stream.get();
+ if (stream.eof() || stream.fail() || c == '\n') goto syntax;
}
}
}
goto syntax1;
loop {
buffer.push(c);
- c = freadchar(stream);
- if (c == cl_EOF)
+ c = stream.get();
+ if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
- funreadchar(stream,c);
+ stream.putback(c);
break;
}
}
namespace cln {
-cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val_)
-{
- // XXX: This signature is for binary compatibility with CLN-1.2.0 only.
- return cl_double_to_DF_pointer(*(double *)(&val_));
-}
-
cl_heap_dfloat* cl_double_to_DF_pointer (const double x)
{
var union { dfloat eksplicit; double machine_double; } u;
// Implementation.
-cl_private_thing cl_float_to_FF_pointer (const ffloatjanus& val_)
-{
- // XXX: This signature is for binary compatibility with CLN-1.2.0 only.
- return cl_float_to_FF_pointer(*(float *)(&val_));
-}
-
cl_private_thing cl_float_to_FF_pointer (const float x)
{
var union { ffloat eksplicit; float machine_float; } u;
var int c;
// Skip whitespace at the beginning.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n'))
continue;
else
buffer.push(c);
// Read some digits, then a letter, then a token.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
buffer.push(c);
if ((c >= '0') && (c <= '9'))
continue;
}
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1;
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
}
// Read a number token.
if (!number_char_p(c))
goto syntax1;
loop {
buffer.push(c);
- c = freadchar(stream);
- if (c == cl_EOF)
+ c = stream.get();
+ if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
- funreadchar(stream,c);
+ stream.putback(c);
break;
}
}
namespace cln {
-#if intCsize > intLsize
-const cl_F read_float (unsigned int base, float_format_t prec, cl_signean sign, const char * string, uintL index1, uintL index4, uintL index2, uintL index3)
-{
- // XXX: This signature is for binary compatibility with CLN-1.2.0 only.
- return read_float(base, prec, sign, string, uintC(index1), uintC(index4), uintC(index2), uintC(index3));
-}
-#endif
-
const cl_F read_float (unsigned int base, float_format_t prec, cl_signean sign, const char * string, uintC index1, uintC index4, uintC index2, uintC index3)
{
var cl_I exponent;
var int c;
// Skip whitespace at the beginning.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n'))
continue;
else
buffer.push(c);
// Read some digits, then a letter, then a token.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
buffer.push(c);
if ((c >= '0') && (c <= '9'))
continue;
}
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1;
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
}
// Read a number token.
if (!number_char_p(c))
goto syntax1;
loop {
buffer.push(c);
- c = freadchar(stream);
- if (c == cl_EOF)
+ c = stream.get();
+ if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
- funreadchar(stream,c);
+ stream.putback(c);
break;
}
}
namespace cln {
-#if intCsize > intLsize
-const cl_I read_integer (unsigned int base, cl_signean sign, const char* string, uintL index1, uintL index2)
-{
- // XXX: This signature is for binary compatibility with CLN-1.2.0 only.
- return read_integer(base, sign, string, uintC(index1), uintC(index2));
-}
-#endif
-
const cl_I read_integer (unsigned int base, cl_signean sign, const char * string, uintC index1, uintC index2)
{
var cl_I x = digits_to_I(&string[index1],index2-index1,(uintD)base);
var int c;
// Skip whitespace at the beginning.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n'))
continue;
else
buffer.push(c);
// Read some digits, then a letter, then a token.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
buffer.push(c);
if ((c >= '0') && (c <= '9'))
continue;
}
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1;
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
}
// Read a number token.
if (!number_char_p(c))
goto syntax1;
loop {
buffer.push(c);
- c = freadchar(stream);
- if (c == cl_EOF)
+ c = stream.get();
+ if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
- funreadchar(stream,c);
+ stream.putback(c);
break;
}
}
namespace cln {
-#if intCsize > intLsize
-const cl_RA read_rational (unsigned int base, cl_signean sign, const char * string, uintL index1, uintL index3, uintL index2)
-{
- // XXX: This signature is for binary compatibility with CLN-1.2.0 only.
- return read_rational(base, sign, string, uintC(index1), uintC(index3), uintC(index2));
-}
-#endif
-
const cl_RA read_rational (unsigned int base, cl_signean sign, const char * string, uintC index1, uintC index3, uintC index2)
{
var uintC index3_1 = index3+1; // Index der ersten Nennerziffer
var int c;
// Skip whitespace at the beginning.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n'))
continue;
else
buffer.push(c);
// Read some digits, then a letter, then a token.
loop {
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
buffer.push(c);
if ((c >= '0') && (c <= '9'))
continue;
}
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1;
- c = freadchar(stream);
- if (c == cl_EOF) goto eof;
+ c = stream.get();
+ if (stream.eof() || stream.fail()) goto eof;
}
// Read a number token.
if (!number_char_p(c))
goto syntax1;
loop {
buffer.push(c);
- c = freadchar(stream);
- if (c == cl_EOF)
+ c = stream.get();
+ if (stream.eof() || stream.fail())
break;
if (!number_char_p(c)) {
- funreadchar(stream,c);
+ stream.putback(c);
break;
}
}