Use std::cin, std::cout, std::cerr instead (obsoletes 2000-10-29).
if (argc < 1)
exit(1);
- fprint(stderr, "Number of repetitions: ");
- fprintdecimal(stderr, repetitions);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Number of repetitions: ");
+ fprintdecimal(std::cerr, repetitions);
+ fprint(std::cerr, "\n");
float_format_t prec = float_format(1000);
- fprint(stderr, "pi\n");
+ fprint(std::cerr, "pi\n");
{ cl_F p;
{ CL_TIMING; p = pi(prec); }
{ CL_TIMING;
cout << p << endl << endl;
}
- fprint(stderr, "gamma\n");
+ fprint(std::cerr, "gamma\n");
{ cl_F p;
{ CL_TIMING; p = eulerconst(prec); }
{ CL_TIMING;
cout << p << endl << endl;
}
- fprint(stderr, "e\n");
+ fprint(std::cerr, "e\n");
{ cl_F p = exp1(prec);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "sqrt(3)\n");
+ fprint(std::cerr, "sqrt(3)\n");
{ cl_R p = sqrt(cl_float(3,prec));
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "exp(log(2))\n");
+ fprint(std::cerr, "exp(log(2))\n");
{ cl_N p = exp(log(cl_float(2,prec)));
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "log(exp(2))\n");
+ fprint(std::cerr, "log(exp(2))\n");
{ cl_N p = log(exp(cl_float(2,prec)));
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "sin(pi/3)\n");
+ fprint(std::cerr, "sin(pi/3)\n");
{ cl_R p = sin(pi(prec)/3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "cos(pi/3)\n");
+ fprint(std::cerr, "cos(pi/3)\n");
{ cl_R p = cos(pi(prec)/3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "arcsin(sqrt(3)/2)\n");
+ fprint(std::cerr, "arcsin(sqrt(3)/2)\n");
{ cl_N p = asin(sqrt(cl_float(3,prec))/2);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "arccos(sqrt(3)/2)\n");
+ fprint(std::cerr, "arccos(sqrt(3)/2)\n");
{ cl_N p = acos(sqrt(cl_float(3,prec))/2);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "sinh(log(2))\n");
+ fprint(std::cerr, "sinh(log(2))\n");
{ cl_N p = sinh(log(cl_float(2,prec)));
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "cosh(log(2))\n");
+ fprint(std::cerr, "cosh(log(2))\n");
{ cl_N p = cosh(log(cl_float(2,prec)));
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "arsinh(pi)\n");
+ fprint(std::cerr, "arsinh(pi)\n");
{ cl_N p = asinh(pi(prec));
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << p << endl << endl;
}
- fprint(stderr, "arcosh(pi)\n");
+ fprint(std::cerr, "arcosh(pi)\n");
{ cl_N p = acosh(pi(prec));
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
if (argc < 1)
exit(1);
- stderr << "Number of digits: " << digits << endl;
- stderr << "Number of repetitions: " << repetitions << endl;
+ cerr << "Number of digits: " << digits << endl;
+ cerr << "Number of repetitions: " << repetitions << endl;
float_format_t prec = float_format(digits);
float_format_t prec2 = float_format(digits*2);
cl_I x2 = floor1(sqrt(cl_float(3,prec)) * pow);
cl_I x3 = pow+1;
- stderr << "multiplication" << endl;
+ cerr << "multiplication" << endl;
{ cl_I r = x1*x2;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "division" << endl;
+ cerr << "division" << endl;
{ cl_I_div_t qr = floor2(x1,x2);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << qr.quotient << endl << qr.remainder << endl << endl;
}
- stderr << "isqrt" << endl;
+ cerr << "isqrt" << endl;
{ cl_I r = isqrt(x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "gcd" << endl;
+ cerr << "gcd" << endl;
{ cl_I r = gcd(x1,x2);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
if (argc < 1)
exit(1);
- stderr << "Limit: " << limit << endl;
- stderr << "Number of repetitions: " << repetitions << endl;
+ cerr << "Limit: " << limit << endl;
+ cerr << "Number of repetitions: " << repetitions << endl;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
if (argc < 1)
exit(1);
- stderr << "Number of digits: " << digits << endl;
- stderr << "Number of repetitions (except for pi,euler,e): " << repetitions << endl;
+ cerr << "Number of digits: " << digits << endl;
+ cerr << "Number of repetitions (except for pi,euler,e): " << repetitions << endl;
float_format_t prec = float_format(digits);
cl_F x1 = sqrt(cl_float(2,prec));
cl_F x2 = sqrt(cl_float(3,prec));
cl_F x3 = The(cl_F)(log(cl_float(2,prec)));
- stderr << "multiplication" << endl;
+ cerr << "multiplication" << endl;
{ cl_F r = x1*x2;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "sqrt" << endl;
+ cerr << "sqrt" << endl;
{ cl_F r = sqrt(x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "pi" << endl;
+ cerr << "pi" << endl;
{ cl_F r;
{ CL_TIMING; r = pi(prec); }
cout << r << endl << endl;
}
- stderr << "eulerconst" << endl;
+ cerr << "eulerconst" << endl;
{ cl_F r;
{ CL_TIMING; r = eulerconst(prec); }
cout << r << endl << endl;
}
- stderr << "e" << endl;
+ cerr << "e" << endl;
{ cl_F r;
{ CL_TIMING; r = exp1(prec); }
cout << r << endl << endl;
}
- stderr << "exp" << endl;
+ cerr << "exp" << endl;
{ cl_F r = exp(-x1);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "log" << endl;
+ cerr << "log" << endl;
{ cl_N r = log(x2);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "sin" << endl;
+ cerr << "sin" << endl;
{ cl_R r = sin(5*x1);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "cos" << endl;
+ cerr << "cos" << endl;
{ cl_R r = cos(5*x1);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "asin" << endl;
+ cerr << "asin" << endl;
{ cl_N r = asin(x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "acos" << endl;
+ cerr << "acos" << endl;
{ cl_N r = acos(x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "atan" << endl;
+ cerr << "atan" << endl;
{ cl_F r = atan(x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "sinh" << endl;
+ cerr << "sinh" << endl;
{ cl_F r = sinh(x2);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "cosh" << endl;
+ cerr << "cosh" << endl;
{ cl_F r = cosh(x2);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "asinh" << endl;
+ cerr << "asinh" << endl;
{ cl_N r = asinh(x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "acosh" << endl;
+ cerr << "acosh" << endl;
{ cl_N r = acosh(1+x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
cout << r << endl << endl;
}
- stderr << "atanh" << endl;
+ cerr << "atanh" << endl;
{ cl_N r = atanh(x3);
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
are coprime integers and the denominator is positive. If the resulting
denominator is @code{1}, the rational number is converted to an integer.
-Small integers (typically in the range @code{-2^30}@dots{}@code{2^30-1},
+@cindex immediate numbers
+Small integers (typically in the range @code{-2^29}@dots{}@code{2^29-1},
for 32-bit machines) are especially efficient, because they consume no heap
allocation. Otherwise the distinction between these immediate integers
(called ``fixnums'') and heap allocated integers (called ``bignums'')
the type of the first argument to all input functions. @code{cl_istream}
is the same as @code{std::istream&}.
-The variable
-@itemize @asis
-@item
-@code{cl_istream stdin}
-@end itemize
-contains the standard input stream.
-
These are the simple input functions:
@table @code
the type of the first argument to all output functions. @code{cl_ostream}
is the same as @code{std::ostream&}.
-The variable
-@itemize @asis
-@item
-@code{cl_ostream stdout}
-@end itemize
-contains the standard output stream.
-
-The variable
-@itemize @asis
-@item
-@code{cl_ostream stderr}
-@end itemize
-contains the standard error output stream.
-
These are the simple output functions:
@table @code
number object's storage is freed immediately when the last reference to the
object is gone.
@item
+@cindex immediate numbers
Small integers are represented as immediate values instead of pointers
to heap allocated storage. This means that integers @code{> -2^29},
@code{< 2^29} don't consume heap memory, unless they were explicitly allocated
#include <cln/io.h>
#include <cln/integer_io.h>
+using namespace std;
using namespace cln;
// Our private error handling: return to the main program.
cl_R x = arg;
// Check sign.
if (minusp(x)) {
- stdout << '-';
+ cout << '-';
x = -x;
}
- fprint(stdout, "[");
+ cout << "[";
const char* separator = "; ";
for (;;) {
// Split x into integral and fractional part.
cl_R_div_t x_split = floor2(x);
- stdout << x_split.quotient;
+ cout << x_split.quotient;
x = x_split.remainder;
if (zerop(x))
break;
- stdout << separator;
+ cout << separator;
separator = ", ";
// Invert x.
x = recip(x);
}
- stdout << ']' << std::endl;
+ cout << ']' << endl;
}
}
int main (int argc, char* argv[])
{
if (argc != 2) {
- stderr << "Usage: fibonacci n" << endl;
+ cerr << "Usage: fibonacci n" << endl;
return(1);
}
int n = atoi(argv[1]);
- stdout << "fib(" << n << ") = " << fibonacci(n) << endl;
+ cout << "fib(" << n << ") = " << fibonacci(n) << endl;
return(0);
}
argc -= 2; argv += 2;
}
if (argc != 2) {
- stderr << "Usage: fibonacci n" << endl;
+ cerr << "Usage: fibonacci n" << endl;
return(1);
}
int n = atoi(argv[1]);
{ CL_TIMING;
- stdout << "fib(" << n << ") = ";
+ cout << "fib(" << n << ") = ";
for (int rep = repetitions-1; rep > 0; rep--)
fibonacci(n);
- stdout << fibonacci(n) << endl;
+ cout << fibonacci(n) << endl;
}
{ CL_TIMING;
- stdout << "fib(" << n << ") = ";
+ cout << "fib(" << n << ") = ";
for (int rep = repetitions-1; rep > 0; rep--)
fibonacci_compact(n);
- stdout << fibonacci_compact(n) << endl;
+ cout << fibonacci_compact(n) << endl;
}
{ CL_TIMING;
- stdout << "fib(" << n << ") = ";
+ cout << "fib(" << n << ") = ";
for (int rep = repetitions-1; rep > 0; rep--)
fibonacci_slow(n);
- stdout << fibonacci_slow(n) << endl;
+ cout << fibonacci_slow(n) << endl;
}
return(0);
}
#include <cln/io.h>
#include <stdlib.h>
+using namespace std;
using namespace cln;
// Computes the n-th Legendre polynomial in R[x], using the formula
int main (int argc, char* argv[])
{
if (!(argc == 2 || argc == 3)) {
- fprint(stderr, "Usage: legendre n [m]\n");
+ cerr << "Usage: legendre n [m]" << endl;
exit(1);
}
int n = atoi(argv[1]);
if (!(n >= 0)) {
- fprint(stderr, "Usage: legendre n [m] with n >= 0\n");
+ cerr << "Usage: legendre n [m] with n >= 0" << endl;
exit(1);
}
if (argc == 2) {
cl_UP p = legendre(cl_RA_ring,n);
- fprint(stdout, p);
+ cout << p << endl;
} else {
cl_I m = argv[2];
cl_UP p = legendre(find_modint_ring(m),n);
- fprint(stdout, p);
+ cout << p << endl;
}
- fprint(stdout, "\n");
+ return 0;
}
int main (int argc, char* argv[])
{
if (argc != 2) {
- cln::stderr << "Usage: nextprime x" << std::endl;
+ std::cerr << "Usage: nextprime x" << std::endl;
return(1);
}
cln::cl_R x = (cln::cl_R)argv[1];
cln::cl_I p = cln::nextprobprime(x);
- cln::stdout << p << std::endl;
+ std::cout << p << std::endl;
return(0);
}
-// I/O through <stdio.h> or <iostream>
+// I/O through <iostream>
#ifndef _CL_IO_H
#define _CL_IO_H
typedef std::istream& cl_istream;
typedef std::ostream& cl_ostream;
-extern cl_istream stdin;
-extern cl_ostream stdout;
-extern cl_ostream stderr;
extern std::ostream* cl_debugout_stream;
#define cl_debugout (*cl_debugout_stream)
// Constructors.
cl_composite_condition (const cl_I& _p)
: p (_p), factor (0)
- { print(stderr); }
+ { print(std::cerr); }
cl_composite_condition (const cl_I& _p, const cl_I& _f)
: p (_p), factor (_f)
- { print(stderr); }
+ { print(std::cerr); }
// Implement general condition methods.
const char * name () const;
void print (cl_ostream) const;
#define cl_class_flags_subclass_rational 8 // all instances belong to cl_RA
#define cl_class_flags_number_ring 16 // all instances are rings whose
// elements belong to cl_number
-// Function to print an object for debugging, to stderr.
+// Function to print an object for debugging, to cerr.
typedef void (*cl_heap_dprint_function) (cl_heap* pointer);
struct cl_class {
struct cl_timing {
// Constructor, starts the time interval.
cl_timing (cl_time_consumption& accumulator);
- cl_timing (cl_ostream destination = stderr);
- cl_timing (const char *, cl_ostream destination = stderr);
+ cl_timing (cl_ostream destination = std::cerr);
+ cl_timing (const char *, cl_ostream destination = std::cerr);
// Destructor, closes the time interval and does a report.
~cl_timing ();
//private:
// Usage:
// { CL_TIMING; computation(); }
// or { CL_TIMING(accumulator); computation(); }
-// or { CL_TIMING(stdout); computation(); }
+// or { CL_TIMING(cout); computation(); }
// The timing interval starts immediately and ends at the closing brace.
#define CL_TIMING CL_TIMING1(__LINE__)
#define CL_TIMING1(line) CL_TIMING2(line)
void cl_error_division_by_0 (void)
{
- fprint(stderr, "Division by zero.\n");
+ fprint(std::cerr, "Division by zero.\n");
cl_abort();
}
void cl_as_error (const cl_number& obj, const char * typestring, const char * filename, int line)
{
- fprint(stderr, "Type assertion failed: in file ");
- fprint(stderr, filename);
- fprint(stderr, ", line ");
- fprintdecimal(stderr, line);
- fprint(stderr, ", not ");
- fprint(stderr, typestring);
- fprint(stderr, ": ");
+ fprint(std::cerr, "Type assertion failed: in file ");
+ fprint(std::cerr, filename);
+ fprint(std::cerr, ", line ");
+ fprintdecimal(std::cerr, line);
+ fprint(std::cerr, ", not ");
+ fprint(std::cerr, typestring);
+ fprint(std::cerr, ": ");
#if 0 // This brings in a dependency from the complex and float printer and all the float stuff.
- fprint(stderr, obj);
+ fprint(std::cerr, obj);
#else
- fprint(stderr, "@0x");
- fprinthexadecimal(stderr, (unsigned long)(void*)&obj);
- fprint(stderr, ": 0x");
- fprinthexadecimal(stderr, (unsigned long)obj.word);
+ fprint(std::cerr, "@0x");
+ fprinthexadecimal(std::cerr, (unsigned long)(void*)&obj);
+ fprint(std::cerr, ": 0x");
+ fprinthexadecimal(std::cerr, (unsigned long)obj.word);
#endif
- fprint(stderr, "\n");
+ fprint(std::cerr, "\n");
cl_abort();
}
// Implementation.
// Just assume that the debugger runs on /dev/tty, independently of
-// stdin, stdout, stderr.
+// cin, cout, cerr.
#include <fstream>
void* ptr = malloc(size);
if (ptr)
return ptr;
- fprint(stderr, "Out of virtual memory.\n");
+ fprint(std::cerr, "Out of virtual memory.\n");
cl_abort();
}
void cl_notreached_abort (const char* filename, int lineno)
{
- fprint(stderr, "Internal error: statement in file ");
- fprint(stderr, filename);
- fprint(stderr, ", line ");
- fprintdecimal(stderr, lineno);
- fprint(stderr, " has been reached!!\n");
- fprint(stderr, "Please send the authors of the program a description how you produced this error!\n");
+ fprint(std::cerr, "Internal error: statement in file ");
+ fprint(std::cerr, filename);
+ fprint(std::cerr, ", line ");
+ fprintdecimal(std::cerr, lineno);
+ fprint(std::cerr, " has been reached!!\n");
+ fprint(std::cerr, "Please send the authors of the program a description how you produced this error!\n");
cl_abort();
}
if (max_l(2) > intDsize && l > intDsize) {
// l > intDsize
if (max_l(2) > 64 && l > 64) {
- fprint(stderr, "FFT problem: l > 64 not supported by pow2_table\n");
+ fprint(std::cerr, "FFT problem: l > 64 not supported by pow2_table\n");
cl_abort();
}
var fftc_real carry = 0;
for ( ; ; k++) {
if (k >= sizeof(max_l_table)/sizeof(max_l_table[0])
|| max_l_table[k] <= 0) {
- fprint(stderr, "FFT problem: numbers too big, floating point precision not sufficient\n");
+ fprint(std::cerr, "FFT problem: numbers too big, floating point precision not sufficient\n");
cl_abort();
}
if (2*ceiling((uintL)len1*intDsize,max_l_table[k])-1 <= ((uintL)1 << k))
var uintD checksum = multiply_checksum(checksum1,checksum2);
mulu_fftcomplex_nocheck(sourceptr1,len1,sourceptr2,len2,destptr);
if (!(checksum == compute_checksum(destptr,len1+len2))) {
- fprint(stderr, "FFT problem: checksum error\n");
+ fprint(std::cerr, "FFT problem: checksum error\n");
cl_abort();
}
}
if (max_l(2) > intDsize && l > intDsize) {
// l > intDsize
if (max_l(2) > 64 && l > 64) {
- fprint(stderr, "FFT problem: l > 64 not supported by pow2_table\n");
+ fprint(std::cerr, "FFT problem: l > 64 not supported by pow2_table\n");
cl_abort();
}
var fftcs_real carry = 0;
for ( ; ; k++) {
if (k >= sizeof(max_l_table)/sizeof(max_l_table[0])
|| max_l_table[k] <= 0) {
- fprint(stderr, "FFT problem: numbers too big, floating point precision not sufficient\n");
+ fprint(std::cerr, "FFT problem: numbers too big, floating point precision not sufficient\n");
cl_abort();
}
if (2*ceiling((uintL)len1*intDsize,max_l_table[k])-1 <= ((uintL)1 << k))
var uintD checksum = multiply_checksum(checksum1,checksum2);
mulu_fftcs_nocheck(sourceptr1,len1,sourceptr2,len2,destptr);
if (!(checksum == compute_checksum(destptr,len1+len2))) {
- fprint(stderr, "FFT problem: checksum error\n");
+ fprint(std::cerr, "FFT problem: checksum error\n");
cl_abort();
}
}
if (max_l(2) > intDsize && l > intDsize) {
// l > intDsize
if (max_l(2) > 64 && l > 64) {
- fprint(stderr, "FFT problem: l > 64 not supported by pow2_table\n");
+ fprint(std::cerr, "FFT problem: l > 64 not supported by pow2_table\n");
cl_abort();
}
var fftr_real carry = 0;
for ( ; ; k++) {
if (k >= sizeof(max_l_table)/sizeof(max_l_table[0])
|| max_l_table[k] <= 0) {
- fprint(stderr, "FFT problem: numbers too big, floating point precision not sufficient\n");
+ fprint(std::cerr, "FFT problem: numbers too big, floating point precision not sufficient\n");
cl_abort();
}
if (2*ceiling((uintL)len1*intDsize,max_l_table[k])-1 <= ((uintL)1 << k))
var uintD checksum = multiply_checksum(checksum1,checksum2);
mulu_fftr_nocheck(sourceptr1,len1,sourceptr2,len2,destptr);
if (!(checksum == compute_checksum(destptr,len1+len2))) {
- fprint(stderr, "FFT problem: checksum error\n");
+ fprint(std::cerr, "FFT problem: checksum error\n");
cl_abort();
}
}
void read_number_bad_syntax (const char * string, const char * string_limit)
{
- fprint(stderr, "Illegal number syntax: \"");
+ fprint(std::cerr, "Illegal number syntax: \"");
for (const char * ptr = string; ptr != string_limit; ptr++)
- fprintchar(stderr, *ptr);
- fprint(stderr, "\"\n");
+ fprintchar(std::cerr, *ptr);
+ fprint(std::cerr, "\"\n");
cl_abort();
}
void read_number_eof (void)
{
- fprint(stderr, "read_number: end of stream encountered\n");
+ fprint(std::cerr, "read_number: end of stream encountered\n");
cl_abort();
}
void read_number_junk (const char * string_rest, const char * string, const char * string_limit)
{
- fprint(stderr, "Junk after number: ");
+ fprint(std::cerr, "Junk after number: ");
{ for (const char * ptr = string; ptr != string_rest; ptr++)
- fprintchar(stderr, *ptr);
+ fprintchar(std::cerr, *ptr);
}
- fprint(stderr, "\"");
+ fprint(std::cerr, "\"");
{ for (const char * ptr = string_rest; ptr != string_limit; ptr++)
- fprintchar(stderr, *ptr);
+ fprintchar(std::cerr, *ptr);
}
- fprint(stderr, "\"\n");
+ fprint(std::cerr, "\"\n");
cl_abort();
}
+++ /dev/null
-// Global variables in CLN
-
-// Specification.
-#include "cln/io.h"
-
-// Implementation.
-
-namespace cln {
-
-cl_istream stdin = std::cin;
-
-} // namespace cln
namespace cln {
-cl_ostream stdout = std::cout;
-cl_ostream stderr = std::cerr;
-
cl_print_flags default_print_flags;
#if 0 // The default constructors already do this.
AT_INITIALIZATION(default_print_flags)
nonreturning_function(static, uninitialized_ring, (void));
static void uninitialized_ring ()
{
- fprint(stderr, "Uninitialized ring operation called\n");
+ fprint(std::cerr, "Uninitialized ring operation called\n");
cl_abort();
}
nonreturning_function(static, uninitialized_error, (const _cl_ring_element&));
static void uninitialized_error (const _cl_ring_element& obj)
{
- fprint(stderr, "Uninitialized ring element @0x");
- fprinthexadecimal(stderr, (unsigned long)(void*)&obj);
- fprint(stderr, ": 0x");
- fprinthexadecimal(stderr, (unsigned long)obj.rep.word);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Uninitialized ring element @0x");
+ fprinthexadecimal(std::cerr, (unsigned long)(void*)&obj);
+ fprint(std::cerr, ": 0x");
+ fprinthexadecimal(std::cerr, (unsigned long)obj.rep.word);
+ fprint(std::cerr, "\n");
cl_abort();
}
#undef floor
#include <cmath>
#define floor cln_floor
-// Ugh, some compilers #define stderr, confusing cln::stderr
-#ifdef stderr
- #undef stderr
-#endif
namespace cln {
goto not_rational_syntax;
var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr);
if (!((base >= 2) && (base <= 36))) {
- fprint(stderr, "Base must be an integer in the range from 2 to 36, not ");
- fprint(stderr, base);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Base must be an integer in the range from 2 to 36, not ");
+ fprint(std::cerr, base);
+ fprint(std::cerr, "\n");
cl_abort();
}
rational_base = FN_to_UL(base); ptr = base_end_ptr;
void cl_error_floating_point_nan (void)
{
- fprint(stderr, "floating point NaN occurred.\n");
+ fprint(std::cerr, "floating point NaN occurred.\n");
cl_abort();
}
void cl_error_floating_point_overflow (void)
{
- fprint(stderr, "Floating point overflow.\n");
+ fprint(std::cerr, "Floating point overflow.\n");
cl_abort();
}
void cl_error_floating_point_underflow (void)
{
- fprint(stderr, "Floating point underflow.\n");
+ fprint(std::cerr, "Floating point underflow.\n");
cl_abort();
}
cl_boolean isqrt (const cl_I& x, cl_I* w)
{
if (minusp(x)) {
- fprint(stderr, "isqrt: applied to negative number: ");
- fprint(stderr, x);
- fprint(stderr, "\n");
+ fprint(std::cerr, "isqrt: applied to negative number: ");
+ fprint(std::cerr, x);
+ fprint(std::cerr, "\n");
cl_abort();
}
CL_ALLOCA_STACK;
void cl_ash_error (const cl_I& badamount)
{
- fprint(stderr, "ash: too large shift amount: ");
- fprint(stderr, badamount);
- fprint(stderr, "\n");
+ fprint(std::cerr, "ash: too large shift amount: ");
+ fprint(std::cerr, badamount);
+ fprint(std::cerr, "\n");
cl_abort();
}
}
else
// x<0
- { fprint(stderr, "logbitp: Index is negative: ");
- fprint(stderr, x);
- fprint(stderr, "\n");
+ { fprint(std::cerr, "logbitp: Index is negative: ");
+ fprint(std::cerr, x);
+ fprint(std::cerr, "\n");
cl_abort();
}
}
#undef IF_LENGTH
}
bad: // unpassendes Objekt
- fprint(stderr, "Not a 32-bit integer: ");
- fprint(stderr, obj);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Not a 32-bit integer: ");
+ fprint(std::cerr, obj);
+ fprint(std::cerr, "\n");
cl_abort();
}
}
#undef IF_LENGTH
}
bad: // unpassendes Objekt
- fprint(stderr, "Not a 64-bit integer: ");
- fprint(stderr, obj);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Not a 64-bit integer: ");
+ fprint(std::cerr, obj);
+ fprint(std::cerr, "\n");
cl_abort();
}
}
#undef IF_LENGTH
}
bad: // unpassendes Objekt
- fprint(stderr, "Not a 32-bit integer: ");
- fprint(stderr, obj);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Not a 32-bit integer: ");
+ fprint(std::cerr, obj);
+ fprint(std::cerr, "\n");
cl_abort();
}
#undef IF_LENGTH
}
bad: // unpassendes Objekt
- fprint(stderr, "Not a 64-bit integer: ");
- fprint(stderr, obj);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Not a 64-bit integer: ");
+ fprint(std::cerr, obj);
+ fprint(std::cerr, "\n");
cl_abort();
}
void cl_error_exquo (const cl_I& x, const cl_I& y)
{
- fprint(stderr, "Quotient ");
- fprint(stderr, x);
- fprint(stderr, " / ");
- fprint(stderr, y);
- fprint(stderr, " is not an integer.\n");
+ fprint(std::cerr, "Quotient ");
+ fprint(std::cerr, x);
+ fprint(std::cerr, " / ");
+ fprint(std::cerr, y);
+ fprint(std::cerr, " is not an integer.\n");
cl_abort();
}
goto not_integer_syntax;
var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr);
if (!((base >= 2) && (base <= 36))) {
- fprint(stderr, "Base must be an integer in the range from 2 to 36, not ");
- fprint(stderr, base);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Base must be an integer in the range from 2 to 36, not ");
+ fprint(std::cerr, base);
+ fprint(std::cerr, "\n");
cl_abort();
}
rational_base = FN_to_UL(base); ptr = base_end_ptr;
{
unused R;
unused randomstate;
- fprint(stderr, "Z / 0 Z not a finite set - no equidistributed random function.\n");
+ fprint(std::cerr, "Z / 0 Z not a finite set - no equidistributed random function.\n");
cl_abort();
#if ((defined(__sparc__) || defined(__sparc64__)) && !defined(__GNUC__)) // Sun CC wants a return value
return _cl_MI(R, 0);
nonreturning_function(static, uninitialized_ring, (void));
static void uninitialized_ring ()
{
- fprint(stderr, "Uninitialized ring operation called\n");
+ fprint(std::cerr, "Uninitialized ring operation called\n");
cl_abort();
}
nonreturning_function(static, uninitialized_error, (const _cl_UP&));
static void uninitialized_error (const _cl_UP& obj)
{
- fprint(stderr, "Uninitialized ring element @0x");
- fprinthexadecimal(stderr, (unsigned long)(void*)&obj);
- fprint(stderr, ": 0x");
- fprinthexadecimal(stderr, (unsigned long)obj.rep.word);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Uninitialized ring element @0x");
+ fprinthexadecimal(std::cerr, (unsigned long)(void*)&obj);
+ fprint(std::cerr, ": 0x");
+ fprinthexadecimal(std::cerr, (unsigned long)obj.rep.word);
+ fprint(std::cerr, "\n");
cl_abort();
}
goto not_rational_syntax;
var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr);
if (!((base >= 2) && (base <= 36))) {
- fprint(stderr, "Base must be an integer in the range from 2 to 36, not ");
- fprint(stderr, base);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Base must be an integer in the range from 2 to 36, not ");
+ fprint(std::cerr, base);
+ fprint(std::cerr, "\n");
cl_abort();
}
rational_base = FN_to_UL(base); ptr = base_end_ptr;
var uintL * small_piece_ptr = &small_pieces[0];
do {
if (*illion_ptr == NULL) {
- fprint(stderr, "format_cardinal: argument too large: ");
- fprint(stderr, argument);
- fprint(stderr, "\n");
+ fprint(std::cerr, "format_cardinal: argument too large: ");
+ fprint(std::cerr, argument);
+ fprint(std::cerr, "\n");
cl_abort();
}
var cl_I_div_t div = floor2(arg,1000);
void format_new_roman (cl_ostream stream, const cl_I& arg)
{
if (!(0 < arg && arg < 4000)) {
- fprint(stderr, "format_new_roman: argument should be in the range 1 - 3999, not ");
- fprint(stderr, arg);
- fprint(stderr, ".\n");
+ fprint(std::cerr, "format_new_roman: argument should be in the range 1 - 3999, not ");
+ fprint(std::cerr, arg);
+ fprint(std::cerr, ".\n");
cl_abort();
}
var uintL value = cl_I_to_UL(arg);
void format_old_roman (cl_ostream stream, const cl_I& arg)
{
if (!(0 < arg && arg < 5000)) {
- fprint(stderr, "format_old_roman: argument should be in the range 1 - 4999, not ");
- fprint(stderr, arg);
- fprint(stderr, ".\n");
+ fprint(std::cerr, "format_old_roman: argument should be in the range 1 - 4999, not ");
+ fprint(std::cerr, arg);
+ fprint(std::cerr, ".\n");
cl_abort();
}
var uintL value = cl_I_to_UL(arg);
#undef floor
#include <cmath>
#define floor cln_floor
-// Ugh, some compilers #define stderr, confusing cln::stderr
-#ifdef stderr
- #undef stderr
-#endif
namespace cln {
goto not_rational_syntax;
var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr);
if (!((base >= 2) && (base <= 36))) {
- fprint(stderr, "Base must be an integer in the range from 2 to 36, not ");
- fprint(stderr, base);
- fprint(stderr, "\n");
+ fprint(std::cerr, "Base must be an integer in the range from 2 to 36, not ");
+ fprint(std::cerr, base);
+ fprint(std::cerr, "\n");
cl_abort();
}
rational_base = FN_to_UL(base); ptr = base_end_ptr;
}
}
}
- fprint(stderr, "random: argument should be positive and an integer or float: ");
- fprint(stderr, n);
- fprint(stderr, "\n");
+ fprint(std::cerr, "random: argument should be positive and an integer or float: ");
+ fprint(std::cerr, n);
+ fprint(std::cerr, "\n");
cl_abort();
}
rtype computed_result = arg1 op arg2; \
rtype result = rtype(test.result); \
if (computed_result != result) { \
- stderr << "Error in " #typename "_" #opname "_tests[" << i << "] !" << endl; \
- stderr << "Result should be: " << result << endl; \
- stderr << "Result computed : " << computed_result << endl << endl; \
+ std::cerr << "Error in " #typename "_" #opname "_tests[" << i << "] !" << endl; \
+ std::cerr << "Result should be: " << result << endl; \
+ std::cerr << "Result computed : " << computed_result << endl << endl; \
error = 1; \
} \
} \
cl_I result1 = cl_I(test.result1); \
type result2 = type(test.result2); \
if ((computed_result.quotient != result1) || (computed_result.remainder != result2)) { \
- stderr << "Error in " #typename "_floor_tests[" << i << endl; \
- stderr << "Results should be: " << result1 << ", " << result2 << endl; \
- stderr << "Results computed : " << computed_result.quotient << ", " << computed_result.remainder << endl << endl; \
+ std::cerr << "Error in " #typename "_floor_tests[" << i << endl; \
+ std::cerr << "Results should be: " << result1 << ", " << result2 << endl; \
+ std::cerr << "Results computed : " << computed_result.quotient << ", " << computed_result.remainder << endl << endl; \
error = 1; \
} \
} \
#define ASSERT(expr) \
if (!(expr)) { \
- stderr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
+ std::cerr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
error = 1; \
}
rtype computed_result = opname(arg1,arg2); \
rtype result = rtype(test.result); \
if (computed_result != result) { \
- stderr << "Error in " #typename "_" #opname "_tests[" << i << "] !" << endl; \
- stderr << "Result should be: " << result << endl; \
- stderr << "Result computed : " << computed_result << endl << endl; \
+ std::cerr << "Error in " #typename "_" #opname "_tests[" << i << "] !" << endl; \
+ std::cerr << "Result should be: " << result << endl; \
+ std::cerr << "Result computed : " << computed_result << endl << endl; \
error = 1; \
} \
} \
#include <cln/timing.h>
#define DUMP(expr) \
- fprint(stdout, #expr" = "); fprint(stdout, expr); fprint(stdout, "\n");
+ fprint(cout, #expr" = "); fprint(cout, expr); fprint(cout, "\n");
int main (int argc, char* argv[])
{
#if 0
cl_F archimedes = pi((float_format_t)10000);
- fprint(stdout, archimedes);
- fprint(stdout, "\n");
+ fprint(cout, archimedes);
+ fprint(cout, "\n");
#endif
#if 0
cl_FF x1 = "-0.2173f0";
cl_FF x2 = "5.5084f9";
cl_FF y = "-1.19698f9";
- fprint(stdout, "x1 = "); print_float_binary(stdout,x1); fprint(stdout, " = "); fprint(stdout,x1); fprint(stdout, "\n");
- fprint(stdout, "x2 = "); print_float_binary(stdout,x2); fprint(stdout, " = "); fprint(stdout,x2); fprint(stdout, "\n");
- fprint(stdout, "y = "); print_float_binary(stdout,y); fprint(stdout, " = "); fprint(stdout,y); fprint(stdout, "\n");
+ fprint(cout, "x1 = "); print_float_binary(cout,x1); fprint(cout, " = "); fprint(cout,x1); fprint(cout, "\n");
+ fprint(cout, "x2 = "); print_float_binary(cout,x2); fprint(cout, " = "); fprint(cout,x2); fprint(cout, "\n");
+ fprint(cout, "y = "); print_float_binary(cout,y); fprint(cout, " = "); fprint(cout,y); fprint(cout, "\n");
cl_FF x = x1*x2;
- fprint(stdout, "x1*x2 = "); print_float_binary(stdout,x); fprint(stdout, " = "); fprint(stdout,x); fprint(stdout, "\n");
+ fprint(cout, "x1*x2 = "); print_float_binary(cout,x); fprint(cout, " = "); fprint(cout,x); fprint(cout, "\n");
#endif
#if 0
cl_I y = ++x;
x *= 2;
x++;
- fprint(stdout, "x = "); fprint(stdout, x); fprint(stdout, "\n");
- fprint(stdout, "y = "); fprint(stdout, y); fprint(stdout, "\n");
+ fprint(cout, "x = "); fprint(cout, x); fprint(cout, "\n");
+ fprint(cout, "y = "); fprint(cout, y); fprint(cout, "\n");
#endif
#if 0
#define ASSERT(expr) \
if (!(expr)) { \
- stderr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
+ std::cerr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
error = 1; \
}
#define ASSERT1(expr,a) \
if (!(expr)) { \
- stderr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
- stderr << #a" = " << a << endl; \
+ std::cerr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
+ std::cerr << #a" = " << a << endl; \
error = 1; \
}
#define ASSERT2(expr,a,b) \
if (!(expr)) { \
- stderr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
- stderr << #a" = " << a << endl; \
- stderr << #b" = " << b << endl; \
+ std::cerr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
+ std::cerr << #a" = " << a << endl; \
+ std::cerr << #b" = " << b << endl; \
error = 1; \
}
#define ASSERT3(expr,a,b,c) \
if (!(expr)) { \
- stderr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
- stderr << #a" = " << a << endl; \
- stderr << #b" = " << b << endl; \
- stderr << #c" = " << c << endl; \
+ std::cerr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
+ std::cerr << #a" = " << a << endl; \
+ std::cerr << #b" = " << b << endl; \
+ std::cerr << #c" = " << c << endl; \
error = 1; \
}
#define ASSERT4(expr,a,b,c,d) \
if (!(expr)) { \
- stderr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
- stderr << #a" = " << a << endl; \
- stderr << #b" = " << b << endl; \
- stderr << #c" = " << c << endl; \
- stderr << #d" = " << d << endl; \
+ std::cerr << "Assertion failed! File " << __FILE__ << ", line " << __LINE__ << endl; \
+ std::cerr << #a" = " << a << endl; \
+ std::cerr << #b" = " << b << endl; \
+ std::cerr << #c" = " << c << endl; \
+ std::cerr << #d" = " << d << endl; \
error = 1; \
}
{
cl_MI a = R->canonhom("1111111111111111111111111111111111111111111111111");
cl_MI b = R->canonhom("777777777777777777777777777777777777777777777777");
- stdout << "product modulo p" << endl;
+ cout << "product modulo p" << endl;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_MI c = R->mul(a,b); }
}
- stdout << "square modulo p" << endl;
+ cout << "square modulo p" << endl;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_MI c = R->square(a); }
}
- stdout << "quotient modulo p" << endl;
+ cout << "quotient modulo p" << endl;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_MI c = R->div(a,b); }
{
cl_MI a = R->canonhom("1234567890123456789012345678901234567890123456789");
cl_MI b = R->canonhom("909090909090909090909090909090909090909090909090");
- stdout << "product modulo p" << endl;
+ cout << "product modulo p" << endl;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_MI c = R->mul(a,b); }
}
- stdout << "square modulo p" << endl;
+ cout << "square modulo p" << endl;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_MI c = R->square(a); }
}
- stdout << "quotient modulo p" << endl;
+ cout << "quotient modulo p" << endl;
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_MI c = R->div(a,b); }
p1.set_coeff(i, R1->canonhom((int)(1.618033989*i*i)));
p1.finalize();
- stdout << p1 << endl;
+ cout << p1 << endl;
cl_UP sp1 = PR1->zero();
{ CL_TIMING;
{ sp1 = square(p1); }
}
- stdout << sp1 << endl;
+ cout << sp1 << endl;
}
// Time:
int n = atoi(argv[1]);
float_format_t prec = float_format(n);
cl_F p;
- stderr << "Computing pi" << endl;
+ cerr << "Computing pi" << endl;
{ CL_TIMING; p = pi(prec); }
- stderr << "Converting pi to decimal" << endl;
+ cerr << "Converting pi to decimal" << endl;
{ CL_TIMING; cout << p << endl << endl; }
#endif
}
cl_I M2 = (cl_I)1 << (intDsize*m2);
cl_I a = random_I(M1);
cl_I b = random_I(M2);
- fprint(stderr, "Squaring: ");
+ fprint(std::cerr, "Squaring: ");
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_I p = a * a; }
}
- fprint(stderr, "Multiplication: ");
+ fprint(std::cerr, "Multiplication: ");
{ CL_TIMING;
for (int rep = repetitions; rep > 0; rep--)
{ cl_I p = a * b; }