diff --git a/ChangeLog b/ChangeLog index 6f29f9b..1efc991 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,215 @@ +2007-07-28 Richard B. Kreckel <kreckel@ginac.de> + + Remove exception hooks in favor of real C++ exceptions: + * include/cln/exception.h: New file... + * include/cln/cln.h: ...included here... + * include/cln/rational.h: ...and here. + * include/cln/abort.h: Removed. + * include/cln/integer.h (ash_exception, exquo_exception): Add exception + types. + * include/cln/float.h (floating_point_exception, + floating_point_nan_exception, floating_point_overflow_exception, + floating_point_underflow_exception): Likewise. + * include/cln/number_io.h (read_number_exception, + read_number_bad_syntax_exception, read_number_junk_exception, + read_number_eof_exception): Likewise. + * include/cln/object.h (CL_DEFINE_CONVERTER): Replace dynamic assertion + with a compile-time assertion. + * include/cln/GV.h: Replace nonreturning functions with exceptions. + * include/cln/modinteger.h: Likewise. + * include/cln/SV.h: Likewise. + * include/cln/ring.h: Likewise. + * include/cln/string.h: Likewise. + * include/cln/univpoly.h: Likewise. + * src/base/cl_abort.cc: Removed. + * src/base/cl_N_err_d0.cc: Removed. + * src/base/cl_d0_exception.cc: New file. + * src/base/cl_as_err.cc: Removed. + * src/base/cl_as_exception.cc: New file. + * src/base/cl_notreached.cc: Removed. + * src/base/cl_notreached_exception.cc: New file. + * src/base/input/cl_read_err_bad.cc: Removed. + * src/base/input/cl_read_bad_syntax_exception.cc: New file. + * src/base/input/cl_read_err_junk.cc: Removed. + * src/base/input/cl_read_junk_exception.cc: New file. + * src/base/input/cl_read_err_eof.cc: Removed. + * src/base/input/cl_read_eof_exception.cc: New file. + * src/base/cl_N.h (cl_as_error): Removed (see cln/exception.h). + * src/base/macros.h (NOTREACHED): Throw. + * src/base/cl_malloc.cc (xmalloc): Throw. + * src/base/digitseq/cl_2DS_div.cc: Throw. + * src/base/digitseq/cl_DS_div.cc: Throw. + * src/base/digitseq/cl_DS_mul.cc: Throw. + * src/base/digitseq/cl_DS_mul_fftc.h: Throw. + * src/base/digitseq/cl_DS_mul_fftcs.h: Throw. + * src/base/digitseq/cl_DS_mul_fftm.h: Throw. + * src/base/digitseq/cl_DS_mul_fftp.h: Throw. + * src/base/digitseq/cl_DS_mul_fftp3.h: Throw. + * src/base/digitseq/cl_DS_mul_fftp3m.h: Throw. + * src/base/digitseq/cl_DS_mul_fftr.h: Throw. + * src/base/digitseq/cl_DS_mul_nuss.h: Throw. + * src/base/digitseq/cl_DS_recipsqrt.cc: Throw. + * src/base/digitseq/cl_DS_sqrt.cc: Throw. + * src/base/hash/cl_hash.h: Throw. + * src/base/hash/cl_hash1.h: Throw. + * src/base/hash/cl_hash1weak.h: Throw. + * src/base/hash/cl_hash2.h: Throw. + * src/base/hash/cl_hash2weak.h: Throw. + * src/base/hash/cl_hashset.h: Throw. + * src/base/hash/cl_hashuniq.h: Throw. + * src/base/hash/cl_hashuniqweak.h: Throw. + * src/base/proplist/cl_pl_add.cc: Throw. + * src/base/ring/cl_no_ring.cc: Throw. + * src/base/string/cl_spushstring.h: Throw. + * src/base/symbol/cl_symbol.cc: Throw. + * src/integer/bitwise/cl_I_ash.h: Removed (see cln/integer.h.) + * src/integer/bitwise/cl_I_asherr.cc: Removed. + * src/integer/bitwise/cl_I_ash_exception.cc: New file. + * src/integer/division/cl_I_exquoerr.cc: Removed. + * src/integer/division/cl_I_exquo_exception.cc: New file. + * src/integer/cl_I.h: Throw. + * src/integer/division/cl_I_exquopos.cc: Throw. + * src/integer/bitwise/cl_I_logbitp_I.cc: Throw. + * src/integer/bitwise/cl_I_ash.cc: Throw. + * src/integer/bitwise/cl_I_ash_I.cc: Throw. + * src/integer/division/cl_I_exquo.cc: Throw. + * src/integer/gcd/cl_I_gcd_aux2.cc: Throw. + * src/integer/conv/cl_I_to_L.cc: Throw. + * src/integer/conv/cl_I_to_Q.cc: Throw. + * src/integer/conv/cl_I_to_UL.cc: Throw. + * src/integer/conv/cl_I_to_UQ.cc: Throw. + * src/integer/conv/cl_I_to_digits.cc: Throw. + * src/integer/elem/cl_I_div.cc: Throw. + * src/integer/algebraic/cl_I_sqrt.cc: Throw. + * src/integer/input/cl_I_read.cc: Throw. + * src/integer/input/cl_I_read_stream.cc: Throw. + * src/integer/misc/cl_I_as.cc: Throw. + * src/rational/elem/cl_RA_from_I_I_div.cc: Throw. + * src/rational/elem/cl_RA_recip.cc: Throw. + * src/rational/input/cl_RA_read.cc: Throw. + * src/rational/input/cl_RA_read_stream.cc: Throw. + * src/rational/input/cl_RA_readparsed.cc: Throw. + * src/rational/misc/cl_RA_as.cc: Throw. + * src/float/base/cl_F_err_nan.cc: Removed. + * src/float/base/cl_F_nan_exception.cc: New file. + * src/float/base/cl_F_err_un.cc: Removed. + * src/float/base/cl_F_underflow_exception.cc: New file. + * src/float/base/cl_F_err_ov.cc: Removed. + * src/float/base/cl_F_overflow_exception.cc: New file. + * src/float/cl_F.h (cl_error_floating_point_nan, + cl_error_floating_point_overflow, cl_error_floating_point_underflow): + Removed (see cln/float.h.) + * src/float/sfloat/cl_SF.h: Throw. + * src/float/sfloat/elem/cl_SF_div.cc: Throw. + * src/float/sfloat/elem/cl_SF_from_RA.cc: Throw. + * src/float/sfloat/elem/cl_SF_scale.cc: Throw. + * src/float/sfloat/elem/cl_SF_scale_I.cc: Throw. + * src/float/sfloat/misc/cl_SF_as.cc: Throw. + * src/float/ffloat/cl_FF.h: Throw. + * src/float/ffloat/conv/cl_FF_from_float.cc: Throw. + * src/float/ffloat/elem/cl_FF_div.cc: Throw. + * src/float/ffloat/elem/cl_FF_from_RA.cc: Throw. + * src/float/ffloat/elem/cl_FF_scale.cc: Throw. + * src/float/ffloat/elem/cl_FF_scale_I.cc: Throw. + * src/float/ffloat/misc/cl_FF_as.cc: Throw. + * src/float/dfloat/cl_DF.h: Throw. + * src/float/dfloat/conv/cl_DF_from_double.cc: Throw. + * src/float/dfloat/elem/cl_DF_div.cc: Throw. + * src/float/dfloat/elem/cl_DF_from_RA.cc: Throw. + * src/float/dfloat/elem/cl_DF_scale.cc: Throw. + * src/float/dfloat/elem/cl_DF_scale_I.cc: Throw. + * src/float/dfloat/misc/cl_DF_as.cc: Throw. + * src/float/lfloat/algebraic/cl_LF_sqrt.cc: Throw. + * src/float/lfloat/elem/cl_LF_1plus.cc: Throw. + * src/float/lfloat/elem/cl_LF_I_div.cc: Throw. + * src/float/lfloat/elem/cl_LF_I_mul.cc: Throw. + * src/float/lfloat/elem/cl_LF_div.cc: Throw. + * src/float/lfloat/elem/cl_LF_from_I.cc: Throw. + * src/float/lfloat/elem/cl_LF_mul.cc: Throw. + * src/float/lfloat/elem/cl_LF_scale.cc: Throw. + * src/float/lfloat/elem/cl_LF_scale_I.cc: Throw. + * src/float/lfloat/elem/cl_LF_square.cc: Throw. + * src/float/lfloat/misc/cl_LF_as.cc: Throw. + * src/float/lfloat/misc/cl_LF_shorten.cc: Throw. + * src/float/lfloat/misc/cl_LF_shortenrel.cc: Throw. + * src/float/lfloat/misc/cl_LF_shortenwith.cc: Throw. + * src/float/input/cl_F_read.cc: Throw. + * src/float/input/cl_F_read_stream.cc: Throw. + * src/float/misc/cl_F_as.cc: Throw. + * src/float/misc/cl_F_shortenrel.cc: Throw. + * src/float/transcendental/cl_LF_coshsinh_aux.cc: Throw. + * src/float/transcendental/cl_LF_cossin_aux.cc: Throw. + * src/float/transcendental/cl_LF_exp_aux.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_a.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_ab.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_b.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_p.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_pa.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_pab.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_pb.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_pq.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_pqa.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_pqab.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_pqb.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_q.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_qa.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_qab.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_qb.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_stream_pq.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_stream_pqa.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_stream_pqab.cc: Throw. + * src/float/transcendental/cl_LF_ratseries_stream_pqb.cc: Throw. + * src/float/transcendental/cl_LF_ratsumseries_pqcd_aux.cc: Throw. + * src/float/transcendental/cl_LF_ratsumseries_pqd.cc: Throw. + * src/float/transcendental/cl_LF_ratsumseries_pqd_aux.cc: Throw. + * src/float/transcendental/cl_LF_zeta_int.cc: Throw. + * src/real/elem/cl_R_div.cc: Throw. + * src/real/format-output/cl_fmt_cardinal.cc: Throw. + * src/real/format-output/cl_fmt_newroman.cc: Throw. + * src/real/format-output/cl_fmt_oldroman.cc: Throw. + * src/real/input/cl_R_read.cc: Throw. + * src/real/input/cl_R_read_stream.cc: Throw. + * src/real/misc/cl_R_as.cc: Throw. + * src/real/random/cl_R_random.cc: Throw. + * src/real/transcendental/cl_R_atan2.cc: Throw. + * src/real/transcendental/cl_R_log.cc: Throw. + * src/complex/input/cl_N_read.cc: Throw. + * src/complex/input/cl_N_read_stream.cc: Throw. + * src/complex/misc/cl_N_as.cc: Throw. + * src/complex/transcendental/cl_C_atanh_aux.cc: Throw. + * src/complex/transcendental/cl_C_expt_C.cc: Throw. + * src/complex/transcendental/cl_C_log.cc: Throw. + * src/complex/transcendental/cl_C_log2.cc: Throw. + * src/numtheory/cl_nt_cornacchia1.cc: Throw. + * src/numtheory/cl_nt_cornacchia4.cc: Throw. + * src/numtheory/cl_nt_isprobprime.cc: Throw. + * src/numtheory/cl_nt_jacobi.cc: Throw. + * src/numtheory/cl_nt_jacobi_low.cc: Throw. + * src/numtheory/cl_nt_sqrtmodp.cc: Throw. + * src/modinteger/cl_MI.cc: Throw. + * src/modinteger/cl_MI_int.h: Throw. + * src/modinteger/cl_MI_montgom.h: Throw. + * src/modinteger/cl_MI_pow2.h: Throw. + * src/modinteger/cl_MI_rshift.cc: Throw. + * src/modinteger/cl_MI_std.h: Throw. + * src/polynomial/elem/cl_UP_GF2.h: Throw. + * src/polynomial/elem/cl_UP_MI.h: Throw. + * src/polynomial/elem/cl_UP_gen.h: Throw. + * src/polynomial/elem/cl_UP_named.cc: Throw. + * src/polynomial/elem/cl_UP_no_ring.cc (uninitialized_error, + uninitialized_ring): Removed (see cln/ring.h.) + * src/polynomial/elem/cl_UP_number.h: Throw. + * src/polynomial/elem/cl_UP_unnamed.cc: Throw. + * src/vector/cl_GV_I.cc: Throw. + * src/vector/cl_GV_number.cc: Throw. + * tests/timediv2adic-compare.cc: Use default abort(), not cl_abort(). + * tests/timeprint-compare.cc: Likewise. + * tests/timerecip2adic-compare.cc: Likewise. + * doc/cln.tex: Document the exception classes. + * examples/contfrac.cc: Use try/catch instead of setjmp/longjmp. + * INSTALL: undocument -fno-exceptions. + * README: Add exceptions to list of used C++ features. + 2007-06-20 Richard B. Kreckel <kreckel@ginac.de> * cln.spec.in (Source0): Package is bzip2-compressed. diff --git a/INSTALL b/INSTALL index 68ce910..42477cd 100644 --- a/INSTALL +++ b/INSTALL @@ -26,17 +26,10 @@ Known to work with: The "make" step takes about 30 minutes, on a P-III / 1 GHz / 512 MB. -If you use g++ from gcc-3.x, I recommend adding "-fno-exceptions" to the -CXXFLAGS. This will likely generate better code. - If you use g++ from gcc-3.0.4 or older on Sparc, add either "-O", "-O1" or "-O2 -fno-schedule-insns" to the CXXFLAGS. With full "-O2", g++ miscompiles the division routines. Do not use gcc-3.0 on Sparc for compiling CLN, it won't work at all. -If you use g++ on OSF/1 or Tru64 using gcc-3.0.n with n larger than 1, you -should not add -fno-exceptions to the CXXFLAGS, since that will generate -wrong code (gcc-3.1 is okay again, as is gcc-3.0). - More detailed installation instructions can be found in the documentation, in the doc/ directory. diff --git a/NEWS b/NEWS index 036535c..7732c2d 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,11 @@ -2006-mm-dd, version 1.2.0 +2007-mm-dd, version 1.2.0 ========================= Implementation changes ---------------------- * Added support for huge numbers... +* CLN now uses C++ exceptions for error handling. * Dropped the cln-config script. Please use pkg-config instead. diff --git a/README b/README index 2f23d0f..018972d 100644 --- a/README +++ b/README @@ -25,14 +25,14 @@ Features: - Interoperability: - Garbage collection with no burden on the main application, - - hooks for memory allocation and exceptions. + - hooks for memory allocation. Requires: C++ compiler g++. The following C++ features are used: classes, member functions, overloading of functions and operators, constructors and destructors, inline, const, multiple inheritance, -templates and namespaces. +templates, namespaces, and exceptions. The following C++ features are not used: -new, delete, virtual inheritance, exceptions. +new, delete, virtual inheritance. Homepage: <http://www.ginac.de/CLN> diff --git a/doc/cln.tex b/doc/cln.tex index 197e900..8e42b1e 100644 --- a/doc/cln.tex +++ b/doc/cln.tex @@ -3,13 +3,9 @@ @setfilename cln.info @settitle CLN, a Class Library for Numbers @c @setchapternewpage off -@c For `info' only. -@paragraphindent 0 -@c For TeX only. -@iftex @c I hate putting "@noindent" in front of every paragraph. -@parindent=0pt -@end iftex +@c For `info' and TeX only. +@paragraphindent 0 @c %**end of header @direntry @@ -228,7 +224,8 @@ CLN aims at being easily integrated into larger software packages: @item The garbage collection imposes no burden on the main application. @item -The library provides hooks for memory allocation and exceptions. +The library provides hooks for memory allocation and throws exceptions +in case of errors. @item @cindex namespace All non-macro identifiers are hidden in namespace @code{cln} in @@ -246,7 +243,7 @@ This section describes how to install the CLN package on your system. @subsection C++ compiler To build CLN, you need a C++ compiler. -Actually, you need GNU @code{g++ 2.95} or newer. +Actually, you need GNU @code{g++ 3.0.0} or newer. The following C++ features are used: classes, member functions, overloading of functions and operators, @@ -254,7 +251,7 @@ constructors and destructors, inline, const, multiple inheritance, templates and namespaces. The following C++ features are not used: -@code{new}, @code{delete}, virtual inheritance, exceptions. +@code{new}, @code{delete}, virtual inheritance. CLN relies on semi-automatic ordering of initializations of static and global variables, a feature which I could implement for GNU g++ @@ -325,13 +322,10 @@ Examples: @example $ CC="gcc" CFLAGS="-O" CXX="g++" CXXFLAGS="-O" ./configure -$ CC="gcc -V egcs-2.91.60" CFLAGS="-O -g" \ - CXX="g++ -V egcs-2.91.60" CXXFLAGS="-O -g" ./configure -$ CC="gcc -V 2.95.2" CFLAGS="-O2 -fno-exceptions" \ - CXX="g++ -V 2.95.2" CFLAGS="-O2 -fno-exceptions" ./configure -$ CC="gcc -V 3.0.4" CFLAGS="-O2 -finline-limit=1000 -fno-exceptions" \ - CXX="g++ -V 3.0.4" CFLAGS="-O2 -finline-limit=1000 -fno-exceptions" \ +$ CC="gcc -V 3.0.4" CFLAGS="-O2 -finline-limit=1000" \ + CXX="g++ -V 3.0.4" CXXFLAGS="-O2 -finline-limit=1000" \ ./configure +$ CC="gcc-4.1" CFLAGS="-O2" CXX="g++-4.1" CXXFLAGS="-O2" ./configure @end example Note that for these environment variables to take effect, you have to set @@ -348,24 +342,12 @@ or no CXXFLAGS at all. (If CXXFLAGS is not set, CLN will use @code{-O}.) If you use @code{g++} 3.x, I recommend adding @samp{-finline-limit=1000} to the CXXFLAGS. This is essential for good code. -If you use @code{g++} gcc-2.95.x or gcc-3.x, I recommend adding -@samp{-fno-exceptions} to the CXXFLAGS. This will likely generate better code. - If you use @code{g++} from gcc-3.0.4 or older on Sparc, add either @samp{-O}, @samp{-O1} or @samp{-O2 -fno-schedule-insns} to the CXXFLAGS. With full @samp{-O2}, @code{g++} miscompiles the division -routines. If you use @code{g++} older than 2.95.3 on Sparc you should -also specify @samp{--disable-shared} because of bad code produced in the -shared library. Also, do not use gcc-3.0 on Sparc for compiling CLN, it +routines. Also, do not use gcc-3.0 on Sparc for compiling CLN, it won't work at all. -If you use @code{g++} on OSF/1 or Tru64 using gcc-2.95.x, you should -specify @samp{--disable-shared} because of linker problems with -duplicate symbols in shared libraries. If you use @code{g++} from -gcc-3.0.n, with n larger than 1, you should @emph{not} add -@samp{-fno-exceptions} to the CXXFLAGS, since that will generate wrong -code (gcc-3.1 is okay again, as is gcc-3.0). - Also, please do not compile CLN with @code{g++} using the @code{-O3} optimization level. This leads to inferior code quality. @@ -401,7 +383,7 @@ some place where your compiler cannot find it by default, you must help an example: @example -$ CC="gcc" CFLAGS="-O2" CXX="g++" CXXFLAGS="-O2 -fno-exceptions" \ +$ CC="gcc" CFLAGS="-O2" CXX="g++" CXXFLAGS="-O2" \ CPPFLAGS="-I/opt/gmp/include" LDFLAGS="-L/opt/gmp/lib" ./configure --with-gmp @end example @@ -2461,7 +2443,7 @@ affect the input syntax. The string starts at @code{string} and ends at @code{NULL}, denoting the entire string, i.e. equivalent to @code{string_limit = string + strlen(string)}. If @code{end_of_parse} is @code{NULL}, the string in memory must contain exactly one number and nothing -more, else a fatal error will be signalled. If @code{end_of_parse} +more, else an exception will be thrown. If @code{end_of_parse} is not @code{NULL}, @code{*end_of_parse} will be assigned a pointer past the last parsed character (i.e. @code{string_limit} if nothing came after the number). Whitespace is not allowed. @@ -3451,10 +3433,10 @@ Flags for customizing input operations. Flags for customizing output operations. @item <cln/malloc.h> @code{malloc_hook}, @code{free_hook}. -@item <cln/abort.h> -@code{cl_abort}. +@item <cln/exception.h> +Exception base class. @item <cln/condition.h> -Conditions/exceptions. +Conditions. @item <cln/string.h> Strings. @item <cln/symbol.h> @@ -3604,17 +3586,22 @@ available from the library: @itemize @bullet @item The library does type checks, range checks, consistency checks at -many places. When one of these fails, the function @code{cl_abort()} is -called. Its default implementation is to perform an @code{exit(1)}, so -you won't have a core dump. But for debugging, it is best to set a -breakpoint at this function: +many places. When one of these fails, an exception of a type derived from +@code{runtime_exception} is thrown. When an exception is cought, the stack +has already been unwound, so it is may not be possible to tell at which +point the exception was thrown. For debugging, it is best to set up a +catchpoint at the event of throwning a C++ exception: @example -(gdb) break cl_abort +(gdb) catch throw @end example -When this breakpoint is hit, look at the stack's backtrace: +When this catchpoint is hit, look at the stack's backtrace: @example (gdb) where @end example +When control over the type of exception is required, it may be possible +to set a breakpoint at the @code{g++} runtime library function +@code{__raise_exception}. Refer to the documentation of GNU @code{gdb} +for details. @item The debugger's normal @code{print} command doesn't know about CLN's types and therefore prints mostly useless hexadecimal addresses. @@ -3666,32 +3653,54 @@ Unfortunately, this feature does not seem to work under all circumstances. @cindex customizing @section Error handling +@cindex Exception +@cindex Error handling + +@cindex @code{runtime_exception} +CLN signals abnormal situations by throwning exceptions. All exceptions +thrown by the library are of type @code{runtime_exception} or of a +derived type. Class @code{cln::runtime_exception} in turn is derived +from the C++ standard library class @code{std::runtime_error} and +inherits the @code{.what()} member function that can be used to query +details about the cause of error. -When a fatal error occurs, an error message is output to the standard error -output stream, and the function @code{cl_abort} is called. The default -version of this function (provided in the library) terminates the application. -To catch such a fatal error, you need to define the function @code{cl_abort} -yourself, with the prototype +The most important classes thrown by the library are + +@cindex @code{floating_point_exception} +@cindex @code{read_number_exception} @example -#include <cln/abort.h> -void cl_abort (void); + Exception base class + runtime_exception + <cln/exception.h> + | + +----------------+----------------+ + | | + Malformed number input Floating-point error + read_number_exception floating_poing_exception + <cln/number_io.h> <cln/float.h> @end example -@cindex @code{cl_abort ()} -This function must not return control to its caller. + +CLN has many more exception classes that allow for more fine-grained +control but I refrain from documenting them all here. They are all +declared in the public header files and they are all subclasses of the +above exceptions, so catching those you are always on the safe side. @section Floating-point underflow @cindex underflow -Floating point underflow denotes the situation when a floating-point number -is to be created which is so close to @code{0} that its exponent is too -low to be represented internally. By default, this causes a fatal error. -If you set the global variable +@cindex @code{floating_point_underflow_exception} +Floating point underflow denotes the situation when a floating-point +number is to be created which is so close to @code{0} that its exponent +is too low to be represented internally. By default, this causes the +exception @code{floating_point_underflow_exception} (subclass of +@code{floating_point_exception}) to be thrown. If you set the global +variable @example cl_boolean cl_inhibit_floating_point_underflow @end example -to @code{cl_true}, the error will be inhibited, and a floating-point zero -will be generated instead. The default value of +to @code{cl_true}, the exception will be inhibited, and a floating-point +zero will be generated instead. The default value of @code{cl_inhibit_floating_point_underflow} is @code{cl_false}. diff --git a/examples/contfrac.cc b/examples/contfrac.cc index b80c661..8c3b0be 100644 --- a/examples/contfrac.cc +++ b/examples/contfrac.cc @@ -11,40 +11,33 @@ using namespace std; using namespace cln; -// Our private error handling: return to the main program. -#include <csetjmp> -jmp_buf restartpoint; -namespace cln { - void cl_abort (void) { longjmp(restartpoint,1); } -} - int main (int argc, char* argv[]) { for (int i = 1; i < argc; i++) { const char * arg = argv[i]; - if (setjmp(restartpoint)) - continue; - // Convert argument to its internal representation: - cl_R x = arg; - // Check sign. - if (minusp(x)) { - cout << '-'; - x = -x; - } - cout << "["; - const char* separator = "; "; - for (;;) { - // Split x into integral and fractional part. - cl_R_div_t x_split = floor2(x); - cout << x_split.quotient; - x = x_split.remainder; - if (zerop(x)) - break; - cout << separator; - separator = ", "; - // Invert x. - x = recip(x); - } - cout << ']' << endl; + try { + // Convert argument to its internal representation: + cl_R x = arg; + // Check sign. + if (minusp(x)) { + cout << '-'; + x = -x; + } + cout << "["; + const char* separator = "; "; + for (;;) { + // Split x into integral and fractional part. + cl_R_div_t x_split = floor2(x); + cout << x_split.quotient; + x = x_split.remainder; + if (zerop(x)) + break; + cout << separator; + separator = ", "; + // Invert x. + x = recip(x); + } + cout << ']' << endl; + } catch ( const runtime_exception& ) {} } } diff --git a/include/cln/GV.h b/include/cln/GV.h index e0d6d98..4f0a369 100644 --- a/include/cln/GV.h +++ b/include/cln/GV.h @@ -5,7 +5,7 @@ #include "cln/object.h" #include "cln/V.h" -#include "cln/abort.h" +#include "cln/exception.h" #include <cstdlib> namespace cln { @@ -172,7 +172,7 @@ template <class T> inline cl_GV_index<T>::operator T () const { #ifndef CL_GV_NO_RANGECHECKS - if (!(index < vec->len)) cl_abort(); + if (!(index < vec->len)) throw runtime_exception(); #endif return vec->vectorops->element(vec,index); } @@ -181,7 +181,7 @@ template <class T> inline void cl_GV_index<T>::operator= (const T& x) const { #ifndef CL_GV_NO_RANGECHECKS - if (!(index < vec->len)) cl_abort(); + if (!(index < vec->len)) throw runtime_exception(); #endif vec->vectorops->set_element(vec,index,x); } @@ -190,7 +190,7 @@ template <class T> inline cl_GV_constindex<T>::operator T () const { #ifndef CL_GV_NO_RANGECHECKS - if (!(index < vec->len)) cl_abort(); + if (!(index < vec->len)) throw runtime_exception(); #endif return vec->vectorops->element(vec,index); } @@ -255,7 +255,7 @@ public: const cl_heap_GV<T> * hsrc = (const cl_heap_GV<T> *) src.pointer; cl_heap_GV<T> * hdest = (cl_heap_GV<T> *) dest.pointer; if (!(hsrc->v.vectorops == hdest->v.vectorops)) - cl_abort(); + throw runtime_exception(); hsrc->v.vectorops->copy_elements(&hsrc->v,srcindex,&hdest->v,destindex,count); } // Private pointer manipulations. diff --git a/include/cln/SV.h b/include/cln/SV.h index 011bb13..5881b61 100644 --- a/include/cln/SV.h +++ b/include/cln/SV.h @@ -5,7 +5,7 @@ #include "cln/object.h" #include "cln/V.h" -#include "cln/abort.h" +#include "cln/exception.h" #include <cstdlib> namespace cln { @@ -50,14 +50,14 @@ public: const T & operator[] (unsigned long index) const { #ifndef CL_SV_NO_RANGECHECKS - if (!(index < length())) cl_abort(); + if (!(index < length())) throw runtime_exception(); #endif return data()[index]; } T & operator[] (unsigned long index) { #ifndef CL_SV_NO_RANGECHECKS - if (!(index < length())) cl_abort(); + if (!(index < length())) throw runtime_exception(); #endif return data()[index]; } diff --git a/include/cln/abort.h b/include/cln/abort.h deleted file mode 100644 index 7bbf0ee..0000000 --- a/include/cln/abort.h +++ /dev/null @@ -1,16 +0,0 @@ -// Abnormal program exit. - -#ifndef _CL_ABORT_H -#define _CL_ABORT_H - -namespace cln { - -#ifdef _CL_MACROS_H -nonreturning_function(extern, cl_abort, (void)); -#else -extern void cl_abort (void); -#endif - -} // namespace cln - -#endif /* _CL_ABORT_H */ diff --git a/include/cln/cln.h b/include/cln/cln.h index a56061a..4ff7e45 100644 --- a/include/cln/cln.h +++ b/include/cln/cln.h @@ -18,7 +18,7 @@ // Miscellaneous. #include "cln/random.h" #include "cln/malloc.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cln/floatformat.h" #include "cln/io.h" #include "cln/condition.h" diff --git a/include/cln/exception.h b/include/cln/exception.h new file mode 100644 index 0000000..d9f1a4f --- /dev/null +++ b/include/cln/exception.h @@ -0,0 +1,39 @@ +// Exception types. + +#ifndef _CL_EXCEPTION_H +#define _CL_EXCEPTION_H + +#include <stdexcept> + +namespace cln { + +// Base class of all exception classes thrown by CLN. +class runtime_exception : public std::runtime_error { +public: + runtime_exception () + : std::runtime_error(std::string()) {} + explicit runtime_exception (const std::string & what) + : std::runtime_error(what) {} +}; + +// Thrown when an assertion is violated. +class notreached_exception : public runtime_exception { +public: + notreached_exception (const char* filename, int lineno); +}; + +// Thrown when a pole is encountered. +class division_by_0_exception : public runtime_exception { +public: + division_by_0_exception (); +}; + +// Thrown when a conversion with As(TYPE)(VALUE) fails. +class as_exception : public runtime_exception { +public: + as_exception (const class cl_number& obj, const char * typestring, const char * filename, int line); +}; + +} // namespace cln + +#endif /* _CL_EXCEPTION_H */ diff --git a/include/cln/float.h b/include/cln/float.h index abee49b..383f1f2 100644 --- a/include/cln/float.h +++ b/include/cln/float.h @@ -12,6 +12,7 @@ #include "cln/ffloat_class.h" #include "cln/dfloat_class.h" #include "cln/lfloat_class.h" +#include "cln/exception.h" namespace cln { @@ -733,11 +734,36 @@ inline cl_F& operator/= (cl_F& x, const float y) { return x = x / y; } inline cl_F& operator/= (cl_F& x, const double y) { return x = x / y; } #endif +// Thrown when a floating-point exception occurs. +class floating_point_exception : public runtime_exception { +public: + explicit floating_point_exception(const std::string & what) + : runtime_exception(what) {} +}; + +// Thrown when NaN occurs. +class floating_point_nan_exception : public floating_point_exception { +public: + floating_point_nan_exception(); +}; + +// Thrown when overflow occurs. +class floating_point_overflow_exception : public floating_point_exception { +public: + floating_point_overflow_exception(); +}; + +// Thrown when underflow occurs. +class floating_point_underflow_exception : public floating_point_exception { +public: + floating_point_underflow_exception(); +}; + CL_REQUIRE(cl_ieee) -// If this is true, floating point underflow returns zero instead of an error. +// If this is true, floating point underflow returns zero instead of throwing an exception. extern cl_boolean cl_inhibit_floating_point_underflow; } // namespace cln diff --git a/include/cln/integer.h b/include/cln/integer.h index 28d5164..f470442 100644 --- a/include/cln/integer.h +++ b/include/cln/integer.h @@ -5,6 +5,7 @@ #include "cln/number.h" #include "cln/integer_class.h" +#include "cln/exception.h" #include "cln/random.h" namespace cln { @@ -165,6 +166,12 @@ inline cl_boolean evenp (const cl_I& x) extern const cl_I ash (const cl_I& x, sintC y); extern const cl_I ash (const cl_I& x, const cl_I& y); +// Thrown when shift amount is too large. +class ash_exception : public runtime_exception { +public: + explicit ash_exception (const cl_I& badamount); +}; + // (LOGCOUNT x), wo x ein Integer ist. Ergebnis uintL. extern uintC logcount (const cl_I& x); @@ -421,6 +428,12 @@ struct cl_I_div_t { // < ergebnis: Quotient x/y, ein Integer extern const cl_I exquo (const cl_I& x, const cl_I& y); +// Thrown when quotient is no integer. +class exquo_exception : public runtime_exception { +public: + exquo_exception (const cl_I& x, const cl_I& y); +}; + // mod(x,y) = (mod x y), wo x,y Integers sind. extern const cl_I mod (const cl_I& x, const cl_I& y); diff --git a/include/cln/modinteger.h b/include/cln/modinteger.h index 90647ca..ade02d8 100644 --- a/include/cln/modinteger.h +++ b/include/cln/modinteger.h @@ -11,7 +11,7 @@ #include "cln/io.h" #include "cln/proplist.h" #include "cln/condition.h" -#include "cln/abort.h" +#include "cln/exception.h" #undef random // Linux defines random() as a macro! namespace cln { @@ -141,9 +141,9 @@ public: cl_MI_x (cl_composite_condition* c) : value (), condition (c) {} cl_MI_x (const cl_MI& x) : value (x), condition (NULL) {} // Cast operators. - //operator cl_MI& () { if (condition) cl_abort(); return value; } - //operator const cl_MI& () const { if (condition) cl_abort(); return value; } - operator cl_MI () const { if (condition) cl_abort(); return value; } + //operator cl_MI& () { if (condition) throw runtime_exception(); return value; } + //operator const cl_MI& () const { if (condition) throw runtime_exception(); return value; } + operator cl_MI () const { if (condition) throw runtime_exception(); return value; } }; @@ -253,13 +253,13 @@ public: // High-level operations. void fprint (std::ostream& stream, const cl_MI& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); _fprint(stream,x); } cl_boolean equal (const cl_MI& x, const cl_MI& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return _equal(x,y); } const cl_MI random (random_state& randomstate = default_random_state) @@ -272,24 +272,24 @@ public: } cl_boolean zerop (const cl_MI& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _zerop(x); } const cl_MI plus (const cl_MI& x, const cl_MI& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_MI(this,_plus(x,y)); } const cl_MI minus (const cl_MI& x, const cl_MI& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_MI(this,_minus(x,y)); } const cl_MI uminus (const cl_MI& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_MI(this,_uminus(x)); } const cl_MI one () @@ -302,34 +302,34 @@ public: } const cl_MI mul (const cl_MI& x, const cl_MI& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_MI(this,_mul(x,y)); } const cl_MI square (const cl_MI& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_MI(this,_square(x)); } const cl_MI expt_pos (const cl_MI& x, const cl_I& y) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_MI(this,_expt_pos(x,y)); } const cl_MI_x recip (const cl_MI& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _recip(x); } const cl_MI_x div (const cl_MI& x, const cl_MI& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return _div(x,y); } const cl_MI_x expt (const cl_MI& x, const cl_I& y) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _expt(x,y); } const cl_I reduce_modulo (const cl_I& x) @@ -338,7 +338,7 @@ public: } const cl_I retract (const cl_MI& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _retract(x); } // Miscellaneous. diff --git a/include/cln/number_io.h b/include/cln/number_io.h index bf77a05..aa9f187 100644 --- a/include/cln/number_io.h +++ b/include/cln/number_io.h @@ -5,31 +5,35 @@ #include "cln/io.h" #include "cln/number.h" +#include "cln/exception.h" namespace cln { // Input. +class read_number_exception : public runtime_exception { +public: + explicit read_number_exception(const std::string & what) + : runtime_exception(what) {} +}; + // Finish with bad syntax. -#ifdef _CL_MACROS_H -nonreturning_function(extern, read_number_bad_syntax, (const char * string, const char * string_limit)); -#else -extern void read_number_bad_syntax (const char * string, const char * string_limit); -#endif +class read_number_bad_syntax_exception : public read_number_exception { +public: + read_number_bad_syntax_exception(const char * string, const char * string_limit); +}; // Finish with junk after the number. -#ifdef _CL_MACROS_H -nonreturning_function(extern, read_number_junk, (const char * string_rest, const char * string, const char * string_limit)); -#else -extern void read_number_junk (const char * string_rest, const char * string, const char * string_limit); -#endif - -// Finish with EOF. -#ifdef _CL_MACROS_H -nonreturning_function(extern, read_number_eof, (void)); -#else -extern void read_number_eof (void); -#endif +class read_number_junk_exception : public read_number_exception { +public: + read_number_junk_exception(const char * string_rest, const char * string, const char * string_limit); +}; + +// Finish with premature EOF. +class read_number_eof_exception : public read_number_exception { +public: + read_number_eof_exception(); +}; struct cl_read_flags; diff --git a/include/cln/object.h b/include/cln/object.h index 1f66055..52f72ef 100644 --- a/include/cln/object.h +++ b/include/cln/object.h @@ -554,7 +554,7 @@ inline cl_private_thing as_cl_private_thing (const cl_rcpointer& x) #define CL_DEFINE_CONVERTER(target_class) \ operator const target_class & () const \ { \ - if (sizeof(*this) != sizeof(target_class)) cl_abort(); \ + typedef int assert1 [2*(sizeof(target_class)==sizeof(*this))-1]; \ return * (const target_class *) (void*) this; \ } diff --git a/include/cln/rational.h b/include/cln/rational.h index 6b50855..bccce7f 100644 --- a/include/cln/rational.h +++ b/include/cln/rational.h @@ -6,6 +6,7 @@ #include "cln/number.h" #include "cln/rational_class.h" #include "cln/integer_class.h" +#include "cln/exception.h" namespace cln { diff --git a/include/cln/ring.h b/include/cln/ring.h index b282cf3..8c7fbbb 100644 --- a/include/cln/ring.h +++ b/include/cln/ring.h @@ -7,6 +7,7 @@ #include "cln/malloc.h" #include "cln/proplist.h" #include "cln/number.h" +#include "cln/exception.h" #include "cln/io.h" namespace cln { @@ -235,13 +236,13 @@ public: // High-level operations. void fprint (std::ostream& stream, const cl_ring_element& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); _fprint(stream,x); } cl_boolean equal (const cl_ring_element& x, const cl_ring_element& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return _equal(x,y); } const cl_ring_element zero () @@ -250,24 +251,24 @@ public: } cl_boolean zerop (const cl_ring_element& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _zerop(x); } const cl_ring_element plus (const cl_ring_element& x, const cl_ring_element& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_ring_element(this,_plus(x,y)); } const cl_ring_element minus (const cl_ring_element& x, const cl_ring_element& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_ring_element(this,_minus(x,y)); } const cl_ring_element uminus (const cl_ring_element& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_ring_element(this,_uminus(x)); } const cl_ring_element one () @@ -280,18 +281,18 @@ public: } const cl_ring_element mul (const cl_ring_element& x, const cl_ring_element& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_ring_element(this,_mul(x,y)); } const cl_ring_element square (const cl_ring_element& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_ring_element(this,_square(x)); } const cl_ring_element expt_pos (const cl_ring_element& x, const cl_I& y) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_ring_element(this,_expt_pos(x,y)); } // Property operations. @@ -363,7 +364,20 @@ inline const cl_ring_element operator* (const cl_ring_element& x, const cl_I& y) // Ring of uninitialized elements. -// Any operation results in a run-time error. +// Any operation results in an exception being thrown. + +// Thrown when an attempt is made to perform an operation on an uninitialized ring. +class uninitialized_ring_exception : public runtime_exception { +public: + uninitialized_ring_exception (); +}; + +// Thrown when a ring element is uninitialized. +class uninitialized_exception : public runtime_exception { +public: + explicit uninitialized_exception (const _cl_ring_element& obj); + uninitialized_exception (const _cl_ring_element& obj_x, const _cl_ring_element& obj_y); +}; extern const cl_ring cl_no_ring; extern cl_class cl_class_no_ring; diff --git a/include/cln/string.h b/include/cln/string.h index 97703ec..c316f04 100644 --- a/include/cln/string.h +++ b/include/cln/string.h @@ -5,7 +5,7 @@ #include "cln/object.h" #include "cln/io.h" -#include "cln/abort.h" +#include "cln/exception.h" #include <cstring> namespace cln { @@ -18,9 +18,9 @@ private: unsigned long length; // length (in characters) char data[1]; // the characters, plus a '\0' at the end // Standard allocation disabled. - void* operator new (size_t size) { (void)size; cl_abort(); return (void*)1; } + void* operator new (size_t size) { (void)size; throw runtime_exception(); } // Standard deallocation disabled. - void operator delete (void* ptr) { (void)ptr; cl_abort(); } + void operator delete (void* ptr) { (void)ptr; throw runtime_exception(); } // No default constructor. cl_heap_string (); private: @@ -52,7 +52,7 @@ public: // Return a specific character. char operator[] (unsigned long i) const { - if (!(i < length())) cl_abort(); // Range check. + if (!(i < length())) throw runtime_exception(); // Range check. return ((cl_heap_string*)pointer)->data[i]; } // New ANSI C++ compilers also want the following. diff --git a/include/cln/univpoly.h b/include/cln/univpoly.h index 39e1f1e..95d2ea1 100644 --- a/include/cln/univpoly.h +++ b/include/cln/univpoly.h @@ -231,13 +231,13 @@ public: // High-level operations. void fprint (std::ostream& stream, const cl_UP& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); _fprint(stream,x); } cl_boolean equal (const cl_UP& x, const cl_UP& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return _equal(x,y); } const cl_UP zero () @@ -246,24 +246,24 @@ public: } cl_boolean zerop (const cl_UP& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _zerop(x); } const cl_UP plus (const cl_UP& x, const cl_UP& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_UP(this,_plus(x,y)); } const cl_UP minus (const cl_UP& x, const cl_UP& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_UP(this,_minus(x,y)); } const cl_UP uminus (const cl_UP& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_UP(this,_uminus(x)); } const cl_UP one () @@ -276,33 +276,33 @@ public: } const cl_UP mul (const cl_UP& x, const cl_UP& y) { - if (!(x.ring() == this)) cl_abort(); - if (!(y.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_UP(this,_mul(x,y)); } const cl_UP square (const cl_UP& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_UP(this,_square(x)); } const cl_UP expt_pos (const cl_UP& x, const cl_I& y) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return cl_UP(this,_expt_pos(x,y)); } const cl_UP scalmul (const cl_ring_element& x, const cl_UP& y) { - if (!(y.ring() == this)) cl_abort(); + if (!(y.ring() == this)) throw runtime_exception(); return cl_UP(this,_scalmul(x,y)); } sintL degree (const cl_UP& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _degree(x); } sintL ldegree (const cl_UP& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _ldegree(x); } const cl_UP monomial (const cl_ring_element& x, uintL e) @@ -311,7 +311,7 @@ public: } const cl_ring_element coeff (const cl_UP& x, uintL index) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _coeff(x,index); } const cl_UP create (sintL deg) @@ -320,17 +320,17 @@ public: } void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); _set_coeff(x,index,y); } void finalize (cl_UP& x) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); _finalize(x); } const cl_ring_element eval (const cl_UP& x, const cl_ring_element& y) { - if (!(x.ring() == this)) cl_abort(); + if (!(x.ring() == this)) throw runtime_exception(); return _eval(x,y); } // Property operations. diff --git a/src/base/cl_N.h b/src/base/cl_N.h index 6acdaba..cf803e4 100644 --- a/src/base/cl_N.h +++ b/src/base/cl_N.h @@ -8,9 +8,6 @@ namespace cln { -nonreturning_function(extern, cl_error_division_by_0, (void)); -nonreturning_function(extern, cl_as_error, (const cl_number& obj, const char * typestring, const char * filename, int line)); - // For the equal-invariant hashcode, we take a mixture of exponent, length // and the most significant 32 bits. To ensure that equal(x,y) implies // equal_hashcode(x) == equal_hashcode(y) we must make sure that diff --git a/src/base/cl_N_err_d0.cc b/src/base/cl_N_err_d0.cc deleted file mode 100644 index 5360d6e..0000000 --- a/src/base/cl_N_err_d0.cc +++ /dev/null @@ -1,23 +0,0 @@ -// cl_error_division_by_0(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_N.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_error_division_by_0 (void) -{ - fprint(std::cerr, "Division by zero.\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/base/cl_abort.cc b/src/base/cl_abort.cc deleted file mode 100644 index 45cb016..0000000 --- a/src/base/cl_abort.cc +++ /dev/null @@ -1,21 +0,0 @@ -// cl_abort(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cln/abort.h" - - -// Implementation. - -#include <cstdlib> - -namespace cln { - -void cl_abort (void) -{ - exit(1); -} - -} // namespace cln diff --git a/src/base/cl_as_err.cc b/src/base/cl_as_err.cc deleted file mode 100644 index 2becee8..0000000 --- a/src/base/cl_as_err.cc +++ /dev/null @@ -1,38 +0,0 @@ -// cl_as_error(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_N.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_as_error (const cl_number& obj, const char * typestring, const char * filename, int line) -{ - 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(std::cerr, obj); -#else - fprint(std::cerr, "@0x"); - fprinthexadecimal(std::cerr, (unsigned long)(void*)&obj); - fprint(std::cerr, ": 0x"); - fprinthexadecimal(std::cerr, (unsigned long)obj.word); -#endif - fprint(std::cerr, "\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/base/cl_as_exception.cc b/src/base/cl_as_exception.cc new file mode 100644 index 0000000..dcab70e --- /dev/null +++ b/src/base/cl_as_exception.cc @@ -0,0 +1,44 @@ +// as_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cln/exception.h" + + +// Implementation. + +#include "cln/io.h" +#include "cl_N.h" +#include <sstream> + +namespace cln { + +static inline const std::string +as_error_msg (const cl_number& obj, const char * typestring, const char * filename, int line) +{ + std::ostringstream buf; + fprint(buf, "Type assertion failed: in file "); + fprint(buf, filename); + fprint(buf, ", line "); + fprintdecimal(buf, line); + fprint(buf, ", not "); + fprint(buf, typestring); + fprint(buf, ": "); +#if 0 // This brings in a dependency from the complex and float printer and all the float stuff. + fprint(buf, obj); +#else + fprint(buf, "@0x"); + fprinthexadecimal(buf, (unsigned long)(void*)&obj); + fprint(buf, ": 0x"); + fprinthexadecimal(buf, (unsigned long)obj.word); +#endif + return buf.str(); +} + +as_exception::as_exception (const cl_number& obj, const char * typestring, const char * filename, int line) + : runtime_exception(as_error_msg(obj, typestring, filename, line)) +{} + +} // namespace cln diff --git a/src/base/cl_d0_exception.cc b/src/base/cl_d0_exception.cc new file mode 100644 index 0000000..7175709 --- /dev/null +++ b/src/base/cl_d0_exception.cc @@ -0,0 +1,15 @@ +// division_by_0_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cln/exception.h" + +namespace cln { + +division_by_0_exception::division_by_0_exception () + : runtime_exception("Division by zero.") +{} + +} // namespace cln diff --git a/src/base/cl_debug.cc b/src/base/cl_debug.cc index e5b0f6c..2998b65 100644 --- a/src/base/cl_debug.cc +++ b/src/base/cl_debug.cc @@ -10,7 +10,6 @@ // Implementation. #include "cln/io.h" -#include "cln/abort.h" namespace cln { diff --git a/src/base/cl_macros.h b/src/base/cl_macros.h index ec49995..af93ce1 100644 --- a/src/base/cl_macros.h +++ b/src/base/cl_macros.h @@ -4,6 +4,7 @@ #define _CL_MACROS_H #include "cln/types.h" +#include "cln/exception.h" // Concatenation of macroexpanded tokens. // Example: @@ -73,10 +74,7 @@ // Denotes a point where control flow can never arrive. // NOTREACHED - #define NOTREACHED cl_notreached_abort(__FILE__,__LINE__); -namespace cln { - nonreturning_function(extern,cl_notreached_abort, (const char* filename, int lineno)); -} // namespace cln + #define NOTREACHED throw notreached_exception(__FILE__,__LINE__); // Check an arithmetic expression. // ASSERT(expr) diff --git a/src/base/cl_malloc.cc b/src/base/cl_malloc.cc index ef6d8b6..981254e 100644 --- a/src/base/cl_malloc.cc +++ b/src/base/cl_malloc.cc @@ -11,7 +11,7 @@ #include <cstdlib> #include "cln/io.h" -#include "cln/abort.h" +#include "cln/exception.h" #ifndef malloc extern "C" void* malloc (size_t size); @@ -28,8 +28,7 @@ static void* xmalloc (size_t size) void* ptr = malloc(size); if (ptr) return ptr; - fprint(std::cerr, "Out of virtual memory.\n"); - cl_abort(); + throw runtime_exception("Out of virtual memory."); } void* (*malloc_hook) (size_t size) = xmalloc; diff --git a/src/base/cl_notreached.cc b/src/base/cl_notreached.cc deleted file mode 100644 index 95b27e5..0000000 --- a/src/base/cl_notreached.cc +++ /dev/null @@ -1,28 +0,0 @@ -// cl_notreached_abort(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_macros.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_notreached_abort (const char* filename, int lineno) -{ - 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(); -} - -} // namespace cln diff --git a/src/base/cl_notreached_exception.cc b/src/base/cl_notreached_exception.cc new file mode 100644 index 0000000..a8cc7fe --- /dev/null +++ b/src/base/cl_notreached_exception.cc @@ -0,0 +1,34 @@ +// cl_notreached_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cl_macros.h" + + +// Implementation. + +#include "cln/io.h" +#include <sstream> + +namespace cln { + +static inline const std::string +notreached_error_msg (const char* filename, int lineno) +{ + std::ostringstream buf; + fprint(buf, "Internal error: statement in file "); + fprint(buf, filename); + fprint(buf, ", line "); + fprintdecimal(buf, lineno); + fprint(buf, " has been reached!!\n"); + fprint(buf, "Please send the authors of the program a description how you produced this error!"); + return buf.str(); +} + +notreached_exception::notreached_exception (const char* filename, int lineno) + : runtime_exception(notreached_error_msg(filename, lineno)) +{} + +} // namespace cln diff --git a/src/base/digitseq/cl_2DS_div.cc b/src/base/digitseq/cl_2DS_div.cc index 5d0738e..997e396 100644 --- a/src/base/digitseq/cl_2DS_div.cc +++ b/src/base/digitseq/cl_2DS_div.cc @@ -11,7 +11,7 @@ #include "cl_2D.h" #include "cl_DS.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -126,7 +126,7 @@ void div2adic (uintC a_len, const uintD* a_LSDptr, uintC b_len, const uintD* b_L cl_UDS_mul(q_LSDptr,b_len,b_LSDptr,b_len,p_LSDptr); // �berpr�fen, da� p == a mod 2^(intDsize*b_len): if (compare_loop_msp(a_LSDptr lspop b_len,p_LSDptr lspop b_len,b_len)) - cl_abort(); + throw runtime_exception(); // Quotient q und "Rest" (a-b*q)/2^(intDsize*b_len) ablegen: copy_loop_lsp(q_LSDptr,dest_LSDptr,b_len); if (lendiff <= b_len) diff --git a/src/base/digitseq/cl_DS_div.cc b/src/base/digitseq/cl_DS_div.cc index 1f850e9..9de5fe1 100644 --- a/src/base/digitseq/cl_DS_div.cc +++ b/src/base/digitseq/cl_DS_div.cc @@ -9,8 +9,7 @@ // Implementation. -#include "cl_N.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -173,7 +172,7 @@ namespace cln { while ((a_len>0) && (mspref(a_MSDptr,0)==0)) { msshrink(a_MSDptr); a_len--; } // b normalisieren (b_MSDptr erh�hen, b_len erniedrigen): loop - { if (b_len==0) { cl_error_division_by_0(); } + { if (b_len==0) { throw division_by_0_exception(); } if (mspref(b_MSDptr,0)==0) { msshrink(b_MSDptr); b_len--; } else break; } @@ -293,11 +292,11 @@ namespace cln { if (subfrom_loop_lsp(b_LSDptr,p_LSDptr,b_len)) dec_loop_lsp(p_LSDptr lspop b_len,j+2); if ((mspref(p_MSDptr,0) > 0) || (compare_loop_msp(p_MSDptr mspop 1,r_MSDptr,a_len+1) > 0)) - cl_abort(); + throw runtime_exception(); } } // Rest bestimmen: subfrom_loop_lsp(p_LSDptr,r_LSDptr,a_len+1); - if (test_loop_msp(r_MSDptr,j)) cl_abort(); + if (test_loop_msp(r_MSDptr,j)) throw runtime_exception(); r_MSDptr = r_LSDptr lspop b_len; // = r_MSDptr mspop (j+1); // d ist um h�chstens 2 zu klein, mu� also evtl. zweimal um 1 // incrementieren, bis der Rest < b wird. @@ -310,10 +309,10 @@ namespace cln { if (subfrom_loop_lsp(b_LSDptr,r_LSDptr,b_len)) lspref(r_LSDptr,b_len) -= 1; if ((lspref(r_MSDptr,0) > 0) || (compare_loop_msp(r_MSDptr,b_MSDptr,b_len) >= 0)) - cl_abort(); + throw runtime_exception(); } } // r ist fertig, q := d. - if (mspref(d_MSDptr,0) > 0) cl_abort(); + if (mspref(d_MSDptr,0) > 0) throw runtime_exception(); q_len = j+1; copy_loop_msp(d_MSDptr mspop 1,q_MSDptr,q_len); } else diff --git a/src/base/digitseq/cl_DS_mul.cc b/src/base/digitseq/cl_DS_mul.cc index 5400e7f..76be717 100644 --- a/src/base/digitseq/cl_DS_mul.cc +++ b/src/base/digitseq/cl_DS_mul.cc @@ -11,7 +11,7 @@ #include "cl_low.h" #include "cln/malloc.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -499,7 +499,7 @@ namespace cln { var uintD tmpprod_xxx = cl_alloc_array(uintD,len1+len2); mulu_xxx(sourceptr1,len1,sourceptr2,len2,arrayLSDptr(tmpprod_xxx,len1+len2)); if (compare_loop_msp(destptr lspop (len1+len2),arrayMSDptr(tmpprod_xxx,len1+len2),len1+len2)) - cl_abort(); + throw runtime_exception(); } #endif } diff --git a/src/base/digitseq/cl_DS_mul_fftc.h b/src/base/digitseq/cl_DS_mul_fftc.h index 5d6eeae..6bd2123 100644 --- a/src/base/digitseq/cl_DS_mul_fftc.h +++ b/src/base/digitseq/cl_DS_mul_fftc.h @@ -157,8 +157,7 @@ #include "cln/floatparam.h" -#include "cln/io.h" -#include "cln/abort.h" +#include "cln/exception.h" #if defined(HAVE_LONGDOUBLE) && (long_double_mant_bits > double_mant_bits) && (defined(__i386__) || defined(__m68k__) || (defined(__sparc__) && 0)) // Only these CPUs have fast "long double"s in hardware. @@ -447,10 +446,10 @@ static void fftc_convolution (const uintL n, const uintC N, // N = 2^n var fftc_complex& w_N = w[N>>1]; part = w_N.re - (fftc_real)(-1.0); if (part > epsilon || part < -epsilon) - cl_abort(); + throw runtime_exception(); part = w_N.im; if (part > epsilon || part < -epsilon) - cl_abort(); + throw runtime_exception(); } { var fftc_complex w_N; @@ -467,10 +466,10 @@ static void fftc_convolution (const uintL n, const uintC N, // N = 2^n var fftc_real part; part = w_N.re - (fftc_real)1.0; if (part > epsilon || part < -epsilon) - cl_abort(); + throw runtime_exception(); part = w_N.im; if (part > epsilon || part < -epsilon) - cl_abort(); + throw runtime_exception(); } #endif var bool squaring = (x == y); @@ -663,8 +662,7 @@ static void fill_factor (uintC N, fftc_complex* x, uintL l, if (max_l(2) > intDsize && l > intDsize) { // l > intDsize if (max_l(2) > 64 && l > 64) { - fprint(std::cerr, "FFT problem: l > 64 not supported by pow2_table\n"); - cl_abort(); + throw runtime_exception("FFT problem: l > 64 not supported by pow2_table"); } var fftc_real carry = 0; var sintL carrybits = 0; // number of bits in carry (>=0, <l) @@ -689,11 +687,11 @@ static void fill_factor (uintC N, fftc_complex* x, uintL l, i++; } if (i > N) - cl_abort(); + throw runtime_exception(); } else if (max_l(2) >= intDsize && l == intDsize) { // l = intDsize if (len > N) - cl_abort(); + throw runtime_exception(); for (i = 0; i < len; i++) { var uintD digit = lsprefnext(sourceptr); x[i].re = (fftc_real)digit; @@ -723,7 +721,7 @@ static void fill_factor (uintC N, fftc_complex* x, uintL l, } while (carrybits > 0) { if (!(i < N)) - cl_abort(); + throw runtime_exception(); x[i].re = (fftc_real)(carry & l_mask); x[i].im = (fftc_real)0; carry >>= l; @@ -731,7 +729,7 @@ static void fill_factor (uintC N, fftc_complex* x, uintL l, i++; } if (len > 0) - cl_abort(); + throw runtime_exception(); } for ( ; i < N; i++) { x[i].re = (fftc_real)0; @@ -886,7 +884,7 @@ static uintD* unfill_product (uintL n, uintC N, // N = 2^n if (!(digit >= (fftc_real)0 && z[i].re > digit - (fftc_real)0.5 && z[i].re < digit + (fftc_real)0.5)) - cl_abort(); + throw runtime_exception(); #endif if (shift > 0) digit = digit * fftc_pow2_table[shift]; @@ -944,8 +942,7 @@ static inline void mulu_fftcomplex_nocheck (const uintD* sourceptr1, uintC len1, for ( ; ; k++) { if (k >= sizeof(max_l_table)/sizeof(max_l_table[0]) || max_l_table[k] <= 0) { - fprint(std::cerr, "FFT problem: numbers too big, floating point precision not sufficient\n"); - cl_abort(); + throw runtime_exception("FFT problem: numbers too big, floating point precision not sufficient"); } if (2*ceiling(len1*intDsize,max_l_table[k])-1 <= ((uintC)1 << k)) break; @@ -997,7 +994,7 @@ static inline void mulu_fftcomplex_nocheck (const uintD* sourceptr1, uintC len1, mulu_loop_lsp(lspref(sourceptr2,0),sourceptr1,tmpptr,len1); if (addto_loop_lsp(tmpptr,destptr,len1+1)) if (inc_loop_lsp(destptr lspop (len1+1),destlen-(len1+1))) - cl_abort(); + throw runtime_exception(); } else { var bool squaring = ((sourceptr1 == sourceptr2) && (len1 == len2p)); // Fill factor x. @@ -1020,10 +1017,10 @@ static inline void mulu_fftcomplex_nocheck (const uintD* sourceptr1, uintC len1, for (var uintC i = 0; i < N; i++) { if (!(z[i].im > im_lo_limit && z[i].im < im_hi_limit)) - cl_abort(); + throw runtime_exception(); if (!(z[i].re > re_lo_limit && z[i].re < re_hi_limit)) - cl_abort(); + throw runtime_exception(); } } #endif @@ -1036,16 +1033,16 @@ static inline void mulu_fftcomplex_nocheck (const uintD* sourceptr1, uintC len1, tmpMSDptr - tmpLSDptr; #endif if (tmplen > tmpprod_len) - cl_abort(); + throw runtime_exception(); // Add result to destptr[-destlen..-1]: if (tmplen > destlen) { if (test_loop_msp(tmpMSDptr,tmplen-destlen)) - cl_abort(); + throw runtime_exception(); tmplen = destlen; } if (addto_loop_lsp(tmpLSDptr,destptr,tmplen)) if (inc_loop_lsp(destptr lspop tmplen,destlen-tmplen)) - cl_abort(); + throw runtime_exception(); } // Decrement len2. destptr = destptr lspop len2p; @@ -1100,7 +1097,6 @@ static void mulu_fftcomplex (const uintD* sourceptr1, uintC len1, var uintD checksum = multiply_checksum(checksum1,checksum2); mulu_fftcomplex_nocheck(sourceptr1,len1,sourceptr2,len2,destptr); if (!(checksum == compute_checksum(destptr,len1+len2))) { - fprint(std::cerr, "FFT problem: checksum error\n"); - cl_abort(); + throw runtime_exception("FFT problem: checksum error"); } } diff --git a/src/base/digitseq/cl_DS_mul_fftcs.h b/src/base/digitseq/cl_DS_mul_fftcs.h index ed3019d..6269bf2 100644 --- a/src/base/digitseq/cl_DS_mul_fftcs.h +++ b/src/base/digitseq/cl_DS_mul_fftcs.h @@ -270,8 +270,7 @@ #include "cln/floatparam.h" -#include "cln/io.h" -#include "cln/abort.h" +#include "cln/exception.h" #if defined(HAVE_LONGDOUBLE) && (long_double_mant_bits > double_mant_bits) && (defined(__i386__) || defined(__m68k__) || (defined(__sparc__) && 0)) @@ -475,7 +474,7 @@ static uintC shuffle (uintL n, uintC x) } x >>= 1; } while (!(--n == 0)); - cl_abort(); + throw runtime_exception(); } #if 0 // unused @@ -493,7 +492,7 @@ static uintC invshuffle (uintL n, uintC x) } v <<= 1; } while (!(--n == 0)); - cl_abort(); + throw runtime_exception(); } #endif @@ -727,8 +726,7 @@ static void fill_factor (uintC N, fftcs_real* x, uintL l, if (max_l(2) > intDsize && l > intDsize) { // l > intDsize if (max_l(2) > 64 && l > 64) { - fprint(std::cerr, "FFT problem: l > 64 not supported by pow2_table\n"); - cl_abort(); + throw runtime_exception("FFT problem: l > 64 not supported by pow2_table"); } var fftcs_real carry = 0; var sintL carrybits = 0; // number of bits in carry (>=0, <l) @@ -751,11 +749,11 @@ static void fill_factor (uintC N, fftcs_real* x, uintL l, i++; } if (i > N) - cl_abort(); + throw runtime_exception(); } else if (max_l(2) >= intDsize && l == intDsize) { // l = intDsize if (len > N) - cl_abort(); + throw runtime_exception(); for (i = 0; i < len; i++) { var uintD digit = lsprefnext(sourceptr); x[i] = (fftcs_real)digit; @@ -782,14 +780,14 @@ static void fill_factor (uintC N, fftcs_real* x, uintL l, } while (carrybits > 0) { if (!(i < N)) - cl_abort(); + throw runtime_exception(); x[i] = (fftcs_real)(carry & l_mask); carry >>= l; carrybits -= l; i++; } if (len > 0) - cl_abort(); + throw runtime_exception(); } for ( ; i < N; i++) x[i] = (fftcs_real)0; @@ -942,7 +940,7 @@ static uintD* unfill_product (uintL n, uintC N, // N = 2^n if (!(digit >= (fftcs_real)0 && z[i] > digit - (fftcs_real)0.5 && z[i] < digit + (fftcs_real)0.5)) - cl_abort(); + throw runtime_exception(); #endif if (shift > 0) digit = digit * fftcs_pow2_table[shift]; @@ -1000,8 +998,7 @@ static inline void mulu_fftcs_nocheck (const uintD* sourceptr1, uintC len1, for ( ; ; k++) { if (k >= sizeof(max_l_table)/sizeof(max_l_table[0]) || max_l_table[k] <= 0) { - fprint(std::cerr, "FFT problem: numbers too big, floating point precision not sufficient\n"); - cl_abort(); + throw runtime_exception("FFT problem: numbers too big, floating point precision not sufficient"); } if (2*ceiling(len1*intDsize,max_l_table[k])-1 <= ((uintC)1 << k)) break; @@ -1053,7 +1050,7 @@ static inline void mulu_fftcs_nocheck (const uintD* sourceptr1, uintC len1, mulu_loop_lsp(lspref(sourceptr2,0),sourceptr1,tmpptr,len1); if (addto_loop_lsp(tmpptr,destptr,len1+1)) if (inc_loop_lsp(destptr lspop (len1+1),destlen-(len1+1))) - cl_abort(); + throw runtime_exception(); } else { var bool squaring = ((sourceptr1 == sourceptr2) && (len1 == len2p)); // Fill factor x. @@ -1074,7 +1071,7 @@ static inline void mulu_fftcs_nocheck (const uintD* sourceptr1, uintC len1, for (var uintC i = 0; i < N; i++) if (!(z[i] > re_lo_limit && z[i] < re_hi_limit)) - cl_abort(); + throw runtime_exception(); } #endif var uintD* tmpLSDptr = arrayLSDptr(tmpprod,tmpprod_len); @@ -1086,16 +1083,16 @@ static inline void mulu_fftcs_nocheck (const uintD* sourceptr1, uintC len1, tmpMSDptr - tmpLSDptr; #endif if (tmplen > tmpprod_len) - cl_abort(); + throw runtime_exception(); // Add result to destptr[-destlen..-1]: if (tmplen > destlen) { if (test_loop_msp(tmpMSDptr,tmplen-destlen)) - cl_abort(); + throw runtime_exception(); tmplen = destlen; } if (addto_loop_lsp(tmpLSDptr,destptr,tmplen)) if (inc_loop_lsp(destptr lspop tmplen,destlen-tmplen)) - cl_abort(); + throw runtime_exception(); } // Decrement len2. destptr = destptr lspop len2p; @@ -1150,7 +1147,6 @@ static void mulu_fftcs (const uintD* sourceptr1, uintC len1, var uintD checksum = multiply_checksum(checksum1,checksum2); mulu_fftcs_nocheck(sourceptr1,len1,sourceptr2,len2,destptr); if (!(checksum == compute_checksum(destptr,len1+len2))) { - fprint(std::cerr, "FFT problem: checksum error\n"); - cl_abort(); + throw runtime_exception("FFT problem: checksum error"); } } diff --git a/src/base/digitseq/cl_DS_mul_fftm.h b/src/base/digitseq/cl_DS_mul_fftm.h index 9b97364..9c9a5de 100644 --- a/src/base/digitseq/cl_DS_mul_fftm.h +++ b/src/base/digitseq/cl_DS_mul_fftm.h @@ -469,7 +469,7 @@ static void mulu_fftm (const uintL r, const uintC R, // R = 2^r var uintC zerodigits = chlen - zchlen; for (i = 0; i < M; i++) if (DS_test_loop(Z(i) lspop chlen,zerodigits,Z(i) lspop zchlen)) - cl_abort(); + throw runtime_exception(); } #endif // Put together result. @@ -479,14 +479,14 @@ static void mulu_fftm (const uintL r, const uintC R, // R = 2^r if (zchlen <= destlen) { if (addto_loop_lsp(Z(i),destptr,zchlen)) if (inc_loop_lsp(destptr lspop zchlen,destlen-zchlen)) - cl_abort(); + throw runtime_exception(); } else { #ifdef DEBUG_FFTM if (DS_test_loop(Z(i) lspop zchlen,zchlen-destlen,Z(i) lspop destlen)) - cl_abort(); + throw runtime_exception(); #endif if (addto_loop_lsp(Z(i),destptr,destlen)) - cl_abort(); + throw runtime_exception(); } if (destlen <= k) { i++; @@ -496,7 +496,7 @@ static void mulu_fftm (const uintL r, const uintC R, // R = 2^r #ifdef DEBUG_FFTM // Check that Z(i)..Z(M-1) are all zero. if (test_loop_up(&arrZ[chlen*i],chlen*(M-i))) - cl_abort(); + throw runtime_exception(); #endif #undef diff #undef sum @@ -562,7 +562,7 @@ static uintC numpieces (uintL r, uintL m, uintC len1, uintC len2) var uintC piecelen2 = (M+1-ceiling(len1,k))*k; #ifdef DEBUG_FFTM if ((sintC)piecelen2 <= 0) - cl_abort(); + throw runtime_exception(); #endif return ceiling(len2,piecelen2); } @@ -592,7 +592,7 @@ static void mulu_fft_modm (const uintD* sourceptr1, uintC len1, } #ifdef DEBUG_FFTM if (!(m > 0 && m <= r+1 && okfor(r,m,len1,len1))) - cl_abort(); + throw runtime_exception(); #endif if (okfor(r,m,len1,len2)) { if ((m <= r) && (r > log2_intDsize+2) && okfor(r-1,m,len1,ceiling(len2,2))) @@ -644,7 +644,7 @@ static void mulu_fft_modm (const uintD* sourceptr1, uintC len1, } if (addto_loop_lsp(tmpptr,destptr,destlenp)) if (inc_loop_lsp(destptr lspop destlenp,destlen-destlenp)) - cl_abort(); + throw runtime_exception(); // Decrement len2. destptr = destptr lspop len2p; destlen -= len2p; diff --git a/src/base/digitseq/cl_DS_mul_fftp.h b/src/base/digitseq/cl_DS_mul_fftp.h index 4743f2f..94a0197 100644 --- a/src/base/digitseq/cl_DS_mul_fftp.h +++ b/src/base/digitseq/cl_DS_mul_fftp.h @@ -283,7 +283,7 @@ static inline void shift (const fftp_word& a, fftp_word& b) #ifdef FFTP_EXTERNAL_LOOPS #ifdef DEBUG_FFTP if (shiftrightcopy_loop_msp(arrayMSDptr(a._w,3),arrayMSDptr(b._w,3),3,1,0)) - cl_abort(); + throw runtime_exception(); #else shiftrightcopy_loop_msp(arrayMSDptr(a._w,3),arrayMSDptr(b._w,3),3,1,0); #endif @@ -301,13 +301,13 @@ static inline void shift (const fftp_word& a, fftp_word& b) #ifdef DEBUG_FFTP carry = tmp << 31; if (carry) - cl_abort(); + throw runtime_exception(); #endif #endif } #ifdef DEBUG_FFTP_OPERATIONS -#define check_fftp_word(x) if (compare_loop_msp(arrayMSDptr((x)._w,3),arrayMSDptr(p._w,3),3) >= 0) cl_abort() +#define check_fftp_word(x) if (compare_loop_msp(arrayMSDptr((x)._w,3),arrayMSDptr(p._w,3),3) >= 0) throw runtime_exception() #else #define check_fftp_word(x) #endif @@ -394,7 +394,7 @@ static void mulp (const fftp_word& a, const fftp_word& b, fftp_word& r) // c[0..3] now contains q, c[4..6] contains (c mod 7*2^n). #ifdef DEBUG_FFTP if (lspref(cLSDptr,6) > 0) - cl_abort(); + throw runtime_exception(); #endif #if 0 if (compare_loop_msp(cLSDptr lspop 6,arrayMSDptr(p._w,3),3) >= 0) // q >= p ? @@ -407,7 +407,7 @@ static void mulp (const fftp_word& a, const fftp_word& b, fftp_word& r) #error "mulp not implemented for this prime" #endif if ((sint32)r.w2 < 0) - cl_abort(); + throw runtime_exception(); check_fftp_word(r); } #ifdef DEBUG_FFTP_OPERATIONS @@ -420,7 +420,7 @@ static void mulp_doublecheck (const fftp_word& a, const fftp_word& b, fftp_word& mulp(ma,mb, or); mulp(a,b, r); if (compare_loop_msp(arrayMSDptr(r._w,3),arrayMSDptr(or._w,3),3)) - cl_abort(); + throw runtime_exception(); } #define mulp mulp_doublecheck #endif /* DEBUG_FFTP_OPERATIONS */ @@ -483,10 +483,10 @@ static void fftp_convolution (const uintL n, const uintC N, // N = 2^n var fftp_word w_N; mulp(w[N-1],fftp_roots_of_1[n], w_N); if (!(w_N.w2 == 0 && w_N.w1 == 0 && w_N.w0 == 1)) - cl_abort(); + throw runtime_exception(); w_N = w[N>>1]; if (!(w_N.w2 == p.w2 && w_N.w1 == p.w1 && w_N.w0 == p.w0 - 1)) - cl_abort(); + throw runtime_exception(); } #endif var bool squaring = (x == y); @@ -698,7 +698,7 @@ static void mulu_fft_modp (const uintD* sourceptr1, uintC len1, mulu_loop_lsp(lspref(sourceptr2,0),sourceptr1,tmpptr,len1); if (addto_loop_lsp(tmpptr,destptr,len1+1)) if (inc_loop_lsp(destptr lspop (len1+1),destlen-(len1+1))) - cl_abort(); + throw runtime_exception(); } else { var uintC destlenp = len1 + len2p - 1; // destlenp = min(N,destlen-1). @@ -738,7 +738,7 @@ static void mulu_fft_modp (const uintD* sourceptr1, uintC len1, // Check result. for (i = 0; i < N; i++) if (!(z[i].w2 < N)) - cl_abort(); + throw runtime_exception(); #endif // Add result to destptr[-destlen..-1]: { @@ -775,7 +775,7 @@ static void mulu_fft_modp (const uintD* sourceptr1, uintC len1, // ac2 = 0. if (ac1 > 0) { if (!((i += 2) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); if ((ac0 += tmp) < tmp) ++ac1; @@ -787,24 +787,24 @@ static void mulu_fft_modp (const uintD* sourceptr1, uintC len1, lsshrink(ptr); if (ac1 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } else if (ac0 > 0) { if (!((i += 1) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); ac0 += tmp; lspref(ptr,0) = ac0; lsshrink(ptr); if (ac0 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } } #ifdef DEBUG_FFTP // If destlenp < N, check that the remaining z[i] are 0. for (i = destlenp; i < N; i++) if (z[i].w2 > 0 || z[i].w1 > 0 || z[i].w0 > 0) - cl_abort(); + throw runtime_exception(); #endif } // Decrement len2. diff --git a/src/base/digitseq/cl_DS_mul_fftp3.h b/src/base/digitseq/cl_DS_mul_fftp3.h index 0af1353..d857eea 100644 --- a/src/base/digitseq/cl_DS_mul_fftp3.h +++ b/src/base/digitseq/cl_DS_mul_fftp3.h @@ -86,7 +86,7 @@ static const fftp3_word fftp3_roots_of_1 [27+1] = #define FFTP3_BACKWARD CLEVER #ifdef DEBUG_FFTP3_OPERATIONS -#define check_fftp3_word(x) if ((x.w1 >= p1) || (x.w2 >= p2) || (x.w3 >= p3)) cl_abort() +#define check_fftp3_word(x) if ((x.w1 >= p1) || (x.w2 >= p2) || (x.w3 >= p3)) throw runtime_exception() #else #define check_fftp3_word(x) #endif @@ -290,7 +290,7 @@ static void mulp3_doublecheck (const fftp3_word& a, const fftp3_word& b, fftp3_w mulp3(ma,mb, or); mulp3(a,b, r); if (!((r.w1 == or.w1) && (r.w2 == or.w2) && (r.w3 == or.w3))) - cl_abort(); + throw runtime_exception(); } #define mulp3 mulp3_doublecheck #endif /* DEBUG_FFTP3_OPERATIONS */ @@ -350,10 +350,10 @@ static void fftp3_convolution (const uintL n, const uintC N, // N = 2^n var fftp3_word w_N; mulp3(w[N-1],fftp3_roots_of_1[n], w_N); if (!(w_N.w1 == 1 && w_N.w2 == 1 && w_N.w3 == 1)) - cl_abort(); + throw runtime_exception(); w_N = w[N>>1]; if (!(w_N.w1 == p1-1 && w_N.w2 == p2-1 && w_N.w3 == p3-1)) - cl_abort(); + throw runtime_exception(); } #endif var bool squaring = (x == y); @@ -565,7 +565,7 @@ static void mulu_fft_modp3 (const uintD* sourceptr1, uintC len1, mulu_loop_lsp(lspref(sourceptr2,0),sourceptr1,tmpptr,len1); if (addto_loop_lsp(tmpptr,destptr,len1+1)) if (inc_loop_lsp(destptr lspop (len1+1),destlen-(len1+1))) - cl_abort(); + throw runtime_exception(); } else { var uintC destlenp = len1 + len2p - 1; // destlenp = min(N,destlen-1). @@ -603,7 +603,7 @@ static void mulu_fft_modp3 (const uintD* sourceptr1, uintC len1, combinep3(z[i],arrayLSDptr(z_i,3)); #ifdef DEBUG_FFTP3 if (!(arrayLSref(z_i,3,2) < N)) - cl_abort(); + throw runtime_exception(); #endif // Add z[i] to the accumulator. tmp = arrayLSref(z_i,3,0); @@ -631,7 +631,7 @@ static void mulu_fft_modp3 (const uintD* sourceptr1, uintC len1, // ac2 = 0. if (ac1 > 0) { if (!((i += 2) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); if ((ac0 += tmp) < tmp) ++ac1; @@ -643,24 +643,24 @@ static void mulu_fft_modp3 (const uintD* sourceptr1, uintC len1, lsshrink(ptr); if (ac1 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } else if (ac0 > 0) { if (!((i += 1) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); ac0 += tmp; lspref(ptr,0) = ac0; lsshrink(ptr); if (ac0 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } } #ifdef DEBUG_FFTP3 // If destlenp < N, check that the remaining z[i] are 0. for (i = destlenp; i < N; i++) if (z[i].w1 > 0 || z[i].w2 > 0 || z[i].w3 > 0) - cl_abort(); + throw runtime_exception(); #endif } // Decrement len2. diff --git a/src/base/digitseq/cl_DS_mul_fftp3m.h b/src/base/digitseq/cl_DS_mul_fftp3m.h index 801d171..0aed00b 100644 --- a/src/base/digitseq/cl_DS_mul_fftp3m.h +++ b/src/base/digitseq/cl_DS_mul_fftp3m.h @@ -222,7 +222,7 @@ static const fftp3m_word fftp3m_roots_of_1 [26+1] = #define FFTP3M_BACKWARD CLEVER #ifdef DEBUG_FFTP3M_OPERATIONS -#define check_fftp3m_word(x) if ((x.w1 >= p1) || (x.w2 >= p2) || (x.w3 >= p3)) cl_abort() +#define check_fftp3m_word(x) if ((x.w1 >= p1) || (x.w2 >= p2) || (x.w3 >= p3)) throw runtime_exception() #else #define check_fftp3m_word(x) #endif @@ -349,7 +349,7 @@ static void combinep3m (const fftp3m_word& r, uintD* resLSDptr) #endif #ifdef DEBUG_FFTP3M_OPERATIONS if (compare_loop_msp(sumLSDptr lspop 3,arrayMSDptr(p123,3),3) >= 0) - cl_abort(); + throw runtime_exception(); #endif // Renormalize the division's remainder: shift right by 4 bits. shiftrightcopy_loop_msp(sumLSDptr lspop 3,resLSDptr lspop 3,3,4,0); @@ -422,7 +422,7 @@ static void mulp3m (const fftp3m_word& a, const fftp3m_word& b, fftp3m_word& res divu_6432_3232(hi,lo,p, ,tmp=); \ if (tmp != 0) { tmp = p-tmp; } \ if (tmp != r) \ - cl_abort(); \ + throw runtime_exception(); \ * endif DEBUG_FFTP3M_OPERATIONS */ \ result_zuweisung r; \ } @@ -465,7 +465,7 @@ static void mulp3m_doublecheck (const fftp3m_word& a, const fftp3m_word& b, fftp mulp3m(ma,mb, or); mulp3m(a,b, r); if (!((r.w1 == or.w1) && (r.w2 == or.w2) && (r.w3 == or.w3))) - cl_abort(); + throw runtime_exception(); } #define mulp3m mulp3m_doublecheck #endif /* DEBUG_FFTP3M_OPERATIONS */ @@ -527,12 +527,12 @@ static void fftp3m_convolution (const uintL n, const uintC N, // N = 2^n if (!( w_N.w1 == (uint32)1<<n1 && w_N.w2 == (uint32)1<<n2 && w_N.w3 == (uint32)1<<n3)) - cl_abort(); + throw runtime_exception(); w_N = w[N>>1]; if (!( w_N.w1 == p1-((uint32)1<<n1) && w_N.w2 == p2-((uint32)1<<n2) && w_N.w3 == p3-((uint32)1<<n3))) - cl_abort(); + throw runtime_exception(); } #endif var bool squaring = (x == y); @@ -744,7 +744,7 @@ static void mulu_fft_modp3m (const uintD* sourceptr1, uintC len1, mulu_loop_lsp(lspref(sourceptr2,0),sourceptr1,tmpptr,len1); if (addto_loop_lsp(tmpptr,destptr,len1+1)) if (inc_loop_lsp(destptr lspop (len1+1),destlen-(len1+1))) - cl_abort(); + throw runtime_exception(); } else { var uintC destlenp = len1 + len2p - 1; // destlenp = min(N,destlen-1). @@ -782,7 +782,7 @@ static void mulu_fft_modp3m (const uintD* sourceptr1, uintC len1, combinep3m(z[i],arrayLSDptr(z_i,3)); #ifdef DEBUG_FFTP3M if (!(arrayLSref(z_i,3,2) < N)) - cl_abort(); + throw runtime_exception(); #endif // Add z[i] to the accumulator. tmp = arrayLSref(z_i,3,0); @@ -810,7 +810,7 @@ static void mulu_fft_modp3m (const uintD* sourceptr1, uintC len1, // ac2 = 0. if (ac1 > 0) { if (!((i += 2) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); if ((ac0 += tmp) < tmp) ++ac1; @@ -822,24 +822,24 @@ static void mulu_fft_modp3m (const uintD* sourceptr1, uintC len1, lsshrink(ptr); if (ac1 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } else if (ac0 > 0) { if (!((i += 1) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); ac0 += tmp; lspref(ptr,0) = ac0; lsshrink(ptr); if (ac0 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } } #ifdef DEBUG_FFTP3M // If destlenp < N, check that the remaining z[i] are 0. for (i = destlenp; i < N; i++) if (z[i].w1 > 0 || z[i].w2 > 0 || z[i].w3 > 0) - cl_abort(); + throw runtime_exception(); #endif } // Decrement len2. diff --git a/src/base/digitseq/cl_DS_mul_fftr.h b/src/base/digitseq/cl_DS_mul_fftr.h index 588f102..d99da53 100644 --- a/src/base/digitseq/cl_DS_mul_fftr.h +++ b/src/base/digitseq/cl_DS_mul_fftr.h @@ -197,8 +197,7 @@ #include "cln/floatparam.h" -#include "cln/io.h" -#include "cln/abort.h" +#include "cln/exception.h" #if defined(HAVE_LONGDOUBLE) && (long_double_mant_bits > double_mant_bits) && (defined(__i386__) || defined(__m68k__) || (defined(__sparc__) && 0)) @@ -413,7 +412,7 @@ static uintC shuffle (uintL n, uintC x) } x >>= 1; } while (!(--n == 0)); - cl_abort(); + throw runtime_exception(); } #if 0 // unused @@ -431,7 +430,7 @@ static uintC invshuffle (uintL n, uintC x) } v <<= 1; } while (!(--n == 0)); - cl_abort(); + throw runtime_exception(); } #endif @@ -714,8 +713,7 @@ static void fill_factor (uintC N, fftr_real* x, uintL l, if (max_l(2) > intDsize && l > intDsize) { // l > intDsize if (max_l(2) > 64 && l > 64) { - fprint(std::cerr, "FFT problem: l > 64 not supported by pow2_table\n"); - cl_abort(); + throw runtime_exception("FFT problem: l > 64 not supported by pow2_table"); } var fftr_real carry = 0; var sintL carrybits = 0; // number of bits in carry (>=0, <l) @@ -738,11 +736,11 @@ static void fill_factor (uintC N, fftr_real* x, uintL l, i++; } if (i > N) - cl_abort(); + throw runtime_exception(); } else if (max_l(2) >= intDsize && l == intDsize) { // l = intDsize if (len > N) - cl_abort(); + throw runtime_exception(); for (i = 0; i < len; i++) { var uintD digit = lsprefnext(sourceptr); x[i] = (fftr_real)digit; @@ -769,14 +767,14 @@ static void fill_factor (uintC N, fftr_real* x, uintL l, } while (carrybits > 0) { if (!(i < N)) - cl_abort(); + throw runtime_exception(); x[i] = (fftr_real)(carry & l_mask); carry >>= l; carrybits -= l; i++; } if (len > 0) - cl_abort(); + throw runtime_exception(); } for ( ; i < N; i++) x[i] = (fftr_real)0; @@ -929,7 +927,7 @@ static uintD* unfill_product (uintL n, uintC N, // N = 2^n if (!(digit >= (fftr_real)0 && z[i] > digit - (fftr_real)0.5 && z[i] < digit + (fftr_real)0.5)) - cl_abort(); + throw runtime_exception(); #endif if (shift > 0) digit = digit * fftr_pow2_table[shift]; @@ -987,8 +985,7 @@ static inline void mulu_fftr_nocheck (const uintD* sourceptr1, uintC len1, for ( ; ; k++) { if (k >= sizeof(max_l_table)/sizeof(max_l_table[0]) || max_l_table[k] <= 0) { - fprint(std::cerr, "FFT problem: numbers too big, floating point precision not sufficient\n"); - cl_abort(); + throw runtime_exception("FFT problem: numbers too big, floating point precision not sufficient"); } if (2*ceiling(len1*intDsize,max_l_table[k])-1 <= ((uintC)1 << k)) break; @@ -1040,7 +1037,7 @@ static inline void mulu_fftr_nocheck (const uintD* sourceptr1, uintC len1, mulu_loop_lsp(lspref(sourceptr2,0),sourceptr1,tmpptr,len1); if (addto_loop_lsp(tmpptr,destptr,len1+1)) if (inc_loop_lsp(destptr lspop (len1+1),destlen-(len1+1))) - cl_abort(); + throw runtime_exception(); } else { var bool squaring = ((sourceptr1 == sourceptr2) && (len1 == len2p)); // Fill factor x. @@ -1061,7 +1058,7 @@ static inline void mulu_fftr_nocheck (const uintD* sourceptr1, uintC len1, for (var uintC i = 0; i < N; i++) if (!(z[i] > re_lo_limit && z[i] < re_hi_limit)) - cl_abort(); + throw runtime_exception(); } #endif var uintD* tmpLSDptr = arrayLSDptr(tmpprod,tmpprod_len); @@ -1073,16 +1070,16 @@ static inline void mulu_fftr_nocheck (const uintD* sourceptr1, uintC len1, tmpMSDptr - tmpLSDptr; #endif if (tmplen > tmpprod_len) - cl_abort(); + throw runtime_exception(); // Add result to destptr[-destlen..-1]: if (tmplen > destlen) { if (test_loop_msp(tmpMSDptr,tmplen-destlen)) - cl_abort(); + throw runtime_exception(); tmplen = destlen; } if (addto_loop_lsp(tmpLSDptr,destptr,tmplen)) if (inc_loop_lsp(destptr lspop tmplen,destlen-tmplen)) - cl_abort(); + throw runtime_exception(); } // Decrement len2. destptr = destptr lspop len2p; @@ -1137,7 +1134,6 @@ static void mulu_fftr (const uintD* sourceptr1, uintC len1, var uintD checksum = multiply_checksum(checksum1,checksum2); mulu_fftr_nocheck(sourceptr1,len1,sourceptr2,len2,destptr); if (!(checksum == compute_checksum(destptr,len1+len2))) { - fprint(std::cerr, "FFT problem: checksum error\n"); - cl_abort(); + throw runtime_exception("FFT problem: checksum error."); } } diff --git a/src/base/digitseq/cl_DS_mul_nuss.h b/src/base/digitseq/cl_DS_mul_nuss.h index f6968e3..fb475e5 100644 --- a/src/base/digitseq/cl_DS_mul_nuss.h +++ b/src/base/digitseq/cl_DS_mul_nuss.h @@ -409,7 +409,7 @@ static void mul_doublecheck (const nuss_inword& a, const nuss_inword& b, nuss_ou subfrom_loop_lsp(arrayLSDptr(a._iw,2),arrayLSDptr(or._ow,4) lspop 2,2); mul(a,b, r); if (compare_loop_msp(arrayMSDptr(r._ow,4),arrayMSDptr(or._ow,4),4)) - cl_abort(); + throw runtime_exception(); } #define mul mul_doublecheck #endif @@ -739,7 +739,7 @@ static inline void shift (const nuss_outword& a, nuss_outword& b) #elif defined(NUSS_OUT_EXTERNAL_LOOPS) #ifdef DEBUG_NUSS if (shiftrightcopy_loop_msp(arrayMSDptr(a._ow,4),arrayMSDptr(b._ow,4),4,1,mspref(arrayMSDptr(a._ow,4),0)>>31)) - cl_abort(); + throw runtime_exception(); #else shiftrightcopy_loop_msp(arrayMSDptr(a._ow,4),arrayMSDptr(b._ow,4),4,1,mspref(arrayMSDptr(a._ow,4),0)>>31); #endif @@ -760,7 +760,7 @@ static inline void shift (const nuss_outword& a, nuss_outword& b) #ifdef DEBUG_NUSS carry = tmp << 31; if (carry) - cl_abort(); + throw runtime_exception(); #endif #endif } @@ -915,7 +915,7 @@ static inline void shift (const nuss_outword& a, nuss_outword& b) #ifdef NUSS_OUT_EXTERNAL_LOOPS #ifdef DEBUG_NUSS if (shiftrightcopy_loop_msp(arrayMSDptr(a._ow,3),arrayMSDptr(b._ow,3),3,1,mspref(arrayMSDptr(a._ow,3),0)>>63)) - cl_abort(); + throw runtime_exception(); #else shiftrightcopy_loop_msp(arrayMSDptr(a._ow,3),arrayMSDptr(b._ow,3),3,1,mspref(arrayMSDptr(a._ow,3),0)>>63); #endif @@ -933,7 +933,7 @@ static inline void shift (const nuss_outword& a, nuss_outword& b) #ifdef DEBUG_NUSS carry = tmp << 63; if (carry) - cl_abort(); + throw runtime_exception(); #endif #endif } @@ -1390,7 +1390,7 @@ static void mulu_nussbaumer (const uintD* sourceptr1, uintC len1, mulu_loop_lsp(lspref(sourceptr2,0),sourceptr1,tmpptr,len1); if (addto_loop_lsp(tmpptr,destptr,len1+1)) if (inc_loop_lsp(destptr lspop (len1+1),destlen-(len1+1))) - cl_abort(); + throw runtime_exception(); } else { var uintC destlenp = len1 + len2p - 1; // destlenp = min(N,destlen-1). @@ -1426,7 +1426,7 @@ static void mulu_nussbaumer (const uintD* sourceptr1, uintC len1, // Check result. for (i = 0; i < N; i++) if (!(z[i].ow3 == 0)) - cl_abort(); + throw runtime_exception(); #endif // Add result to destptr[-destlen..-1]: { @@ -1463,7 +1463,7 @@ static void mulu_nussbaumer (const uintD* sourceptr1, uintC len1, // ac2 = 0. if (ac1 > 0) { if (!((i += 2) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); if ((ac0 += tmp) < tmp) ++ac1; @@ -1475,24 +1475,24 @@ static void mulu_nussbaumer (const uintD* sourceptr1, uintC len1, lsshrink(ptr); if (ac1 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } else if (ac0 > 0) { if (!((i += 1) <= destlen)) - cl_abort(); + throw runtime_exception(); tmp = lspref(ptr,0); ac0 += tmp; lspref(ptr,0) = ac0; lsshrink(ptr); if (ac0 < tmp) if (inc_loop_lsp(ptr,destlen-i)) - cl_abort(); + throw runtime_exception(); } } #ifdef DEBUG_NUSS // If destlenp < N, check that the remaining z[i] are 0. for (i = destlenp; i < N; i++) if (z[i].ow2 > 0 || z[i].ow1 > 0 || z[i].ow0 > 0) - cl_abort(); + throw runtime_exception(); #endif } // Decrement len2. diff --git a/src/base/digitseq/cl_DS_recip.cc b/src/base/digitseq/cl_DS_recip.cc index a4ed47a..67680ef 100644 --- a/src/base/digitseq/cl_DS_recip.cc +++ b/src/base/digitseq/cl_DS_recip.cc @@ -9,8 +9,6 @@ // Implementation. -#include "cln/abort.h" - namespace cln { // Compute the reciprocal value of a digit sequence. diff --git a/src/base/digitseq/cl_DS_recipsqrt.cc b/src/base/digitseq/cl_DS_recipsqrt.cc index e561c54..d68c5a1 100644 --- a/src/base/digitseq/cl_DS_recipsqrt.cc +++ b/src/base/digitseq/cl_DS_recipsqrt.cc @@ -10,7 +10,7 @@ // Implementation. #include "cl_low.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -138,24 +138,24 @@ namespace cln { // xm*yn*yn < 1 { neg_loop_lsp(y3_MSDptr mspop (m+2),m+2); mspref(y3_MSDptr,0) += 1; - if (test_loop_msp(y3_MSDptr,n)) cl_abort(); // check 0 <= y3 < beta^-(n-1) + if (test_loop_msp(y3_MSDptr,n)) throw runtime_exception(); // check 0 <= y3 < beta^-(n-1) cl_UDS_mul(y_MSDptr mspop (n+2),n+2, y3_MSDptr mspop (m+2),m+2-n, y4_MSDptr mspop (m+4)); shift1right_loop_msp(y4_MSDptr,m+3-n,0); if (addto_loop_lsp(y4_MSDptr mspop (m+3-n),y_MSDptr mspop (m+2),m+3-n)) - if ((n<1) || inc_loop_lsp(y_MSDptr mspop (n-1),n-1)) cl_abort(); + if ((n<1) || inc_loop_lsp(y_MSDptr mspop (n-1),n-1)) throw runtime_exception(); } else // xm*yn*yn >= 1 (this can happen since xm >= xn) { mspref(y3_MSDptr,0) -= 1; - if (test_loop_msp(y3_MSDptr,n)) cl_abort(); // check 0 >= y3 > -beta^-(n-1) + if (test_loop_msp(y3_MSDptr,n)) throw runtime_exception(); // check 0 >= y3 > -beta^-(n-1) cl_UDS_mul(y_MSDptr mspop (n+2),n+2, y3_MSDptr mspop (m+2),m+2-n, y4_MSDptr mspop (m+4)); shift1right_loop_msp(y4_MSDptr,m+3-n,0); if (subfrom_loop_lsp(y4_MSDptr mspop (m+3-n),y_MSDptr mspop (m+2),m+3-n)) - if ((n<1) || dec_loop_lsp(y_MSDptr mspop (n-1),n-1)) cl_abort(); + if ((n<1) || dec_loop_lsp(y_MSDptr mspop (n-1),n-1)) throw runtime_exception(); } n = m; // n = ceiling(b_len/2^k) limbs of y have now been computed. diff --git a/src/base/digitseq/cl_DS_sqrt.cc b/src/base/digitseq/cl_DS_sqrt.cc index 382c391..d3afef7 100644 --- a/src/base/digitseq/cl_DS_sqrt.cc +++ b/src/base/digitseq/cl_DS_sqrt.cc @@ -10,7 +10,7 @@ // Implementation. #include "cl_low.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -155,7 +155,7 @@ cl_boolean cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDpt // 1/4 <= d < 2, | sqrt(a) - d | < beta^-n. if (mspref(d_MSDptr,0) > 0) { dec_loop_lsp(d_MSDptr mspop (n+1),n+1); - if (mspref(d_MSDptr,0) > 0) cl_abort(); + if (mspref(d_MSDptr,0) > 0) throw runtime_exception(); } // D is our guess for B. Square to see how much we have to correct. cl_UDS_mul_square(d_MSDptr mspop (1+n),n,d2_MSDptr mspop 2*n); @@ -171,13 +171,13 @@ cl_boolean cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDpt { dec_loop_lsp(b_->LSDptr,n); dec_loop_lsp(d_MSDptr mspop (1+n),1+n); // store 2*D+1 if (!addto_loop_lsp(d_MSDptr mspop (1+n),a_MSDptr mspop 2*n,1+n)) - cl_abort(); + throw runtime_exception(); if (!inc_loop_lsp(a_MSDptr mspop (n-1),n-1)) - cl_abort(); + throw runtime_exception(); } else if (test_loop_msp(a_MSDptr,n-1)) // guessed way too low - cl_abort(); + throw runtime_exception(); else if (compare_loop_msp(a_MSDptr mspop (n-1),d_MSDptr,1+n) > 0) // guessed too low, increment D { inc_loop_lsp(b_->LSDptr,n); @@ -185,7 +185,7 @@ cl_boolean cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDpt subfrom_loop_lsp(d_MSDptr mspop (1+n),a_MSDptr mspop 2*n,1+n); inc_loop_lsp(d_MSDptr mspop (1+n),1+n); // store 2*D if (compare_loop_msp(a_MSDptr mspop (n-1),d_MSDptr,1+n) > 0) - cl_abort(); + throw runtime_exception(); } else // guessed ok diff --git a/src/base/hash/cl_hash.h b/src/base/hash/cl_hash.h index adf8466..92576f3 100644 --- a/src/base/hash/cl_hash.h +++ b/src/base/hash/cl_hash.h @@ -5,7 +5,7 @@ #include "cln/object.h" #include "cln/malloc.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_iterator.h" namespace cln { @@ -132,7 +132,7 @@ protected: return index; } #if !(defined(__hppa__) && !defined(__GNUC__)) // workaround HP CC problem - cl_abort(); + throw runtime_exception(); #endif return -1; // dummy } @@ -170,7 +170,7 @@ public: htentry& next () { if (_index < 0) - cl_abort(); + throw runtime_exception(); var long old_index = _index; do { _index--; } while (_index >= 0 && _entries[_index].next < 0); diff --git a/src/base/hash/cl_hash1.h b/src/base/hash/cl_hash1.h index 9dd37cf..0602880 100644 --- a/src/base/hash/cl_hash1.h +++ b/src/base/hash/cl_hash1.h @@ -49,7 +49,7 @@ public: var long index = this->_slots[hashcode(key) % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,this->_entries[index].entry.key)) return &this->_entries[index].entry.val; index = this->_entries[index].next - 1; @@ -65,7 +65,7 @@ public: var long index = this->_slots[hcode % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,this->_entries[index].entry.key)) { this->_entries[index].entry.val = val; return; @@ -89,7 +89,7 @@ public: while (*_index > 0) { var long index = *_index - 1; if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,this->_entries[index].entry.key)) { // Remove _entries[index].entry *_index = this->_entries[index].next; diff --git a/src/base/hash/cl_hash1weak.h b/src/base/hash/cl_hash1weak.h index e351332..071cf85 100644 --- a/src/base/hash/cl_hash1weak.h +++ b/src/base/hash/cl_hash1weak.h @@ -63,7 +63,7 @@ private: ht->remove(entry.key); if (entry.val.pointer_p()) { var cl_heap* p = entry.val.heappointer; - if (!(--p->refcount == 0)) cl_abort(); + if (!(--p->refcount == 0)) throw runtime_exception(); cl_free_heap_object(p); } removed++; diff --git a/src/base/hash/cl_hash2.h b/src/base/hash/cl_hash2.h index 3f7a20f..da911a7 100644 --- a/src/base/hash/cl_hash2.h +++ b/src/base/hash/cl_hash2.h @@ -47,7 +47,7 @@ public: var long index = this->_slots[hashcode(key1,key2) % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key1,this->_entries[index].entry.key1) && equal(key2,this->_entries[index].entry.key2)) return &this->_entries[index].entry.val; @@ -64,7 +64,7 @@ public: var long index = this->_slots[hcode % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key1,this->_entries[index].entry.key1) && equal(key2,this->_entries[index].entry.key2)) { this->_entries[index].entry.val = val; @@ -89,7 +89,7 @@ public: while (*_index > 0) { var long index = *_index - 1; if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key1,this->_entries[index].entry.key1) && equal(key2,this->_entries[index].entry.key2)) { // Remove _entries[index].entry diff --git a/src/base/hash/cl_hash2weak.h b/src/base/hash/cl_hash2weak.h index c3c4279..f14d585 100644 --- a/src/base/hash/cl_hash2weak.h +++ b/src/base/hash/cl_hash2weak.h @@ -63,7 +63,7 @@ private: ht->remove(entry.key1,entry.key2); if (entry.val.pointer_p()) { var cl_heap* p = entry.val.heappointer; - if (!(--p->refcount == 0)) cl_abort(); + if (!(--p->refcount == 0)) throw runtime_exception(); cl_free_heap_object(p); } removed++; diff --git a/src/base/hash/cl_hashset.h b/src/base/hash/cl_hashset.h index 2c13e88..15ced7b 100644 --- a/src/base/hash/cl_hashset.h +++ b/src/base/hash/cl_hashset.h @@ -38,7 +38,7 @@ public: var long index = this->_slots[hashcode(key) % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,this->_entries[index].entry.key)) return true; index = this->_entries[index].next - 1; @@ -54,7 +54,7 @@ public: var long index = this->_slots[hcode % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,this->_entries[index].entry.key)) return; index = this->_entries[index].next - 1; @@ -76,7 +76,7 @@ public: while (*_index > 0) { var long index = *_index - 1; if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,this->_entries[index].entry.key)) { // Remove _entries[index].entry *_index = this->_entries[index].next; diff --git a/src/base/hash/cl_hashuniq.h b/src/base/hash/cl_hashuniq.h index 81af352..a5df68b 100644 --- a/src/base/hash/cl_hashuniq.h +++ b/src/base/hash/cl_hashuniq.h @@ -49,7 +49,7 @@ public: var long index = this->_slots[hashcode(key) % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,hashkey(this->_entries[index].entry.val))) return &this->_entries[index].entry.val; index = this->_entries[index].next - 1; @@ -65,7 +65,7 @@ public: var long index = this->_slots[hcode % this->_modulus] - 1; while (index >= 0) { if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,hashkey(this->_entries[index].entry.val))) return; index = this->_entries[index].next - 1; @@ -87,7 +87,7 @@ public: while (*_index > 0) { var long index = *_index - 1; if (!(index < this->_size)) - cl_abort(); + throw runtime_exception(); if (equal(key,hashkey(this->_entries[index].entry.val))) { // Remove _entries[index].entry *_index = this->_entries[index].next; diff --git a/src/base/hash/cl_hashuniqweak.h b/src/base/hash/cl_hashuniqweak.h index 7aca192..fd1793f 100644 --- a/src/base/hash/cl_hashuniqweak.h +++ b/src/base/hash/cl_hashuniqweak.h @@ -63,7 +63,7 @@ private: ht->remove(hashkey(v)); if (v.pointer_p()) { var cl_heap* p = v.heappointer; - if (!(--p->refcount == 0)) cl_abort(); + if (!(--p->refcount == 0)) throw runtime_exception(); cl_free_heap_object(p); } removed++; diff --git a/src/base/input/cl_read_bad_syntax_exception.cc b/src/base/input/cl_read_bad_syntax_exception.cc new file mode 100644 index 0000000..8b7928f --- /dev/null +++ b/src/base/input/cl_read_bad_syntax_exception.cc @@ -0,0 +1,32 @@ +// read_number_bad_syntax_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cln/number_io.h" + + +// Implementation. + +#include <sstream> +#include "cln/io.h" + +namespace cln { + +static inline const std::string +read_number_bad_syntax_msg (const char * string, const char * string_limit) +{ + std::ostringstream buf; + fprint(buf, "Illegal number syntax: \""); + for (const char * ptr = string; ptr != string_limit; ptr++) + fprintchar(buf, *ptr); + fprint(buf, "\""); + return buf.str(); +} + +read_number_bad_syntax_exception::read_number_bad_syntax_exception (const char * string, const char * string_limit) + : read_number_exception(read_number_bad_syntax_msg(string, string_limit)) +{} + +} // namespace cln diff --git a/src/base/input/cl_read_err_eof.cc b/src/base/input/cl_read_eof_exception.cc similarity index 52% rename from src/base/input/cl_read_err_eof.cc rename to src/base/input/cl_read_eof_exception.cc index 5fc8318..db9e202 100644 --- a/src/base/input/cl_read_err_eof.cc +++ b/src/base/input/cl_read_eof_exception.cc @@ -1,4 +1,4 @@ -// read_number_eof(). +// read_number_eof_exception(). // General includes. #include "cl_sysdep.h" @@ -10,14 +10,11 @@ // Implementation. #include "cln/io.h" -#include "cln/abort.h" namespace cln { -void read_number_eof (void) -{ - fprint(std::cerr, "read_number: end of stream encountered\n"); - cl_abort(); -} +read_number_eof_exception::read_number_eof_exception () + : read_number_exception("read_number: end of stream encountered") +{} } // namespace cln diff --git a/src/base/input/cl_read_err_bad.cc b/src/base/input/cl_read_err_bad.cc deleted file mode 100644 index 023abb8..0000000 --- a/src/base/input/cl_read_err_bad.cc +++ /dev/null @@ -1,26 +0,0 @@ -// read_number_bad_syntax(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cln/number_io.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void read_number_bad_syntax (const char * string, const char * string_limit) -{ - fprint(std::cerr, "Illegal number syntax: \""); - for (const char * ptr = string; ptr != string_limit; ptr++) - fprintchar(std::cerr, *ptr); - fprint(std::cerr, "\"\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/base/input/cl_read_err_junk.cc b/src/base/input/cl_read_err_junk.cc deleted file mode 100644 index 8e62933..0000000 --- a/src/base/input/cl_read_err_junk.cc +++ /dev/null @@ -1,31 +0,0 @@ -// read_number_junk(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cln/number_io.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void read_number_junk (const char * string_rest, const char * string, const char * string_limit) -{ - fprint(std::cerr, "Junk after number: "); - { for (const char * ptr = string; ptr != string_rest; ptr++) - fprintchar(std::cerr, *ptr); - } - fprint(std::cerr, "\""); - { for (const char * ptr = string_rest; ptr != string_limit; ptr++) - fprintchar(std::cerr, *ptr); - } - fprint(std::cerr, "\"\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/base/input/cl_read_junk_exception.cc b/src/base/input/cl_read_junk_exception.cc new file mode 100644 index 0000000..85640c0 --- /dev/null +++ b/src/base/input/cl_read_junk_exception.cc @@ -0,0 +1,37 @@ +// read_number_junk_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cln/number_io.h" + + +// Implementation. + +#include <sstream> +#include "cln/io.h" + +namespace cln { + +static inline const std::string +read_number_junk_msg (const char * string_rest, const char * string, const char * string_limit) +{ + std::ostringstream buf; + fprint(buf, "Junk after number: "); + { for (const char * ptr = string; ptr != string_rest; ptr++) + fprintchar(buf, *ptr); + } + fprint(buf, "\""); + { for (const char * ptr = string_rest; ptr != string_limit; ptr++) + fprintchar(buf, *ptr); + } + fprint(buf, "\""); + return buf.str(); +} + +read_number_junk_exception::read_number_junk_exception (const char * string_rest, const char * string, const char * string_limit) + : read_number_exception(read_number_junk_msg(string_rest, string, string_limit)) +{} + +} // namespace cln diff --git a/src/base/proplist/cl_pl_add.cc b/src/base/proplist/cl_pl_add.cc index 3de5272..47e88e6 100644 --- a/src/base/proplist/cl_pl_add.cc +++ b/src/base/proplist/cl_pl_add.cc @@ -9,7 +9,7 @@ // Implementation. -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -19,7 +19,7 @@ void cl_property::dummy () {} void cl_property_list::add_property (cl_property* new_property) { if (new_property->next) - cl_abort(); + throw runtime_exception(); new_property->next = list; list = new_property; } diff --git a/src/base/ring/cl_no_ring.cc b/src/base/ring/cl_no_ring.cc index 86869bd..6c4f7a0 100644 --- a/src/base/ring/cl_no_ring.cc +++ b/src/base/ring/cl_no_ring.cc @@ -11,71 +11,85 @@ CL_PROVIDE(cl_no_ring) // Implementation. +#include <sstream> #include "cln/io.h" -#include "cln/abort.h" namespace cln { -nonreturning_function(static, uninitialized_ring, (void)); -static void uninitialized_ring () +uninitialized_ring_exception::uninitialized_ring_exception () + : runtime_exception("Uninitialized ring operation called.") +{} + +static inline const std::string +uninitialized_error_msg (const _cl_ring_element& obj) { - fprint(std::cerr, "Uninitialized ring operation called\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "Uninitialized ring element @0x"); + fprinthexadecimal(buf, (unsigned long)(void*)&obj); + fprint(buf, ": 0x"); + fprinthexadecimal(buf, (unsigned long)obj.rep.word); + return buf.str(); } -nonreturning_function(static, uninitialized_error, (const _cl_ring_element&)); -static void uninitialized_error (const _cl_ring_element& obj) +static inline const std::string +uninitialized_error_msg (const _cl_ring_element& obj_x, const _cl_ring_element& obj_y) { - 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(); + std::ostringstream buf; + fprint(buf, "Uninitialized ring elements @0x"); + fprinthexadecimal(buf, (unsigned long)(void*)&obj_x); + fprint(buf, ": 0x"); + fprinthexadecimal(buf, (unsigned long)obj_x.rep.word); + fprint(buf, ", @0x"); + fprinthexadecimal(buf, (unsigned long)(void*)&obj_y); + fprint(buf, ": 0x"); + fprinthexadecimal(buf, (unsigned long)obj_y.rep.word); + return buf.str(); } -#if (defined(__sparc__) && !defined(__GNUC__)) - // avoid Sun C++ 4.1 compiler bug - #define RETDUMMY return *(_cl_ring_element*)R -#else - #define RETDUMMY return *(_cl_ring_element*)0 -#endif +uninitialized_exception::uninitialized_exception (const _cl_ring_element& obj) + : runtime_exception(uninitialized_error_msg(obj)) +{} + +uninitialized_exception::uninitialized_exception (const _cl_ring_element& obj_x, const _cl_ring_element& obj_y) + : runtime_exception(uninitialized_error_msg(obj_x, obj_y)) +{} + static const _cl_ring_element dummy_op0 (cl_heap_ring* R) { unused R; - uninitialized_ring(); RETDUMMY; + throw uninitialized_ring_exception(); } static const _cl_ring_element dummy_op1 (cl_heap_ring* R, const _cl_ring_element& x) { unused R; - uninitialized_error(x); RETDUMMY; + throw uninitialized_exception(x); } static const _cl_ring_element dummy_op2 (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y) { unused R; - uninitialized_error(x); uninitialized_error(y); RETDUMMY; + throw uninitialized_exception(x, y); } static void dummy_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x) { unused R; unused stream; - uninitialized_error(x); + throw uninitialized_exception(x); } static cl_boolean dummy_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y) { unused R; - uninitialized_error(x); uninitialized_error(y); return cl_false; + throw uninitialized_exception(x, y); } #define dummy_zero dummy_op0 static cl_boolean dummy_zerop (cl_heap_ring* R, const _cl_ring_element& x) { unused R; - uninitialized_error(x); return cl_false; + throw uninitialized_exception(x); } #define dummy_plus dummy_op2 #define dummy_minus dummy_op2 @@ -86,7 +100,7 @@ static const _cl_ring_element dummy_canonhom (cl_heap_ring* R, const cl_I& x) { unused R; (void)&x; // unused x; - uninitialized_ring(); RETDUMMY; + throw uninitialized_ring_exception(); } #define dummy_mul dummy_op2 #define dummy_square dummy_op1 @@ -94,7 +108,7 @@ static const _cl_ring_element dummy_expt_pos (cl_heap_ring* R, const _cl_ring_el { unused R; (void)&y; // unused y; - uninitialized_error(x); RETDUMMY; + throw uninitialized_exception(x); } static cl_ring_setops dummy_setops = { diff --git a/src/base/string/cl_spushstring.h b/src/base/string/cl_spushstring.h index 0abfa51..eaae52e 100644 --- a/src/base/string/cl_spushstring.h +++ b/src/base/string/cl_spushstring.h @@ -6,7 +6,7 @@ #include "cln/object.h" #include "cln/malloc.h" #include "cl_sstring.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -56,7 +56,7 @@ inline uintL cl_spushstring::length () const } inline char cl_spushstring::operator[] (uintL i) const { - if (!(i < index)) cl_abort(); + if (!(i < index)) throw runtime_exception(); return buffer[i]; } diff --git a/src/base/symbol/cl_symbol.cc b/src/base/symbol/cl_symbol.cc index 0193027..7e86b79 100644 --- a/src/base/symbol/cl_symbol.cc +++ b/src/base/symbol/cl_symbol.cc @@ -92,7 +92,7 @@ cl_symbol::cl_symbol (const cl_string& s) symbol_table.put(s); sym_in_table = symbol_table.get(s); if (!sym_in_table) - cl_abort(); + throw runtime_exception(); } var cl_heap* p = sym_in_table->heappointer; cl_inc_pointer_refcount(p); diff --git a/src/complex/input/cl_N_read.cc b/src/complex/input/cl_N_read.cc index 0c36339..76fabe2 100644 --- a/src/complex/input/cl_N_read.cc +++ b/src/complex/input/cl_N_read.cc @@ -10,6 +10,7 @@ // Implementation. #include <cstring> +#include <sstream> #include "cln/input.h" #include "cln/real_io.h" #include "cln/float_io.h" @@ -19,7 +20,7 @@ #include "cl_I.h" #include "cl_F.h" #include "cl_C.h" -#include "cln/abort.h" +#include "cln/exception.h" #undef floor #include <cmath> @@ -59,7 +60,7 @@ static const cl_N read_complex_number_rest (const cl_read_flags& flags, const ch if (end_of_parse) \ { *end_of_parse = (ptr); } \ else \ - { if ((ptr) != string_limit) { read_number_junk((ptr),string,string_limit); } } + { if ((ptr) != string_limit) { throw read_number_junk_exception((ptr),string,string_limit); } } const cl_N read_complex (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse) { @@ -92,10 +93,10 @@ const cl_N read_complex (const cl_read_flags& flags, const char * string, const goto not_rational_syntax; var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr); if (!((base >= 2) && (base <= 36))) { - 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(); + std::ostringstream buf; + fprint(buf, "Base must be an integer in the range from 2 to 36, not "); + fprint(buf, base); + throw runtime_exception(buf.str()); } rational_base = FN_to_UV(base); ptr = base_end_ptr; break; @@ -297,7 +298,7 @@ not_complex_syntax: *end_of_parse = string; return 0; // dummy return } - read_number_bad_syntax(string,string_limit); + throw read_number_bad_syntax_exception(string,string_limit); } static const cl_N read_complex_number_rest (const cl_read_flags& flags, const char * string_rest, const char * string, const char * string_limit, const char * * end_of_parse, const cl_R& x) diff --git a/src/complex/input/cl_N_read_stream.cc b/src/complex/input/cl_N_read_stream.cc index 7199476..3f119c4 100644 --- a/src/complex/input/cl_N_read_stream.cc +++ b/src/complex/input/cl_N_read_stream.cc @@ -108,10 +108,10 @@ done: // Handle syntax error. syntax1: buffer.push(c); -syntax: read_number_bad_syntax(buffer.start_pointer(),buffer.end_pointer()); +syntax: throw read_number_bad_syntax_exception(buffer.start_pointer(),buffer.end_pointer()); // Handle premature EOF. -eof: read_number_eof(); +eof: throw read_number_eof_exception(); } } // namespace cln diff --git a/src/complex/misc/cl_N_as.cc b/src/complex/misc/cl_N_as.cc index 1b8f41f..15cccfd 100644 --- a/src/complex/misc/cl_N_as.cc +++ b/src/complex/misc/cl_N_as.cc @@ -10,6 +10,7 @@ // Implementation. #include "cl_N.h" +#include "cln/exception.h" namespace cln { @@ -40,7 +41,7 @@ const cl_N& cl_N_As (const cl_number& x, const char * filename, int line) DeclareType(cl_N,x); return x; } else - cl_as_error(x,"a number",filename,line); + throw as_exception(x,"a number",filename,line); } } // namespace cln diff --git a/src/complex/transcendental/cl_C_atanh_aux.cc b/src/complex/transcendental/cl_C_atanh_aux.cc index 42cae75..3b3014c 100644 --- a/src/complex/transcendental/cl_C_atanh_aux.cc +++ b/src/complex/transcendental/cl_C_atanh_aux.cc @@ -71,7 +71,7 @@ const cl_C_R atanh (const cl_R& x, const cl_R& y) var cl_R v; if (!minusp(xx)) { if (zerop(xx)) - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } v = 0; } else { // (1+x)/(1-x) < 0 -> Betrag nehmen, Imagin�rteil berechnen: @@ -112,7 +112,7 @@ const cl_C_R atanh (const cl_R& x, const cl_R& y) var cl_F num = _1_plus_x*_1_plus_x + yf_2; // (1+x)^2+y^2, ein Float >=0 var cl_F den = _1_minus_x*_1_minus_x + yf_2; // (1-x)^2+y^2, ein Float >=0 if (zerop(den)) - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } u = scale_float(ln(num/den),-2); } } diff --git a/src/complex/transcendental/cl_C_expt_C.cc b/src/complex/transcendental/cl_C_expt_C.cc index 151a9d2..5e042c9 100644 --- a/src/complex/transcendental/cl_C_expt_C.cc +++ b/src/complex/transcendental/cl_C_expt_C.cc @@ -184,7 +184,7 @@ const cl_N expt (const cl_N& x, const cl_N& y) if (rationalp(realpart(y))) // Realteil von y >0 exakt. return 0; if (!plusp(realpart(y))) // Realteil von y <=0 ? - cl_error_division_by_0(); + throw division_by_0_exception(); else { var cl_R f = contagion(contagion(x),contagion(y)); // ein Float, da sonst x = Fixnum 0 gewesen w�re diff --git a/src/complex/transcendental/cl_C_log.cc b/src/complex/transcendental/cl_C_log.cc index 6e3c680..c96577c 100644 --- a/src/complex/transcendental/cl_C_log.cc +++ b/src/complex/transcendental/cl_C_log.cc @@ -21,7 +21,7 @@ const cl_N log (const cl_N& x) // (complex (log (abs x)) (phase x)) var cl_R r = abs(x); if (zerop(r)) // (abs x) = 0 -> Error - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } return complex(ln(r),phase(x)); } diff --git a/src/complex/transcendental/cl_C_log2.cc b/src/complex/transcendental/cl_C_log2.cc index 86e22fa..0232c22 100644 --- a/src/complex/transcendental/cl_C_log2.cc +++ b/src/complex/transcendental/cl_C_log2.cc @@ -55,7 +55,7 @@ const cl_N log (const cl_N& a, const cl_N& b) { var cl_R angle = phase(a); if (eq(angle,0)) // = Fixnum 0 <==> (= a 0) -> Error - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } { DeclareType(cl_F,angle); var cl_F bf = cl_somefloat(b,angle); // (float b) im = angle / ln(bf); diff --git a/src/float/base/cl_F_err_nan.cc b/src/float/base/cl_F_err_nan.cc deleted file mode 100644 index f616ec5..0000000 --- a/src/float/base/cl_F_err_nan.cc +++ /dev/null @@ -1,23 +0,0 @@ -// cl_error_floating_point_overflow(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_F.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_error_floating_point_nan (void) -{ - fprint(std::cerr, "floating point NaN occurred.\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/float/base/cl_F_err_ov.cc b/src/float/base/cl_F_err_ov.cc deleted file mode 100644 index 270b052..0000000 --- a/src/float/base/cl_F_err_ov.cc +++ /dev/null @@ -1,23 +0,0 @@ -// cl_error_floating_point_overflow(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_F.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_error_floating_point_overflow (void) -{ - fprint(std::cerr, "Floating point overflow.\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/float/base/cl_F_err_un.cc b/src/float/base/cl_F_err_un.cc deleted file mode 100644 index 3ac0dcf..0000000 --- a/src/float/base/cl_F_err_un.cc +++ /dev/null @@ -1,23 +0,0 @@ -// cl_error_floating_point_underflow(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_F.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_error_floating_point_underflow (void) -{ - fprint(std::cerr, "Floating point underflow.\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/float/base/cl_F_nan_exception.cc b/src/float/base/cl_F_nan_exception.cc new file mode 100644 index 0000000..a1a70d3 --- /dev/null +++ b/src/float/base/cl_F_nan_exception.cc @@ -0,0 +1,20 @@ +// floating_point_nan_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cl_F.h" + + +// Implementation. + +#include "cln/io.h" + +namespace cln { + +floating_point_nan_exception::floating_point_nan_exception () + : floating_point_exception("floating point NaN occurred.") +{} + +} // namespace cln diff --git a/src/float/base/cl_F_overflow_exception.cc b/src/float/base/cl_F_overflow_exception.cc new file mode 100644 index 0000000..f35d7b7 --- /dev/null +++ b/src/float/base/cl_F_overflow_exception.cc @@ -0,0 +1,20 @@ +// floating_point_overflow_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cl_F.h" + + +// Implementation. + +#include "cln/io.h" + +namespace cln { + +floating_point_overflow_exception::floating_point_overflow_exception () + : floating_point_exception("floating point overflow.") +{} + +} // namespace cln diff --git a/src/float/base/cl_F_underflow_exception.cc b/src/float/base/cl_F_underflow_exception.cc new file mode 100644 index 0000000..ab717ae --- /dev/null +++ b/src/float/base/cl_F_underflow_exception.cc @@ -0,0 +1,20 @@ +// floating_point_underflow_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cl_F.h" + + +// Implementation. + +#include "cln/io.h" + +namespace cln { + +floating_point_underflow_exception::floating_point_underflow_exception () + : floating_point_exception("floating point underflow.") +{} + +} // namespace cln diff --git a/src/float/cl_F.h b/src/float/cl_F.h index c140642..a62329d 100644 --- a/src/float/cl_F.h +++ b/src/float/cl_F.h @@ -9,9 +9,6 @@ namespace cln { -nonreturning_function(extern, cl_error_floating_point_overflow, (void)); -nonreturning_function(extern, cl_error_floating_point_underflow, (void)); - #define underflow_allowed() (! cl_inhibit_floating_point_underflow) @@ -72,10 +69,6 @@ extern const cl_FF cl_LF_to_FF (const cl_LF& x); extern const cl_DF cl_LF_to_DF (const cl_LF& x); -// Fehlermeldung wegen NaN -nonreturning_function(extern, cl_error_floating_point_nan, (void)); - - // Runtime typing support. extern cl_class cl_class_ffloat; extern cl_class cl_class_dfloat; diff --git a/src/float/dfloat/cl_DF.h b/src/float/dfloat/cl_DF.h index ec81dc1..988553d 100644 --- a/src/float/dfloat/cl_DF.h +++ b/src/float/dfloat/cl_DF.h @@ -161,13 +161,13 @@ inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintQ mant) { if (exp < (sintL)(DF_exp_low-DF_exp_mid)) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_DF_0; } } else if (exp > (sintL)(DF_exp_high-DF_exp_mid)) - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } else return allocate_dfloat ( ((sint64)sign & bit(63)) /* Vorzeichen */ @@ -188,13 +188,13 @@ inline const cl_DF encode_DF (cl_signean sign, sintL exp, uintL manthi, uintL ma { if (exp < (sintL)(DF_exp_low-DF_exp_mid)) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_DF_0; } } else if (exp > (sintL)(DF_exp_high-DF_exp_mid)) - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } else return allocate_dfloat ( ((sint32)sign & bit(31)) /* Vorzeichen */ @@ -234,7 +234,7 @@ inline double DF_to_double (const cl_DF& obj) ) \ && underflow_allowed() \ ) \ - { cl_error_floating_point_underflow(); } /* subnormal oder noch kleiner -> Underflow */\ + { throw floating_point_underflow_exception(); } /* subnormal oder noch kleiner -> Underflow */\ else \ { ergebnis_zuweisung cl_DF_0; } /* +/- 0.0 -> 0.0 */ \ } \ @@ -242,12 +242,12 @@ inline double DF_to_double (const cl_DF& obj) && (((~_erg.eksplicit) & ((uint64)bit(DF_exp_len+DF_mant_len)-bit(DF_mant_len))) == 0) /* e=2047 ? */\ ) \ { if (maybe_nan && !((_erg.eksplicit<<(64-DF_mant_len)) == 0)) \ - { cl_error_division_by_0(); } /* NaN, also Singularit�t -> "Division durch 0" */\ + { throw division_by_0_exception(); } /* NaN, also Singularit�t -> "Division durch 0" */\ else /* Infinity */ \ if (!maybe_overflow || maybe_divide_0) \ - { cl_error_division_by_0(); } /* Infinity, Division durch 0 */\ + { throw division_by_0_exception(); } /* Infinity, Division durch 0 */\ else \ - { cl_error_floating_point_overflow(); } /* Infinity, Overflow */\ + { throw floating_point_overflow_exception(); } /* Infinity, Overflow */\ } \ else \ { ergebnis_zuweisung allocate_dfloat(_erg.eksplicit); } \ @@ -262,7 +262,7 @@ inline double DF_to_double (const cl_DF& obj) ) ) \ && underflow_allowed() \ ) \ - { cl_error_floating_point_underflow(); } /* subnormal oder noch kleiner -> Underflow */\ + { throw floating_point_underflow_exception(); } /* subnormal oder noch kleiner -> Underflow */\ else \ { ergebnis_zuweisung cl_DF_0; } /* +/- 0.0 -> 0.0 */\ } \ @@ -270,12 +270,12 @@ inline double DF_to_double (const cl_DF& obj) && (((~_erg.eksplicit.semhi) & ((uint32)bit(DF_exp_len+DF_mant_len-32)-bit(DF_mant_len-32))) == 0) /* e=2047 ? */\ ) \ { if (maybe_nan && !(((_erg.eksplicit.semhi<<(64-DF_mant_len)) == 0) && (_erg.eksplicit.mlo==0))) \ - { cl_error_division_by_0(); } /* NaN, also Singularit�t -> "Division durch 0" */\ + { throw division_by_0_exception(); } /* NaN, also Singularit�t -> "Division durch 0" */\ else /* Infinity */\ if (!maybe_overflow || maybe_divide_0) \ - { cl_error_division_by_0(); } /* Infinity, Division durch 0 */\ + { throw division_by_0_exception(); } /* Infinity, Division durch 0 */\ else \ - { cl_error_floating_point_overflow(); } /* Infinity, Overflow */\ + { throw floating_point_overflow_exception(); } /* Infinity, Overflow */\ } \ else \ { ergebnis_zuweisung allocate_dfloat(_erg.eksplicit.semhi,_erg.eksplicit.mlo); } \ diff --git a/src/float/dfloat/conv/cl_DF_from_double.cc b/src/float/dfloat/conv/cl_DF_from_double.cc index f6c4605..7e3ffe9 100644 --- a/src/float/dfloat/conv/cl_DF_from_double.cc +++ b/src/float/dfloat/conv/cl_DF_from_double.cc @@ -19,20 +19,20 @@ cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val_) if (exp == 0) // e=0 ? // vorzeichenbehaftete 0.0 oder subnormale Zahl { if (!((val << 1) == 0) && underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_DF_0; } // +/- 0.0 -> 0.0 } elif (exp == 2047) // e=2047 ? { if (!((val << (64-DF_mant_len)) == 0)) - { cl_error_floating_point_nan(); } // NaN + { throw floating_point_nan_exception(); } // NaN else - { cl_error_floating_point_overflow(); } // Infinity, Overflow + { throw floating_point_overflow_exception(); } // Infinity, Overflow } else { // Der Exponent mu� um DF_exp_mid-1022 erh�ht werden. if ((DF_exp_mid>1022) && (exp > DF_exp_high-DF_exp_mid+1022)) - { cl_error_floating_point_overflow(); } // Overflow + { throw floating_point_overflow_exception(); } // Overflow val += (sint64)(DF_exp_mid - 1022) << DF_mant_len; return allocate_dfloat(val); } @@ -41,20 +41,20 @@ cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val_) if (exp == 0) // e=0 ? // vorzeichenbehaftete 0.0 oder subnormale Zahl { if (!(((val.semhi << 1) == 0) && (val.mlo == 0)) && underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_DF_0; } // +/- 0.0 -> 0.0 } elif (exp == 2047) // e=2047 ? { if (!(((val.semhi << (64-DF_mant_len)) == 0) && (val.mlo == 0))) - { cl_error_floating_point_nan(); } // NaN + { throw floating_point_nan_exception(); } // NaN else - { cl_error_floating_point_overflow(); } // Infinity, Overflow + { throw floating_point_overflow_exception(); } // Infinity, Overflow } else { // Der Exponent mu� um DF_exp_mid-1022 erh�ht werden. if ((DF_exp_mid>1022) && (exp > DF_exp_high-DF_exp_mid+1022)) - { cl_error_floating_point_overflow(); } // Overflow + { throw floating_point_overflow_exception(); } // Overflow val.semhi += (sint32)(DF_exp_mid - 1022) << (DF_mant_len-32); return allocate_dfloat(val.semhi,val.mlo); } diff --git a/src/float/dfloat/elem/cl_DF_div.cc b/src/float/dfloat/elem/cl_DF_div.cc index d5e9541..786b866 100644 --- a/src/float/dfloat/elem/cl_DF_div.cc +++ b/src/float/dfloat/elem/cl_DF_div.cc @@ -69,10 +69,10 @@ const cl_DF operator/ (const cl_DF& x1, const cl_DF& x2) #if (cl_word_size==64) var uint64 mantx1; var uint64 mantx2; - DF_decode(x2, { cl_error_division_by_0(); }, sign2=,exp2=,mantx2=); + DF_decode(x2, { throw division_by_0_exception(); }, sign2=,exp2=,mantx2=); DF_decode(x1, { return x1; }, sign1=,exp1=,mantx1=); #else - DF_decode2(x2, { cl_error_division_by_0(); }, sign2=,exp2=,manthi2=,mantlo2=); + DF_decode2(x2, { throw division_by_0_exception(); }, sign2=,exp2=,manthi2=,mantlo2=); DF_decode2(x1, { return x1; }, sign1=,exp1=,manthi1=,mantlo1=); #endif exp1 = exp1 - exp2; // Differenz der Exponenten diff --git a/src/float/dfloat/elem/cl_DF_from_RA.cc b/src/float/dfloat/elem/cl_DF_from_RA.cc index f05bbc5..6e9cbf7 100644 --- a/src/float/dfloat/elem/cl_DF_from_RA.cc +++ b/src/float/dfloat/elem/cl_DF_from_RA.cc @@ -44,10 +44,10 @@ const cl_DF cl_RA_to_DF (const cl_RA& x) var sintC lendiff = (sintC)integer_length(a) // (integer-length a) - (sintC)integer_length(b); // (integer-length b) if (lendiff > DF_exp_high-DF_exp_mid) // Exponent >= n-m > Obergrenze ? - { cl_error_floating_point_overflow(); } // -> Overflow + { throw floating_point_overflow_exception(); } // -> Overflow if (lendiff < DF_exp_low-DF_exp_mid-2) // Exponent <= n-m+2 < Untergrenze ? { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } // -> Underflow + { throw floating_point_underflow_exception(); } // -> Underflow else { return cl_DF_0; } } diff --git a/src/float/dfloat/elem/cl_DF_scale.cc b/src/float/dfloat/elem/cl_DF_scale.cc index b3c1ef0..a932408 100644 --- a/src/float/dfloat/elem/cl_DF_scale.cc +++ b/src/float/dfloat/elem/cl_DF_scale.cc @@ -43,7 +43,7 @@ const cl_DF scale_float (const cl_DF& x, sintC delta) #endif } else - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } } else // delta<0 @@ -58,7 +58,7 @@ const cl_DF scale_float (const cl_DF& x, sintC delta) } else if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_DF_0; } } diff --git a/src/float/dfloat/elem/cl_DF_scale_I.cc b/src/float/dfloat/elem/cl_DF_scale_I.cc index c0e5682..1c60c86 100644 --- a/src/float/dfloat/elem/cl_DF_scale_I.cc +++ b/src/float/dfloat/elem/cl_DF_scale_I.cc @@ -46,7 +46,7 @@ const cl_DF scale_float (const cl_DF& x, const cl_I& delta) #endif } else - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } } else // delta<0 @@ -64,7 +64,7 @@ const cl_DF scale_float (const cl_DF& x, const cl_I& delta) } else if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_DF_0; } } diff --git a/src/float/dfloat/misc/cl_DF_as.cc b/src/float/dfloat/misc/cl_DF_as.cc index d3efc2d..f378170 100644 --- a/src/float/dfloat/misc/cl_DF_as.cc +++ b/src/float/dfloat/misc/cl_DF_as.cc @@ -27,7 +27,7 @@ const cl_DF& cl_DF_As (const cl_number& x, const char * filename, int line) DeclareType(cl_DF,x); return x; } else - cl_as_error(x,"a double-float number",filename,line); + throw as_exception(x,"a double-float number",filename,line); } } // namespace cln diff --git a/src/float/ffloat/cl_FF.h b/src/float/ffloat/cl_FF.h index a7c5f3b..ecbc702 100644 --- a/src/float/ffloat/cl_FF.h +++ b/src/float/ffloat/cl_FF.h @@ -144,13 +144,13 @@ inline const cl_FF encode_FF (cl_signean sign, sintL exp, uintL mant) { if (exp < (sintL)(FF_exp_low-FF_exp_mid)) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_FF_0; } } else if (exp > (sintL)(FF_exp_high-FF_exp_mid)) - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } else return make_FF(sign, exp+FF_exp_mid, mant & (bit(FF_mant_len)-1)); } @@ -191,7 +191,7 @@ inline float FF_to_float (const cl_FF& obj) ) \ && underflow_allowed() \ ) \ - { cl_error_floating_point_underflow(); } /* subnormal oder noch kleiner -> Underflow */\ + { throw floating_point_underflow_exception(); } /* subnormal oder noch kleiner -> Underflow */\ else \ { ergebnis_zuweisung cl_FF_0; } /* +/- 0.0 -> 0.0 */ \ } \ @@ -199,12 +199,12 @@ inline float FF_to_float (const cl_FF& obj) && (((~_erg.eksplicit) & ((uint32)bit(FF_exp_len+FF_mant_len)-bit(FF_mant_len))) == 0) /* e=255 ? */\ ) \ { if (maybe_nan && !((_erg.eksplicit << (32-FF_mant_len)) == 0)) \ - { cl_error_division_by_0(); } /* NaN, also Singularit�t -> "Division durch 0" */\ + { throw division_by_0_exception(); } /* NaN, also Singularit�t -> "Division durch 0" */\ else /* Infinity */ \ if (!maybe_overflow || maybe_divide_0) \ - { cl_error_division_by_0(); } /* Infinity, Division durch 0 */\ + { throw division_by_0_exception(); } /* Infinity, Division durch 0 */\ else \ - { cl_error_floating_point_overflow(); } /* Infinity, Overflow */\ + { throw floating_point_overflow_exception(); } /* Infinity, Overflow */\ } \ else \ { ergebnis_zuweisung allocate_ffloat(_erg.eksplicit); } \ diff --git a/src/float/ffloat/conv/cl_FF_from_float.cc b/src/float/ffloat/conv/cl_FF_from_float.cc index 64eda10..29be439 100644 --- a/src/float/ffloat/conv/cl_FF_from_float.cc +++ b/src/float/ffloat/conv/cl_FF_from_float.cc @@ -17,20 +17,20 @@ cl_private_thing cl_float_to_FF_pointer (const ffloatjanus& val_) if (exp == 0) // e=0 ? // vorzeichenbehaftete 0.0 oder subnormale Zahl { if (!((val << 1) == 0) && underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return as_cl_private_thing(cl_FF_0); } // +/- 0.0 -> 0.0 } elif (exp == 255) // e=255 ? { if (!((val << (32-FF_mant_len)) == 0)) - { cl_error_floating_point_nan(); } // NaN + { throw floating_point_nan_exception(); } // NaN else - { cl_error_floating_point_overflow(); } // Infinity, Overflow + { throw floating_point_overflow_exception(); } // Infinity, Overflow } else { // Der Exponent mu� um FF_exp_mid-126 erh�ht werden. if ((FF_exp_mid>126) && (exp > FF_exp_high-FF_exp_mid+126)) - { cl_error_floating_point_overflow(); } // Overflow + { throw floating_point_overflow_exception(); } // Overflow val += (FF_exp_mid - 126) << FF_mant_len; #if defined(CL_WIDE_POINTERS) return as_cl_private_thing(allocate_ffloat(val)); diff --git a/src/float/ffloat/elem/cl_FF_div.cc b/src/float/ffloat/elem/cl_FF_div.cc index b3492b4..bc9f21f 100644 --- a/src/float/ffloat/elem/cl_FF_div.cc +++ b/src/float/ffloat/elem/cl_FF_div.cc @@ -59,7 +59,7 @@ const cl_FF operator/ (const cl_FF& x1, const cl_FF& x2) var cl_signean sign2; var sintL exp2; var uintL mant2; - FF_decode(x2, { cl_error_division_by_0(); }, sign2=,exp2=,mant2=); + FF_decode(x2, { throw division_by_0_exception(); }, sign2=,exp2=,mant2=); FF_decode(x1, { return x1; }, sign1=,exp1=,mant1=); exp1 = exp1 - exp2; // Differenz der Exponenten sign1 = sign1 ^ sign2; // Ergebnis-Vorzeichen diff --git a/src/float/ffloat/elem/cl_FF_from_RA.cc b/src/float/ffloat/elem/cl_FF_from_RA.cc index 40332a8..d3c7565 100644 --- a/src/float/ffloat/elem/cl_FF_from_RA.cc +++ b/src/float/ffloat/elem/cl_FF_from_RA.cc @@ -44,10 +44,10 @@ const cl_FF cl_RA_to_FF (const cl_RA& x) var sintC lendiff = (sintC)integer_length(a) // (integer-length a) - (sintC)integer_length(b); // (integer-length b) if (lendiff > FF_exp_high-FF_exp_mid) // Exponent >= n-m > Obergrenze ? - { cl_error_floating_point_overflow(); } // -> Overflow + { throw floating_point_overflow_exception(); } // -> Overflow if (lendiff < FF_exp_low-FF_exp_mid-2) // Exponent <= n-m+2 < Untergrenze ? { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } // -> Underflow + { throw floating_point_underflow_exception(); } // -> Underflow else { return cl_FF_0; } } diff --git a/src/float/ffloat/elem/cl_FF_scale.cc b/src/float/ffloat/elem/cl_FF_scale.cc index 8cf7b4d..688cf61 100644 --- a/src/float/ffloat/elem/cl_FF_scale.cc +++ b/src/float/ffloat/elem/cl_FF_scale.cc @@ -33,7 +33,7 @@ const cl_FF scale_float (const cl_FF& x, sintC delta) return encode_FF(sign,exp,mant); } else - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } } else // delta<0 @@ -44,7 +44,7 @@ const cl_FF scale_float (const cl_FF& x, sintC delta) } else if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_FF_0; } } diff --git a/src/float/ffloat/elem/cl_FF_scale_I.cc b/src/float/ffloat/elem/cl_FF_scale_I.cc index b11386f..2f444d7 100644 --- a/src/float/ffloat/elem/cl_FF_scale_I.cc +++ b/src/float/ffloat/elem/cl_FF_scale_I.cc @@ -36,7 +36,7 @@ const cl_FF scale_float (const cl_FF& x, const cl_I& delta) return encode_FF(sign,exp,mant); } else - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } } else // delta<0 @@ -50,7 +50,7 @@ const cl_FF scale_float (const cl_FF& x, const cl_I& delta) } else if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return cl_FF_0; } } diff --git a/src/float/ffloat/misc/cl_FF_as.cc b/src/float/ffloat/misc/cl_FF_as.cc index e22057f..e9bbfef 100644 --- a/src/float/ffloat/misc/cl_FF_as.cc +++ b/src/float/ffloat/misc/cl_FF_as.cc @@ -33,7 +33,7 @@ const cl_FF& cl_FF_As (const cl_number& x, const char * filename, int line) DeclareType(cl_FF,x); return x; } else - cl_as_error(x,"a single-float number",filename,line); + throw as_exception(x,"a single-float number",filename,line); } } // namespace cln diff --git a/src/float/input/cl_F_read.cc b/src/float/input/cl_F_read.cc index 627652d..52b3e2b 100644 --- a/src/float/input/cl_F_read.cc +++ b/src/float/input/cl_F_read.cc @@ -51,7 +51,7 @@ static const char * skip_digits (const char * ptr, const char * string_limit, un if (end_of_parse) \ { *end_of_parse = (ptr); } \ else \ - { if ((ptr) != string_limit) { read_number_junk((ptr),string,string_limit); } } + { if ((ptr) != string_limit) { throw read_number_junk_exception((ptr),string,string_limit); } } const cl_F read_float (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse) { @@ -175,7 +175,7 @@ not_float_syntax: *end_of_parse = string; return cl_F(); // dummy return } - read_number_bad_syntax(string,string_limit); + throw read_number_bad_syntax_exception(string,string_limit); } } // namespace cln diff --git a/src/float/input/cl_F_read_stream.cc b/src/float/input/cl_F_read_stream.cc index b2daee6..d7a4eef 100644 --- a/src/float/input/cl_F_read_stream.cc +++ b/src/float/input/cl_F_read_stream.cc @@ -98,10 +98,10 @@ const cl_F read_float (std::istream& stream, const cl_read_flags& flags) // Handle syntax error. syntax1: buffer.push(c); - read_number_bad_syntax(buffer.start_pointer(),buffer.end_pointer()); + throw read_number_bad_syntax_exception(buffer.start_pointer(),buffer.end_pointer()); // Handle premature EOF. -eof: read_number_eof(); +eof: throw read_number_eof_exception(); } } // namespace cln diff --git a/src/float/lfloat/algebraic/cl_LF_sqrt.cc b/src/float/lfloat/algebraic/cl_LF_sqrt.cc index 8d53c6a..ae07194 100644 --- a/src/float/lfloat/algebraic/cl_LF_sqrt.cc +++ b/src/float/lfloat/algebraic/cl_LF_sqrt.cc @@ -13,7 +13,7 @@ #include "cl_LF_impl.h" #include "cl_F.h" #include "cl_DS.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -99,7 +99,7 @@ const cl_LF sqrt (const cl_LF& x) } else // �ertrag durch Rundungsfehler - { if (test_loop_msp(y_mantMSDptr,len)) cl_abort(); + { if (test_loop_msp(y_mantMSDptr,len)) throw runtime_exception(); mspref(y_mantMSDptr,0) = bit(intDsize-1); // Mantisse := 10...0 (TheLfloat(y)->expo)++; // Exponenten incrementieren } diff --git a/src/float/lfloat/elem/cl_LF_1plus.cc b/src/float/lfloat/elem/cl_LF_1plus.cc index 2114521..596a4dd 100644 --- a/src/float/lfloat/elem/cl_LF_1plus.cc +++ b/src/float/lfloat/elem/cl_LF_1plus.cc @@ -124,7 +124,7 @@ const cl_LF LF_LF_plus_LF (const cl_LF& arg1, const cl_LF& arg2) { if ( inc_loop_lsp(ptr,i) ) // �bertrag �ber das erste Digit hinaus { // Exponent von y incrementieren: - if ( ++(TheLfloat(y)->expo) == LF_exp_high+1 ) { cl_error_floating_point_overflow(); } + if ( ++(TheLfloat(y)->expo) == LF_exp_high+1 ) { throw floating_point_overflow_exception(); } // normalisiere durch Schieben um 1 Bit nach rechts: {var uintD carry_rechts = shift1right_loop_msp(y_mantMSDptr,len,~(uintD)0); @@ -179,7 +179,7 @@ const cl_LF LF_LF_plus_LF (const cl_LF& arg1, const cl_LF& arg2) if (uexp <= k) #endif { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } @@ -212,7 +212,7 @@ const cl_LF LF_LF_plus_LF (const cl_LF& arg1, const cl_LF& arg2) if (uexp <= s) #endif { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } @@ -232,7 +232,7 @@ const cl_LF LF_LF_plus_LF (const cl_LF& arg1, const cl_LF& arg2) { // �bertrag durchs Aufrunden mspref(y_mantMSDptr,0) = bit(intDsize-1); // Mantisse := 10...0 // Exponent erh�hen: - if (++(TheLfloat(y)->expo) == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (++(TheLfloat(y)->expo) == LF_exp_high+1) { throw floating_point_overflow_exception(); } } ab: // abrunden ; diff --git a/src/float/lfloat/elem/cl_LF_I_div.cc b/src/float/lfloat/elem/cl_LF_I_div.cc index 139f3e1..8f3772f 100644 --- a/src/float/lfloat/elem/cl_LF_I_div.cc +++ b/src/float/lfloat/elem/cl_LF_I_div.cc @@ -27,7 +27,7 @@ const cl_LF cl_LF_I_div (const cl_LF& x, const cl_I& y) // Else divide the mantissa of x by the absolute value of y, then round. if (TheLfloat(x)->expo == 0) { if (zerop(y)) - cl_error_division_by_0(); + throw division_by_0_exception(); else return x; } @@ -88,7 +88,7 @@ const cl_LF cl_LF_I_div (const cl_LF& x, const cl_I& y) var uintE dexp = intDsize*y_len - shiftcount; // >= 0 ! if ((uexp < dexp) || ((uexp = uexp - dexp) < LF_exp_low)) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } } @@ -107,7 +107,7 @@ const cl_LF cl_LF_I_div (const cl_LF& x, const cl_I& y) // �bertrag durchs Aufrunden { mspref(MSDptr,0) = bit(intDsize-1); // Mantisse := 10...0 // Exponenten incrementieren: - if (++uexp == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (++uexp == LF_exp_high+1) { throw floating_point_overflow_exception(); } } } return encode_LFu(TheLfloat(x)->sign ^ sign, uexp, MSDptr, len); } diff --git a/src/float/lfloat/elem/cl_LF_I_mul.cc b/src/float/lfloat/elem/cl_LF_I_mul.cc index d83424a..ebcf481 100644 --- a/src/float/lfloat/elem/cl_LF_I_mul.cc +++ b/src/float/lfloat/elem/cl_LF_I_mul.cc @@ -64,7 +64,7 @@ const cl_R cl_LF_I_mul (const cl_LF& x, const cl_I& y) var uintE iexp = intDsize*y_len - shiftcount; // >= 0 ! uexp = uexp + iexp; if ((uexp < iexp) || (uexp > LF_exp_high)) - cl_error_floating_point_overflow(); + throw floating_point_overflow_exception(); // Runden: var uintD* midptr = prodMSDptr mspop len; var uintC restlen = prodlen - len; @@ -82,7 +82,7 @@ const cl_R cl_LF_I_mul (const cl_LF& x, const cl_I& y) { if ( inc_loop_lsp(midptr,len) ) // �bertrag durchs Aufrunden { mspref(prodMSDptr,0) = bit(intDsize-1); // Mantisse := 10...0 - if (++uexp == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (++uexp == LF_exp_high+1) { throw floating_point_overflow_exception(); } } } return encode_LFu(TheLfloat(x)->sign ^ sign, uexp, prodMSDptr, len); } diff --git a/src/float/lfloat/elem/cl_LF_div.cc b/src/float/lfloat/elem/cl_LF_div.cc index 318b83d..3b9f1fa 100644 --- a/src/float/lfloat/elem/cl_LF_div.cc +++ b/src/float/lfloat/elem/cl_LF_div.cc @@ -42,7 +42,7 @@ const cl_LF operator/ (const cl_LF& x1, const cl_LF& x2) var uintC len2 = TheLfloat(x2)->len; var uintC len = (len1 < len2 ? len1 : len2); // min. L�nge n von x1 und x2 var uintE uexp2 = TheLfloat(x2)->expo; - if (uexp2==0) { cl_error_division_by_0(); } // x2=0.0 -> Error + if (uexp2==0) { throw division_by_0_exception(); } // x2=0.0 -> Error var uintE uexp1 = TheLfloat(x1)->expo; if (uexp1==0) // x1=0.0 -> Ergebnis 0.0 { if (len < len1) return shorten(x1,len); else return x1; } @@ -50,14 +50,14 @@ const cl_LF operator/ (const cl_LF& x1, const cl_LF& x2) // (uexp1-LF_exp_mid) - (uexp2-LF_exp_mid) = (uexp1-uexp2+LF_exp_mid)-LF_exp_mid if (uexp1 >= uexp2) { uexp1 = uexp1 - uexp2; // kein Carry - if (uexp1 > LF_exp_high-LF_exp_mid) { cl_error_floating_point_overflow(); } + if (uexp1 > LF_exp_high-LF_exp_mid) { throw floating_point_overflow_exception(); } uexp1 = uexp1 + LF_exp_mid; } else { uexp1 = uexp1 - uexp2; // Carry if (uexp1 < (uintE)(LF_exp_low-1-LF_exp_mid)) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } @@ -105,7 +105,7 @@ const cl_LF operator/ (const cl_LF& x1, const cl_LF& x2) shiftrightcopy_loop_msp(q.MSDptr mspop 1,y_mantMSDptr,len,1, /* carry links = mspref(q.MSDptr,0) = 1 */ 1 ); // Exponenten incrementieren: - if (++(TheLfloat(y)->expo) == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (++(TheLfloat(y)->expo) == LF_exp_high+1) { throw floating_point_overflow_exception(); } // Runden: if ( (carry_rechts == 0) // herausgeschobenes Bit =0 -> abrunden || ( (lspref(q.LSDptr,0)==0) // =1 und weitere Bits >0 oder Rest >0 -> aufrunden @@ -138,14 +138,14 @@ const cl_LF operator/ (const cl_LF& x1, const cl_LF& x2) // �bertrag durchs Aufrunden { mspref(y_mantMSDptr,0) = bit(intDsize-1); // Mantisse := 10...0 // Exponenten incrementieren: - if (++(TheLfloat(y)->expo) == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (++(TheLfloat(y)->expo) == LF_exp_high+1) { throw floating_point_overflow_exception(); } } } } } // LF_exp_low <= exp <= LF_exp_high sicherstellen: if (TheLfloat(y)->expo == LF_exp_low-1) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } diff --git a/src/float/lfloat/elem/cl_LF_from_I.cc b/src/float/lfloat/elem/cl_LF_from_I.cc index c18e329..9601436 100644 --- a/src/float/lfloat/elem/cl_LF_from_I.cc +++ b/src/float/lfloat/elem/cl_LF_from_I.cc @@ -43,7 +43,7 @@ const cl_LF cl_I_to_LF (const cl_I& x, uintC len) ) {} // garantiert exp <= intDsize*2^intCsize-1 <= LF_exp_high-LF_exp_mid else - { if (!(exp <= (uintE)(LF_exp_high-LF_exp_mid))) { cl_error_floating_point_overflow(); } } + { if (!(exp <= (uintE)(LF_exp_high-LF_exp_mid))) { throw floating_point_overflow_exception(); } } // Long-Float bauen: var Lfloat y = allocate_lfloat(len,exp+LF_exp_mid,sign); var uintD* y_mantMSDptr = arrayMSDptr(TheLfloat(y)->data,len); @@ -96,7 +96,7 @@ const cl_LF cl_I_to_LF (const cl_I& x, uintC len) // garantiert exp < intDsize*2^intCsize-1 <= LF_exp_high-LF_exp_mid { (TheLfloat(y)->expo)++; } // jetzt exp <= LF_exp_high-LF_exp_mid else - { if (++(TheLfloat(y)->expo) == LF_exp_high+1) { cl_error_floating_point_overflow(); } } + { if (++(TheLfloat(y)->expo) == LF_exp_high+1) { throw floating_point_overflow_exception(); } } } ab: // abrunden ; diff --git a/src/float/lfloat/elem/cl_LF_mul.cc b/src/float/lfloat/elem/cl_LF_mul.cc index 5429a6c..6132d05 100644 --- a/src/float/lfloat/elem/cl_LF_mul.cc +++ b/src/float/lfloat/elem/cl_LF_mul.cc @@ -43,13 +43,13 @@ const cl_LF operator* (const cl_LF& x1, const cl_LF& x2) // kein Carry { if (uexp1 < LF_exp_mid+LF_exp_low) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } } else // Carry - { if (uexp1 > (uintE)(LF_exp_mid+LF_exp_high+1)) { cl_error_floating_point_overflow(); } } + { if (uexp1 > (uintE)(LF_exp_mid+LF_exp_high+1)) { throw floating_point_overflow_exception(); } } uexp1 = uexp1 - LF_exp_mid; // Nun ist LF_exp_low <= uexp1 <= LF_exp_high+1. // neues Long-Float allozieren: @@ -77,7 +77,7 @@ const cl_LF operator* (const cl_LF& x1, const cl_LF& x2) // Exponenten decrementieren: if (--(TheLfloat(y)->expo) == LF_exp_low-1) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } @@ -103,7 +103,7 @@ const cl_LF operator* (const cl_LF& x1, const cl_LF& x2) (TheLfloat(y)->expo)++; // Exponent wieder zurck-erhhen } } // LF_exp_low <= exp <= LF_exp_high sicherstellen: - if (TheLfloat(y)->expo == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (TheLfloat(y)->expo == LF_exp_high+1) { throw floating_point_overflow_exception(); } }} return y; } diff --git a/src/float/lfloat/elem/cl_LF_scale.cc b/src/float/lfloat/elem/cl_LF_scale.cc index 7a2738f..9aa98b1 100644 --- a/src/float/lfloat/elem/cl_LF_scale.cc +++ b/src/float/lfloat/elem/cl_LF_scale.cc @@ -31,13 +31,13 @@ const cl_LF scale_float (const cl_LF& x, sintC delta) if ( ((uexp = uexp+udelta) < udelta) // Exponent-�berlauf? || (uexp > LF_exp_high) // oder Exponent zu gro�? ) - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } } else { // delta <0, udelta = 2^intEsize+delta if ( ((uintE)(-(uexp = uexp+udelta)) <= (uintE)(-udelta)) // oder Exponent-Unterlauf? || (uexp < LF_exp_low) // oder Exponent zu klein? ) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } } var uintC len = TheLfloat(x)->len; return encode_LFu(TheLfloat(x)->sign,uexp,arrayMSDptr(TheLfloat(x)->data,len),len); diff --git a/src/float/lfloat/elem/cl_LF_scale_I.cc b/src/float/lfloat/elem/cl_LF_scale_I.cc index 6691fd7..ef119bd 100644 --- a/src/float/lfloat/elem/cl_LF_scale_I.cc +++ b/src/float/lfloat/elem/cl_LF_scale_I.cc @@ -92,7 +92,7 @@ const cl_LF scale_float (const cl_LF& x, const cl_I& delta) || (uexp > LF_exp_high) // oder Exponent zu gro�? ) overflow: - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } goto ok; neg: // delta <0, udelta = 2^32+delta @@ -100,7 +100,7 @@ const cl_LF scale_float (const cl_LF& x, const cl_I& delta) || (uexp < LF_exp_low) // oder Exponent zu klein? ) underflow: - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } goto ok; ok: diff --git a/src/float/lfloat/elem/cl_LF_square.cc b/src/float/lfloat/elem/cl_LF_square.cc index 72d5827..956dcc9 100644 --- a/src/float/lfloat/elem/cl_LF_square.cc +++ b/src/float/lfloat/elem/cl_LF_square.cc @@ -30,14 +30,14 @@ const cl_LF square (const cl_LF& x) { uexp = 2*uexp; if (uexp < LF_exp_mid+LF_exp_low) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } } else // Carry { uexp = 2*uexp; - if (uexp > (uintE)(LF_exp_mid+LF_exp_high+1)) { cl_error_floating_point_overflow(); } + if (uexp > (uintE)(LF_exp_mid+LF_exp_high+1)) { throw floating_point_overflow_exception(); } } uexp = uexp - LF_exp_mid; // Nun ist LF_exp_low <= uexp <= LF_exp_high+1. @@ -57,7 +57,7 @@ const cl_LF square (const cl_LF& x) // Exponenten decrementieren: if ((TheLfloat(y)->expo)-- == LF_exp_low-1) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return encode_LF0(len); } // Ergebnis 0.0 } @@ -83,7 +83,7 @@ const cl_LF square (const cl_LF& x) (TheLfloat(y)->expo)++; // Exponent wieder zur�ck-erh�hen } } // LF_exp_low <= exp <= LF_exp_high sicherstellen: - if (TheLfloat(y)->expo == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (TheLfloat(y)->expo == LF_exp_high+1) { throw floating_point_overflow_exception(); } }} return y; } diff --git a/src/float/lfloat/misc/cl_LF_as.cc b/src/float/lfloat/misc/cl_LF_as.cc index 8f84e7a..ef6f527 100644 --- a/src/float/lfloat/misc/cl_LF_as.cc +++ b/src/float/lfloat/misc/cl_LF_as.cc @@ -27,7 +27,7 @@ const cl_LF& cl_LF_As (const cl_number& x, const char * filename, int line) DeclareType(cl_LF,x); return x; } else - cl_as_error(x,"a long-float number",filename,line); + throw as_exception(x,"a long-float number",filename,line); } } // namespace cln diff --git a/src/float/lfloat/misc/cl_LF_shorten.cc b/src/float/lfloat/misc/cl_LF_shorten.cc index 4d9696f..f7e9b42 100644 --- a/src/float/lfloat/misc/cl_LF_shorten.cc +++ b/src/float/lfloat/misc/cl_LF_shorten.cc @@ -39,7 +39,7 @@ const cl_LF shorten (const cl_LF& x, uintC len) // �bertrag durch Aufrunden { mspref(arrayMSDptr(TheLfloat(y)->data,len),0) = bit(intDsize-1); // Mantisse := 10...0 // Exponent erh�hen: - if (++(TheLfloat(y)->expo) == LF_exp_high+1) { cl_error_floating_point_overflow(); } + if (++(TheLfloat(y)->expo) == LF_exp_high+1) { throw floating_point_overflow_exception(); } } } } return y; diff --git a/src/float/lfloat/misc/cl_LF_shortenrel.cc b/src/float/lfloat/misc/cl_LF_shortenrel.cc index 77d5f75..5217967 100644 --- a/src/float/lfloat/misc/cl_LF_shortenrel.cc +++ b/src/float/lfloat/misc/cl_LF_shortenrel.cc @@ -9,7 +9,7 @@ // Implementation. -#include "cln/abort.h" +#include "cln/exception.h" #undef MAYBE_INLINE2 #define MAYBE_INLINE2 inline @@ -31,7 +31,7 @@ const cl_LF cl_LF_shortenrelative (const cl_LF& x, const cl_LF& y) var sintE ey = float_exponent(y); var sintC dy = float_precision(y); if (dy==0) // zerop(y) ? - cl_abort(); + throw runtime_exception(); var sintE ex = float_exponent(x); var sintC dx = float_precision(x); if (dx==0) // zerop(x) ? diff --git a/src/float/lfloat/misc/cl_LF_shortenwith.cc b/src/float/lfloat/misc/cl_LF_shortenwith.cc index b12156a..f88a614 100644 --- a/src/float/lfloat/misc/cl_LF_shortenwith.cc +++ b/src/float/lfloat/misc/cl_LF_shortenwith.cc @@ -9,8 +9,6 @@ // Implementation. -#include "cln/abort.h" - #undef MAYBE_INLINE2 #define MAYBE_INLINE2 inline #include "cl_LF_precision.cc" diff --git a/src/float/misc/cl_F_as.cc b/src/float/misc/cl_F_as.cc index 1f3dfff..cd122dc 100644 --- a/src/float/misc/cl_F_as.cc +++ b/src/float/misc/cl_F_as.cc @@ -35,7 +35,7 @@ const cl_F& cl_F_As (const cl_number& x, const char * filename, int line) DeclareType(cl_F,x); return x; } else - cl_as_error(x,"a floating-point number",filename,line); + throw as_exception(x,"a floating-point number",filename,line); } } // namespace cln diff --git a/src/float/misc/cl_F_shortenrel.cc b/src/float/misc/cl_F_shortenrel.cc index c0b292f..1f219a0 100644 --- a/src/float/misc/cl_F_shortenrel.cc +++ b/src/float/misc/cl_F_shortenrel.cc @@ -10,7 +10,7 @@ // Implementation. #include "cl_LF.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -25,7 +25,7 @@ const cl_F cl_F_shortenrelative (const cl_F& x, const cl_F& y) var sintE ey = float_exponent(y); var sintC dy = float_precision(y); if (dy==0) // zerop(y) ? - cl_abort(); + throw runtime_exception(); var sintE ex = float_exponent(x); var sintC dx = float_precision(x); if (dx==0) // zerop(x) ? diff --git a/src/float/sfloat/cl_SF.h b/src/float/sfloat/cl_SF.h index ab0f9f7..a9c30fa 100644 --- a/src/float/sfloat/cl_SF.h +++ b/src/float/sfloat/cl_SF.h @@ -105,13 +105,13 @@ inline const cl_SF encode_SF (cl_signean sign, sintL exp, uintL mant) { if (exp < (sintL)(SF_exp_low-SF_exp_mid)) { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return SF_0; } } else if (exp > (sintL)(SF_exp_high-SF_exp_mid)) - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } else return make_SF(sign, exp+SF_exp_mid, mant); } diff --git a/src/float/sfloat/elem/cl_SF_div.cc b/src/float/sfloat/elem/cl_SF_div.cc index e71e5de..39b105e 100644 --- a/src/float/sfloat/elem/cl_SF_div.cc +++ b/src/float/sfloat/elem/cl_SF_div.cc @@ -42,7 +42,7 @@ const cl_SF operator/ (const cl_SF& x1, const cl_SF& x2) var cl_signean sign2; var sintL exp2; var uintL mant2; - SF_decode(x2, { cl_error_division_by_0(); }, sign2=,exp2=,mant2=); + SF_decode(x2, { throw division_by_0_exception(); }, sign2=,exp2=,mant2=); SF_decode(x1, { return x1; }, sign1=,exp1=,mant1=); exp1 = exp1 - exp2; // Differenz der Exponenten sign1 = sign1 ^ sign2; // Ergebnis-Vorzeichen diff --git a/src/float/sfloat/elem/cl_SF_from_RA.cc b/src/float/sfloat/elem/cl_SF_from_RA.cc index fe5eec1..e0019f5 100644 --- a/src/float/sfloat/elem/cl_SF_from_RA.cc +++ b/src/float/sfloat/elem/cl_SF_from_RA.cc @@ -43,10 +43,10 @@ const cl_SF cl_RA_to_SF (const cl_RA& x) var sintC lendiff = (sintC)integer_length(a) // (integer-length a) - (sintC)integer_length(b); // (integer-length b) if (lendiff > SF_exp_high-SF_exp_mid) // Exponent >= n-m > Obergrenze ? - { cl_error_floating_point_overflow(); } // -> Overflow + { throw floating_point_overflow_exception(); } // -> Overflow if (lendiff < SF_exp_low-SF_exp_mid-2) // Exponent <= n-m+2 < Untergrenze ? { if (underflow_allowed()) - { cl_error_floating_point_underflow(); } // -> Underflow + { throw floating_point_underflow_exception(); } // -> Underflow else { return SF_0; } } diff --git a/src/float/sfloat/elem/cl_SF_scale.cc b/src/float/sfloat/elem/cl_SF_scale.cc index e88afde..842b5fa 100644 --- a/src/float/sfloat/elem/cl_SF_scale.cc +++ b/src/float/sfloat/elem/cl_SF_scale.cc @@ -33,7 +33,7 @@ const cl_SF scale_float (const cl_SF& x, sintC delta) return encode_SF(sign,exp,mant); } else - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } } else // delta<0 @@ -44,7 +44,7 @@ const cl_SF scale_float (const cl_SF& x, sintC delta) } else if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return SF_0; } } diff --git a/src/float/sfloat/elem/cl_SF_scale_I.cc b/src/float/sfloat/elem/cl_SF_scale_I.cc index f0a9f32..c11ba5d 100644 --- a/src/float/sfloat/elem/cl_SF_scale_I.cc +++ b/src/float/sfloat/elem/cl_SF_scale_I.cc @@ -36,7 +36,7 @@ const cl_SF scale_float (const cl_SF& x, const cl_I& delta) return encode_SF(sign,exp,mant); } else - { cl_error_floating_point_overflow(); } + { throw floating_point_overflow_exception(); } } else // delta<0 @@ -50,7 +50,7 @@ const cl_SF scale_float (const cl_SF& x, const cl_I& delta) } else if (underflow_allowed()) - { cl_error_floating_point_underflow(); } + { throw floating_point_underflow_exception(); } else { return SF_0; } } diff --git a/src/float/sfloat/misc/cl_SF_as.cc b/src/float/sfloat/misc/cl_SF_as.cc index 2f9146a..d5a32ff 100644 --- a/src/float/sfloat/misc/cl_SF_as.cc +++ b/src/float/sfloat/misc/cl_SF_as.cc @@ -27,7 +27,7 @@ const cl_SF& cl_SF_As (const cl_number& x, const char * filename, int line) DeclareType(cl_SF,x); return x; } else - cl_as_error(x,"a short-float number",filename,line); + throw as_exception(x,"a short-float number",filename,line); } } // namespace cln diff --git a/src/float/transcendental/cl_LF_coshsinh_aux.cc b/src/float/transcendental/cl_LF_coshsinh_aux.cc index 5aebbf1..f7c9f57 100644 --- a/src/float/transcendental/cl_LF_coshsinh_aux.cc +++ b/src/float/transcendental/cl_LF_coshsinh_aux.cc @@ -14,7 +14,7 @@ #include "cl_LF.h" #include "cln/integer.h" #include "cl_alloca.h" -#include "cln/abort.h" +#include "cln/exception.h" #undef floor #include <cmath> @@ -30,7 +30,7 @@ const cl_LF_cosh_sinh_t cl_coshsinh_aux (const cl_I& p, uintE lq, uintC len) { { Mutable(cl_I,p); var uintE lp = integer_length(p); // now |p| < 2^lp. - if (!(lp <= lq)) cl_abort(); + if (!(lp <= lq)) throw runtime_exception(); lp = lq - lp; // now |p/2^lq| < 2^-lp. // Minimize lq (saves computation time). { diff --git a/src/float/transcendental/cl_LF_cossin_aux.cc b/src/float/transcendental/cl_LF_cossin_aux.cc index 943158b..83dafa3 100644 --- a/src/float/transcendental/cl_LF_cossin_aux.cc +++ b/src/float/transcendental/cl_LF_cossin_aux.cc @@ -14,7 +14,7 @@ #include "cl_LF.h" #include "cln/integer.h" #include "cl_alloca.h" -#include "cln/abort.h" +#include "cln/exception.h" #undef floor #include <cmath> @@ -30,7 +30,7 @@ const cl_LF_cos_sin_t cl_cossin_aux (const cl_I& p, uintE lq, uintC len) { { Mutable(cl_I,p); var uintE lp = integer_length(p); // now |p| < 2^lp. - if (!(lp <= lq)) cl_abort(); + if (!(lp <= lq)) throw runtime_exception(); lp = lq - lp; // now |p/2^lq| < 2^-lp. // Minimize lq (saves computation time). { diff --git a/src/float/transcendental/cl_LF_eulerconst.cc b/src/float/transcendental/cl_LF_eulerconst.cc index 3ab99de..1258f75 100644 --- a/src/float/transcendental/cl_LF_eulerconst.cc +++ b/src/float/transcendental/cl_LF_eulerconst.cc @@ -14,7 +14,6 @@ #include "cl_LF.h" #include "cln/integer.h" #include "cl_alloca.h" -#include "cln/abort.h" namespace cln { diff --git a/src/float/transcendental/cl_LF_exp_aux.cc b/src/float/transcendental/cl_LF_exp_aux.cc index 3401768..a732bb7 100644 --- a/src/float/transcendental/cl_LF_exp_aux.cc +++ b/src/float/transcendental/cl_LF_exp_aux.cc @@ -14,7 +14,7 @@ #include "cl_LF.h" #include "cln/integer.h" #include "cl_alloca.h" -#include "cln/abort.h" +#include "cln/exception.h" #undef floor #include <cmath> @@ -26,7 +26,7 @@ const cl_LF cl_exp_aux (const cl_I& p, uintE lq, uintC len) { { Mutable(cl_I,p); var uintE lp = integer_length(p); // now |p| < 2^lp. - if (!(lp <= lq)) cl_abort(); + if (!(lp <= lq)) throw runtime_exception(); lp = lq - lp; // now |p/2^lq| < 2^-lp. // Minimize lq (saves computation time). { diff --git a/src/float/transcendental/cl_LF_ratseries_.cc b/src/float/transcendental/cl_LF_ratseries_.cc index 537ea15..be72ea3 100644 --- a/src/float/transcendental/cl_LF_ratseries_.cc +++ b/src/float/transcendental/cl_LF_ratseries_.cc @@ -11,7 +11,6 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" #include "cl_LF.h" namespace cln { diff --git a/src/float/transcendental/cl_LF_ratseries_a.cc b/src/float/transcendental/cl_LF_ratseries_a.cc index b8338da..edbe3ce 100644 --- a/src/float/transcendental/cl_LF_ratseries_a.cc +++ b/src/float/transcendental/cl_LF_ratseries_a.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_a_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: *T = args.av[N1]; break; diff --git a/src/float/transcendental/cl_LF_ratseries_ab.cc b/src/float/transcendental/cl_LF_ratseries_ab.cc index e5f50fb..ed48489 100644 --- a/src/float/transcendental/cl_LF_ratseries_ab.cc +++ b/src/float/transcendental/cl_LF_ratseries_ab.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_ab_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: *B = args.bv[N1]; *T = args.av[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_b.cc b/src/float/transcendental/cl_LF_ratseries_b.cc index 5c3ce3c..1c56864 100644 --- a/src/float/transcendental/cl_LF_ratseries_b.cc +++ b/src/float/transcendental/cl_LF_ratseries_b.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_b_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: *B = args.bv[N1]; *T = 1; diff --git a/src/float/transcendental/cl_LF_ratseries_p.cc b/src/float/transcendental/cl_LF_ratseries_p.cc index 65ef9b5..f2562d0 100644 --- a/src/float/transcendental/cl_LF_ratseries_p.cc +++ b/src/float/transcendental/cl_LF_ratseries_p.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_p_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *T = args.pv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_pa.cc b/src/float/transcendental/cl_LF_ratseries_pa.cc index 6382f84..196f580 100644 --- a/src/float/transcendental/cl_LF_ratseries_pa.cc +++ b/src/float/transcendental/cl_LF_ratseries_pa.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_pa_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *T = args.av[N1] * args.pv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_pab.cc b/src/float/transcendental/cl_LF_ratseries_pab.cc index ee97f06..67a2b78 100644 --- a/src/float/transcendental/cl_LF_ratseries_pab.cc +++ b/src/float/transcendental/cl_LF_ratseries_pab.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_pab_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *B = args.bv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_pb.cc b/src/float/transcendental/cl_LF_ratseries_pb.cc index eedd587..27abaab 100644 --- a/src/float/transcendental/cl_LF_ratseries_pb.cc +++ b/src/float/transcendental/cl_LF_ratseries_pb.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_pb_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *B = args.bv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_pq.cc b/src/float/transcendental/cl_LF_ratseries_pq.cc index ce90e8b..4bc195d 100644 --- a/src/float/transcendental/cl_LF_ratseries_pq.cc +++ b/src/float/transcendental/cl_LF_ratseries_pq.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_pq_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; @@ -91,7 +91,7 @@ static void eval_pqs_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_pqa.cc b/src/float/transcendental/cl_LF_ratseries_pqa.cc index 95c6e03..ee0dba1 100644 --- a/src/float/transcendental/cl_LF_ratseries_pqa.cc +++ b/src/float/transcendental/cl_LF_ratseries_pqa.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_pqa_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; @@ -91,7 +91,7 @@ static void eval_pqsa_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_pqab.cc b/src/float/transcendental/cl_LF_ratseries_pqab.cc index 1d9ef3e..2710042 100644 --- a/src/float/transcendental/cl_LF_ratseries_pqab.cc +++ b/src/float/transcendental/cl_LF_ratseries_pqab.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_pqab_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; @@ -99,7 +99,7 @@ static void eval_pqsab_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_pqb.cc b/src/float/transcendental/cl_LF_ratseries_pqb.cc index 69cf1d2..2ef3f0c 100644 --- a/src/float/transcendental/cl_LF_ratseries_pqb.cc +++ b/src/float/transcendental/cl_LF_ratseries_pqb.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_pqb_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; @@ -99,7 +99,7 @@ static void eval_pqsb_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (P) { *P = args.pv[N1]; } *Q = args.qv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_q.cc b/src/float/transcendental/cl_LF_ratseries_q.cc index 7897bb2..6e93909 100644 --- a/src/float/transcendental/cl_LF_ratseries_q.cc +++ b/src/float/transcendental/cl_LF_ratseries_q.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_q_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: *Q = args.qv[N1]; *T = 1; diff --git a/src/float/transcendental/cl_LF_ratseries_qa.cc b/src/float/transcendental/cl_LF_ratseries_qa.cc index f94c754..306089e 100644 --- a/src/float/transcendental/cl_LF_ratseries_qa.cc +++ b/src/float/transcendental/cl_LF_ratseries_qa.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_qa_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: *Q = args.qv[N1]; *T = args.av[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_qab.cc b/src/float/transcendental/cl_LF_ratseries_qab.cc index 4dadb3b..8ea60c1 100644 --- a/src/float/transcendental/cl_LF_ratseries_qab.cc +++ b/src/float/transcendental/cl_LF_ratseries_qab.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_qab_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: *Q = args.qv[N1]; *B = args.bv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_qb.cc b/src/float/transcendental/cl_LF_ratseries_qb.cc index 58ae23e..c006f09 100644 --- a/src/float/transcendental/cl_LF_ratseries_qb.cc +++ b/src/float/transcendental/cl_LF_ratseries_qb.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -28,7 +28,7 @@ static void eval_qb_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: *Q = args.qv[N1]; *B = args.bv[N1]; diff --git a/src/float/transcendental/cl_LF_ratseries_stream_pq.cc b/src/float/transcendental/cl_LF_ratseries_stream_pq.cc index 440f85d..91b3391 100644 --- a/src/float/transcendental/cl_LF_ratseries_stream_pq.cc +++ b/src/float/transcendental/cl_LF_ratseries_stream_pq.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -22,7 +22,7 @@ static void eval_pq_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: { var cl_pq_series_term v0 = args.next(); // [N1] if (P) { *P = v0.p; } diff --git a/src/float/transcendental/cl_LF_ratseries_stream_pqa.cc b/src/float/transcendental/cl_LF_ratseries_stream_pqa.cc index 1bc6e30..3a2f3f0 100644 --- a/src/float/transcendental/cl_LF_ratseries_stream_pqa.cc +++ b/src/float/transcendental/cl_LF_ratseries_stream_pqa.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -22,7 +22,7 @@ static void eval_pqa_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: { var cl_pqa_series_term v0 = args.next(); // [N1] if (P) { *P = v0.p; } diff --git a/src/float/transcendental/cl_LF_ratseries_stream_pqab.cc b/src/float/transcendental/cl_LF_ratseries_stream_pqab.cc index 376d88a..8203c9f 100644 --- a/src/float/transcendental/cl_LF_ratseries_stream_pqab.cc +++ b/src/float/transcendental/cl_LF_ratseries_stream_pqab.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -22,7 +22,7 @@ static void eval_pqab_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: { var cl_pqab_series_term v0 = args.next(); // [N1] if (P) { *P = v0.p; } diff --git a/src/float/transcendental/cl_LF_ratseries_stream_pqb.cc b/src/float/transcendental/cl_LF_ratseries_stream_pqb.cc index 2cfc32a..12925b7 100644 --- a/src/float/transcendental/cl_LF_ratseries_stream_pqb.cc +++ b/src/float/transcendental/cl_LF_ratseries_stream_pqb.cc @@ -11,7 +11,7 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_LF.h" namespace cln { @@ -22,7 +22,7 @@ static void eval_pqb_series_aux (uintC N1, uintC N2, { switch (N2 - N1) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: { var cl_pqb_series_term v0 = args.next(); // [N1] if (P) { *P = v0.p; } diff --git a/src/float/transcendental/cl_LF_ratsumseries_pqcd.cc b/src/float/transcendental/cl_LF_ratsumseries_pqcd.cc index 7c22c81..009beea 100644 --- a/src/float/transcendental/cl_LF_ratsumseries_pqcd.cc +++ b/src/float/transcendental/cl_LF_ratsumseries_pqcd.cc @@ -11,7 +11,6 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" #include "cl_LF.h" namespace cln { diff --git a/src/float/transcendental/cl_LF_ratsumseries_pqcd_aux.cc b/src/float/transcendental/cl_LF_ratsumseries_pqcd_aux.cc index 232214e..0e023ac 100644 --- a/src/float/transcendental/cl_LF_ratsumseries_pqcd_aux.cc +++ b/src/float/transcendental/cl_LF_ratsumseries_pqcd_aux.cc @@ -10,7 +10,7 @@ // Implementation. #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -19,7 +19,7 @@ void eval_pqcd_series_aux (uintC N, cl_pqcd_series_term* args, cl_pqcd_series_re // N = N2-N1 switch (N) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (!rightmost) { Z.P = args[0].p; } Z.Q = args[0].q; diff --git a/src/float/transcendental/cl_LF_ratsumseries_pqd.cc b/src/float/transcendental/cl_LF_ratsumseries_pqd.cc index 7db496c..7d70ad7 100644 --- a/src/float/transcendental/cl_LF_ratsumseries_pqd.cc +++ b/src/float/transcendental/cl_LF_ratsumseries_pqd.cc @@ -11,7 +11,6 @@ #include "cln/lfloat.h" #include "cln/integer.h" -#include "cln/abort.h" #include "cl_LF.h" namespace cln { diff --git a/src/float/transcendental/cl_LF_ratsumseries_pqd_aux.cc b/src/float/transcendental/cl_LF_ratsumseries_pqd_aux.cc index 7abf666..f6886bd 100644 --- a/src/float/transcendental/cl_LF_ratsumseries_pqd_aux.cc +++ b/src/float/transcendental/cl_LF_ratsumseries_pqd_aux.cc @@ -10,7 +10,7 @@ // Implementation. #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -19,7 +19,7 @@ void eval_pqd_series_aux (uintC N, cl_pqd_series_term* args, cl_pqd_series_resul // N = N2-N1 switch (N) { case 0: - cl_abort(); break; + throw runtime_exception(); break; case 1: if (!rightmost) { Z.P = args[0].p; } Z.Q = args[0].q; diff --git a/src/float/transcendental/cl_LF_zeta_int.cc b/src/float/transcendental/cl_LF_zeta_int.cc index 6070fd5..3f80cdd 100644 --- a/src/float/transcendental/cl_LF_zeta_int.cc +++ b/src/float/transcendental/cl_LF_zeta_int.cc @@ -13,7 +13,7 @@ #include "cl_LF_tran.h" #include "cl_LF.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_alloca.h" namespace cln { @@ -137,7 +137,7 @@ const cl_LF compute_zeta_cvz2 (int s, uintC len) const cl_LF zeta (int s, uintC len) { if (!(s > 1)) - cl_abort(); + throw runtime_exception(); if (len < 280*(uintL)s) return compute_zeta_cvz1(s,len); else diff --git a/src/integer/algebraic/cl_I_sqrt.cc b/src/integer/algebraic/cl_I_sqrt.cc index 9de7f74..44a5eb1 100644 --- a/src/integer/algebraic/cl_I_sqrt.cc +++ b/src/integer/algebraic/cl_I_sqrt.cc @@ -12,19 +12,20 @@ #include "cln/number.h" #include "cln/io.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_I.h" #include "cl_DS.h" +#include <sstream> namespace cln { cl_boolean isqrt (const cl_I& x, cl_I* w) { if (minusp(x)) { - fprint(std::cerr, "isqrt: applied to negative number: "); - fprint(std::cerr, x); - fprint(std::cerr, "\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "isqrt: applied to negative number: "); + fprint(buf, x); + throw runtime_exception(buf.str()); } CL_ALLOCA_STACK; var const uintD* x_MSDptr; diff --git a/src/integer/bitwise/cl_I_ash.cc b/src/integer/bitwise/cl_I_ash.cc index db355e4..19c9f1c 100644 --- a/src/integer/bitwise/cl_I_ash.cc +++ b/src/integer/bitwise/cl_I_ash.cc @@ -11,7 +11,6 @@ #include "cl_I.h" #include "cl_DS.h" -#include "cl_I_ash.h" namespace cln { @@ -42,7 +41,7 @@ const cl_I ash (const cl_I& x, sintC y) var const uintD* x_LSDptr; I_to_NDS_nocopy(x, ,len=,x_LSDptr=,cl_false,); // DS zu x bilden. if (k >= (uintC)(~len)) // kann len+k+1 �berlauf geben? - { cl_ash_error(y); } // ja -> Fehler + { throw ash_exception(y); } // ja -> Fehler num_stack_alloc_1(len+k,,LSDptr=); LSDptr = clear_loop_lsp(LSDptr,k); // k Nulldigits {var uintD* MSDptr = copy_loop_lsp(x_LSDptr,LSDptr,len); diff --git a/src/integer/bitwise/cl_I_ash.h b/src/integer/bitwise/cl_I_ash.h deleted file mode 100644 index 1a15c60..0000000 --- a/src/integer/bitwise/cl_I_ash.h +++ /dev/null @@ -1,16 +0,0 @@ -// cl_I internals for ash - -#ifndef _CL_I_ASH_H -#define _CL_I_ASH_H - -#include "cln/number.h" -#include "cln/integer_class.h" -#include "cl_macros.h" - -namespace cln { - -nonreturning_function(extern, cl_ash_error, (const cl_I& badamount)); - -} // namespace cln - -#endif /* _CL_I_ASH_H */ diff --git a/src/integer/bitwise/cl_I_ash_I.cc b/src/integer/bitwise/cl_I_ash_I.cc index f10e2e7..cee74a3 100644 --- a/src/integer/bitwise/cl_I_ash_I.cc +++ b/src/integer/bitwise/cl_I_ash_I.cc @@ -11,7 +11,6 @@ #include "cl_I.h" #include "cl_DS.h" -#include "cl_I_ash.h" namespace cln { @@ -39,19 +38,19 @@ const cl_I ash (const cl_I& x, const cl_I& y) if (bignump(y)) { #if (log2_intDsize+intCsize <= cl_value_len-1) // y >= 2^(cl_value_len-1) >= intDsize*2^intCsize - cl_ash_error(y); + throw ash_exception(y); #else // y >= 2^(cl_value_len-1) // usable only if y < intDsize*2^intCsize var cl_heap_bignum* bn = TheBignum(y); var uintC len = bn->length; if (len > ceiling(log2_intDsize+intCsize+1,intDsize)) - cl_ash_error(y); + throw ash_exception(y); // bn_minlength <= len <= ceiling(log2_intDsize+intCsize+1,intDsize). if (bn_minlength == ceiling(log2_intDsize+intCsize+1,intDsize) || len == ceiling(log2_intDsize+intCsize+1,intDsize)) if (mspref(arrayMSDptr(bn->data,len),0) >= (uintD)bit((log2_intDsize+intCsize)%intDsize)) - cl_ash_error(y); + throw ash_exception(y); #if (log2_intDsize+intCsize > intDsize) #define IF_LENGTH(i) \ if (bn_minlength <= i && i <= ceiling(log2_intDsize+intCsize+1,intDsize) && (i == ceiling(log2_intDsize+intCsize+1,intDsize) || len == i)) @@ -66,7 +65,7 @@ const cl_I ash (const cl_I& x, const cl_I& y) else IF_LENGTH(5) k = get_uint4D_Dptr(arrayLSDptr(bn->data,5) lspop 1); else - cl_abort(); + throw runtime_exception(); #undef IF_LENGTH k = k << (intDsize-log2_intDsize); #else @@ -87,7 +86,7 @@ const cl_I ash (const cl_I& x, const cl_I& y) var const uintD* x_LSDptr; I_to_NDS_nocopy(x, ,len=,x_LSDptr=,cl_false,); // DS zu x bilden. if (k >= (uintC)(~len)) // kann len+k+1 �berlauf geben? - { cl_ash_error(y); } // ja -> Fehler + { throw ash_exception(y); } // ja -> Fehler num_stack_alloc_1(len+k,,LSDptr=); LSDptr = clear_loop_lsp(LSDptr,k); // k Nulldigits var uintD* MSDptr = copy_loop_lsp(x_LSDptr,LSDptr,len); @@ -143,7 +142,7 @@ const cl_I ash (const cl_I& x, const cl_I& y) else IF_LENGTH(5) k = ~get_sint4D_Dptr(arrayLSDptr(bn->data,5) lspop 1); else - cl_abort(); + throw runtime_exception(); #undef IF_LENGTH k = k << (intDsize-log2_intDsize); #else diff --git a/src/integer/bitwise/cl_I_ash_exception.cc b/src/integer/bitwise/cl_I_ash_exception.cc new file mode 100644 index 0000000..c5f00ac --- /dev/null +++ b/src/integer/bitwise/cl_I_ash_exception.cc @@ -0,0 +1,30 @@ +// ash_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cln/integer.h" + + +// Implementation. +#include "cln/io.h" +#include "cln/integer_io.h" +#include <sstream> + +namespace cln { + +static inline const std::string +ash_error_msg (const cl_I& badamount) +{ + std::ostringstream buf; + fprint(buf, "ash: too large shift amount: "); + fprint(buf, badamount); + return buf.str(); +} + +ash_exception::ash_exception (const cl_I& badamount) + : runtime_exception(ash_error_msg(badamount)) +{} + +} // namespace cln diff --git a/src/integer/bitwise/cl_I_asherr.cc b/src/integer/bitwise/cl_I_asherr.cc deleted file mode 100644 index 24dda4d..0000000 --- a/src/integer/bitwise/cl_I_asherr.cc +++ /dev/null @@ -1,27 +0,0 @@ -// cl_ash_error(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_I_ash.h" - - -// Implementation. - -#include "cln/number.h" -#include "cln/io.h" -#include "cln/integer_io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_ash_error (const cl_I& badamount) -{ - fprint(std::cerr, "ash: too large shift amount: "); - fprint(std::cerr, badamount); - fprint(std::cerr, "\n"); - cl_abort(); -} - -} // namespace cln diff --git a/src/integer/bitwise/cl_I_logbitp_I.cc b/src/integer/bitwise/cl_I_logbitp_I.cc index c1b87ad..bb26201 100644 --- a/src/integer/bitwise/cl_I_logbitp_I.cc +++ b/src/integer/bitwise/cl_I_logbitp_I.cc @@ -13,7 +13,8 @@ #include "cl_DS.h" #include "cln/io.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" +#include <sstream> namespace cln { @@ -44,10 +45,10 @@ cl_boolean logbitp (const cl_I& x, const cl_I& y) } else // x<0 - { fprint(std::cerr, "logbitp: Index is negative: "); - fprint(std::cerr, x); - fprint(std::cerr, "\n"); - cl_abort(); + { std::ostringstream buf; + fprint(buf, "logbitp: Index is negative: "); + fprint(buf, x); + throw runtime_exception(buf.str()); } } diff --git a/src/integer/cl_I.h b/src/integer/cl_I.h index 282aece..17bc537 100644 --- a/src/integer/cl_I.h +++ b/src/integer/cl_I.h @@ -7,7 +7,7 @@ #include "cln/integer.h" #include "cl_macros.h" #include "cln/malloc.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_offsetof.h" #include "cl_DS.h" @@ -474,9 +474,9 @@ inline sintD FN_MSD (cl_uint word) #if (FN_maxlength==1) #define FN_LSD0(word) FN_MSD(word) - #define FN_LSD1(word) (cl_abort(), (uintD)0) // never used - #define FN_LSD2(word) (cl_abort(), (uintD)0) // never used - #define FN_LSD3(word) (cl_abort(), (uintD)0) // never used + #define FN_LSD1(word) (throw runtime_exception(), (uintD)0) // never used + #define FN_LSD2(word) (throw runtime_exception(), (uintD)0) // never used + #define FN_LSD3(word) (throw runtime_exception(), (uintD)0) // never used #endif #if (FN_maxlength==2) inline uintD FN_LSD0 (cl_uint word) @@ -484,8 +484,8 @@ inline sintD FN_MSD (cl_uint word) return (uintD)(word >> cl_value_shift); } #define FN_LSD1(word) FN_MSD(word) - #define FN_LSD2(word) (cl_abort(), (uintD)0) // never used - #define FN_LSD3(word) (cl_abort(), (uintD)0) // never used + #define FN_LSD2(word) (throw runtime_exception(), (uintD)0) // never used + #define FN_LSD3(word) (throw runtime_exception(), (uintD)0) // never used #endif #if (FN_maxlength==4) inline uintD FN_LSD0 (cl_uint word) @@ -656,9 +656,6 @@ inline sintD FN_MSD (cl_uint word) // < q,r: Quotient q, Rest r extern const cl_I_div_t cl_divide (const cl_I& x, const cl_I& y); -// Fehler, wenn Quotient keine ganze Zahl ist - nonreturning_function(extern, cl_error_exquo, (const cl_I& x, const cl_I& y)); - // ggT und kgV von Integers diff --git a/src/integer/conv/cl_I_to_L.cc b/src/integer/conv/cl_I_to_L.cc index dc337eb..52d59c9 100644 --- a/src/integer/conv/cl_I_to_L.cc +++ b/src/integer/conv/cl_I_to_L.cc @@ -14,7 +14,8 @@ #include "cl_DS.h" #include "cln/io.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" +#include <sstream> namespace cln { @@ -76,10 +77,10 @@ sint32 cl_I_to_L (const cl_I& obj) } } bad: // unpassendes Objekt - fprint(std::cerr, "Not a 32-bit integer: "); - fprint(std::cerr, obj); - fprint(std::cerr, "\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "Not a 32-bit integer: "); + fprint(buf, obj); + throw runtime_exception(buf.str()); } } // namespace cln diff --git a/src/integer/conv/cl_I_to_Q.cc b/src/integer/conv/cl_I_to_Q.cc index 99a7344..13197c3 100644 --- a/src/integer/conv/cl_I_to_Q.cc +++ b/src/integer/conv/cl_I_to_Q.cc @@ -15,7 +15,8 @@ #include "cl_DS.h" #include "cln/io.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" +#include <sstream> namespace cln { @@ -131,10 +132,10 @@ sint64 cl_I_to_Q (const cl_I& obj) #undef IF_LENGTH } bad: // unpassendes Objekt - fprint(std::cerr, "Not a 64-bit integer: "); - fprint(std::cerr, obj); - fprint(std::cerr, "\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "Not a 64-bit integer: "); + fprint(buf, obj); + throw runtime_exception(buf.str()); } } diff --git a/src/integer/conv/cl_I_to_UL.cc b/src/integer/conv/cl_I_to_UL.cc index 2e8d9ea..7ee081d 100644 --- a/src/integer/conv/cl_I_to_UL.cc +++ b/src/integer/conv/cl_I_to_UL.cc @@ -14,7 +14,8 @@ #include "cl_DS.h" #include "cln/io.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" +#include <sstream> namespace cln { @@ -57,10 +58,10 @@ uint32 cl_I_to_UL (const cl_I& obj) #undef IF_LENGTH } bad: // unpassendes Objekt - fprint(std::cerr, "Not a 32-bit integer: "); - fprint(std::cerr, obj); - fprint(std::cerr, "\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "Not a 32-bit integer: "); + fprint(buf, obj); + throw runtime_exception(buf.str()); } } // namespace cln diff --git a/src/integer/conv/cl_I_to_UQ.cc b/src/integer/conv/cl_I_to_UQ.cc index 2dd15ed..5f30e50 100644 --- a/src/integer/conv/cl_I_to_UQ.cc +++ b/src/integer/conv/cl_I_to_UQ.cc @@ -15,7 +15,8 @@ #include "cl_DS.h" #include "cln/io.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" +#include <sstream> namespace cln { @@ -91,10 +92,10 @@ uint64 cl_I_to_UQ (const cl_I& obj) #undef IF_LENGTH } bad: // unpassendes Objekt - fprint(std::cerr, "Not a 64-bit integer: "); - fprint(std::cerr, obj); - fprint(std::cerr, "\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "Not a 64-bit integer: "); + fprint(buf, obj); + throw runtime_exception(buf.str()); } } // namespace cln diff --git a/src/integer/conv/cl_I_to_digits.cc b/src/integer/conv/cl_I_to_digits.cc index b5d8a84..d661b81 100644 --- a/src/integer/conv/cl_I_to_digits.cc +++ b/src/integer/conv/cl_I_to_digits.cc @@ -49,7 +49,7 @@ namespace cln { static inline void I_to_digits_noshrink (const cl_I& X, uintD base, uintC erg_len, cl_digits* erg) { I_to_digits(X,base,erg); - if (erg->len > erg_len) cl_abort(); + if (erg->len > erg_len) throw runtime_exception(); var uintC count = erg_len - erg->len; if (count > 0) { var uintB* ptr = erg->MSBptr; @@ -179,10 +179,10 @@ void I_to_digits (const cl_I& X, uintD base, cl_digits* erg) // floor(2^ilen_X/B) = floor(floor(2^(2*ilen_B)/B)/2^(2*ilen_B-ilen_X)) var cl_I q = (X * (p->inv_base_pow >> (2*ilen_B-ilen_X))) >> ilen_X; var cl_I r = X - q * p->base_pow; - if (r < 0) cl_abort(); + if (r < 0) throw runtime_exception(); if (r >= p->base_pow) { q = q+1; r = r - p->base_pow; - if (r >= p->base_pow) cl_abort(); + if (r >= p->base_pow) throw runtime_exception(); } #else var cl_I_div_t q_r = floor2(X,p->base_pow); diff --git a/src/integer/division/cl_I_exquo.cc b/src/integer/division/cl_I_exquo.cc index 771eef8..5028e72 100644 --- a/src/integer/division/cl_I_exquo.cc +++ b/src/integer/division/cl_I_exquo.cc @@ -21,7 +21,7 @@ const cl_I exquo (const cl_I& x, const cl_I& y) // Falls r<>0, Error. // Falls x,y verschiedene Vorzeichen haben, liefere -q, sonst q. var cl_I_div_t q_r = cl_divide(abs(x),abs(y)); - if (!zerop(q_r.remainder)) { cl_error_exquo(x,y); } + if (!zerop(q_r.remainder)) { throw exquo_exception(x,y); } if (minusp(x) == minusp(y)) { return q_r.quotient; } else diff --git a/src/integer/division/cl_I_exquo_exception.cc b/src/integer/division/cl_I_exquo_exception.cc new file mode 100644 index 0000000..6ac671e --- /dev/null +++ b/src/integer/division/cl_I_exquo_exception.cc @@ -0,0 +1,34 @@ +// exquo_exception(). + +// General includes. +#include "cl_sysdep.h" + +// Specification. +#include "cln/integer.h" + + +// Implementation. + +#include "cln/io.h" +#include "cln/integer_io.h" +#include <sstream> + +namespace cln { + +static inline const std::string +exquo_error_msg (const cl_I& x, const cl_I& y) +{ + std::ostringstream buf; + fprint(buf, "Quotient "); + fprint(buf, x); + fprint(buf, " / "); + fprint(buf, y); + fprint(buf, " is not an integer."); + return buf.str(); +} + +exquo_exception::exquo_exception (const cl_I& x, const cl_I& y) + : runtime_exception(exquo_error_msg(x,y)) +{} + +} // namespace cln diff --git a/src/integer/division/cl_I_exquoerr.cc b/src/integer/division/cl_I_exquoerr.cc deleted file mode 100644 index a8198ac..0000000 --- a/src/integer/division/cl_I_exquoerr.cc +++ /dev/null @@ -1,28 +0,0 @@ -// cl_error_exquo(). - -// General includes. -#include "cl_sysdep.h" - -// Specification. -#include "cl_I.h" - - -// Implementation. - -#include "cln/io.h" -#include "cln/integer_io.h" -#include "cln/abort.h" - -namespace cln { - -void cl_error_exquo (const cl_I& x, const cl_I& y) -{ - 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(); -} - -} // namespace cln diff --git a/src/integer/division/cl_I_exquopos.cc b/src/integer/division/cl_I_exquopos.cc index 5e28f72..2ec651d 100644 --- a/src/integer/division/cl_I_exquopos.cc +++ b/src/integer/division/cl_I_exquopos.cc @@ -21,7 +21,7 @@ const cl_I exquopos (const cl_I& x, const cl_I& y) // Falls r<>0, Error. // Liefere q. var cl_I_div_t q_r = cl_divide(x,y); - if (!zerop(q_r.remainder)) { cl_error_exquo(x,y); } + if (!zerop(q_r.remainder)) { throw exquo_exception(x,y); } return q_r.quotient; } diff --git a/src/integer/elem/cl_I_div.cc b/src/integer/elem/cl_I_div.cc index b0307d7..b88661b 100644 --- a/src/integer/elem/cl_I_div.cc +++ b/src/integer/elem/cl_I_div.cc @@ -9,7 +9,7 @@ // Implementation. -#include "cl_N.h" +#include "cln/exception.h" namespace cln { @@ -25,7 +25,7 @@ namespace cln { // auch y Fixnum >=0 { var uintV x_ = FN_to_UV(x); var uintV y_ = FN_to_UV(y); - if (y_==0) { cl_error_division_by_0(); } + if (y_==0) { throw division_by_0_exception(); } elif (x_ < y_) // Trivialfall: q=0, r=x goto trivial; diff --git a/src/integer/gcd/cl_I_gcd_aux2.cc b/src/integer/gcd/cl_I_gcd_aux2.cc index 507220d..2a4fc03 100644 --- a/src/integer/gcd/cl_I_gcd_aux2.cc +++ b/src/integer/gcd/cl_I_gcd_aux2.cc @@ -54,7 +54,7 @@ static uintD floorDD (uintDD x, uintDD y) var uintDD p = muluDD_unchecked(q,y); #ifdef DEBUG_GCD if (x < p) - cl_abort(); + throw runtime_exception(); #endif x -= p; } @@ -66,7 +66,7 @@ static uintD floorDD (uintDD x, uintDD y) #ifdef DEBUG_GCD x -= y; if (x >= y) - cl_abort(); + throw runtime_exception(); #endif } } @@ -118,7 +118,7 @@ void partial_gcd (uintDD z1, uintDD z2, partial_gcd_result* erg) if (x2 > ~x1) goto done; if (y2 > ~y1) goto done; #ifdef DEBUG_GCD - if (z1 < z2) cl_abort(); + if (z1 < z2) throw runtime_exception(); #endif // Now really subtract. x1 += x2; @@ -166,7 +166,7 @@ void partial_gcd (uintDD z1, uintDD z2, partial_gcd_result* erg) if (x1 > ~x2) goto done; if (y1 > ~y2) goto done; #ifdef DEBUG_GCD - if (z2 < z1) cl_abort(); + if (z2 < z1) throw runtime_exception(); #endif // Now really subtract. x2 += x1; @@ -219,7 +219,7 @@ static uintD floorDD (uintD xhi, uintD xlo, uintD yhi, uintD ylo) muluD(q,yhi, , phi +=); #ifdef DEBUG_GCD if ((xhi < phi) || ((xhi == phi) && (xlo < plo))) - cl_abort(); + throw runtime_exception(); #endif xhi = xhi - phi; if (xlo < plo) @@ -240,7 +240,7 @@ static uintD floorDD (uintD xhi, uintD xlo, uintD yhi, uintD ylo) xhi -= 1; xlo = xlo - ylo; if ((xhi > yhi) || ((xhi == yhi) && (xlo >= ylo))) - cl_abort(); + throw runtime_exception(); #endif } } @@ -316,8 +316,8 @@ void partial_gcd (uintD z1hi, uintD z1lo, uintD z2hi, uintD z2lo, partial_gcd_re if (x2 > ~x1) goto done; if (y2 > ~y1) goto done; #ifdef DEBUG_GCD - if (z1hi < z2hi) cl_abort(); - if (z1hi == z2hi) if (z1lo < z2lo) cl_abort(); + if (z1hi < z2hi) throw runtime_exception(); + if (z1hi == z2hi) if (z1lo < z2lo) throw runtime_exception(); #endif // Now really subtract. x1 += x2; @@ -412,8 +412,8 @@ void partial_gcd (uintD z1hi, uintD z1lo, uintD z2hi, uintD z2lo, partial_gcd_re if (x1 > ~x2) goto done; if (y1 > ~y2) goto done; #ifdef DEBUG_GCD - if (z2hi < z1hi) cl_abort(); - if (z2hi == z1hi) if (z2lo < z1lo) cl_abort(); + if (z2hi < z1hi) throw runtime_exception(); + if (z2hi == z1hi) if (z2lo < z1lo) throw runtime_exception(); #endif // Now really subtract. x2 += x1; diff --git a/src/integer/input/cl_I_read.cc b/src/integer/input/cl_I_read.cc index 430f568..d3faace 100644 --- a/src/integer/input/cl_I_read.cc +++ b/src/integer/input/cl_I_read.cc @@ -12,10 +12,10 @@ // Implementation. #include <cstring> +#include <sstream> #include "cln/input.h" #include "cln/integer.h" #include "cl_I.h" -#include "cln/abort.h" namespace cln { @@ -47,7 +47,7 @@ static const char * skip_digits (const char * ptr, const char * string_limit, un if (end_of_parse) \ { *end_of_parse = (ptr); } \ else \ - { if ((ptr) != string_limit) { read_number_junk((ptr),string,string_limit); } } + { if ((ptr) != string_limit) { throw read_number_junk_exception((ptr),string,string_limit); } } const cl_I read_integer (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse) { @@ -81,10 +81,10 @@ const cl_I read_integer (const cl_read_flags& flags, const char * string, const goto not_integer_syntax; var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr); if (!((base >= 2) && (base <= 36))) { - 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(); + std::ostringstream buf; + fprint(buf, "Base must be an integer in the range from 2 to 36, not "); + fprint(buf, base); + throw runtime_exception(buf.str()); } rational_base = FN_to_UV(base); ptr = base_end_ptr; break; @@ -127,7 +127,7 @@ not_integer_syntax: *end_of_parse = string; return 0; // dummy return } - read_number_bad_syntax(string,string_limit); + throw read_number_bad_syntax_exception(string,string_limit); } } // namespace cln diff --git a/src/integer/input/cl_I_read_stream.cc b/src/integer/input/cl_I_read_stream.cc index 6f6a5c0..eeae222 100644 --- a/src/integer/input/cl_I_read_stream.cc +++ b/src/integer/input/cl_I_read_stream.cc @@ -98,10 +98,10 @@ const cl_I read_integer (std::istream& stream, const cl_read_flags& flags) // Handle syntax error. syntax1: buffer.push(c); - read_number_bad_syntax(buffer.start_pointer(),buffer.end_pointer()); + throw read_number_bad_syntax_exception(buffer.start_pointer(),buffer.end_pointer()); // Handle premature EOF. -eof: read_number_eof(); +eof: throw read_number_eof_exception(); } } // namespace cln diff --git a/src/integer/misc/cl_I_as.cc b/src/integer/misc/cl_I_as.cc index 6759c13..fcbd839 100644 --- a/src/integer/misc/cl_I_as.cc +++ b/src/integer/misc/cl_I_as.cc @@ -36,7 +36,7 @@ const cl_I& cl_I_As (const cl_number& x, const char * filename, int line) DeclareType(cl_I,x); return x; } else - cl_as_error(x,"an integer",filename,line); + throw as_exception(x,"an integer",filename,line); } } // namespace cln diff --git a/src/modinteger/cl_MI.cc b/src/modinteger/cl_MI.cc index 297718d..071028b 100644 --- a/src/modinteger/cl_MI.cc +++ b/src/modinteger/cl_MI.cc @@ -18,7 +18,7 @@ CL_PROVIDE(cl_MI) #include "cln/integer_io.h" #include "cl_N.h" #include "cl_MI.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_alloca.h" // MacOS X does "#define _R 0x00040000L" @@ -42,7 +42,7 @@ cl_heap_modint_ring::cl_heap_modint_ring (cl_I m, cl_modint_setops* setopv, cl_m { refcount = 0; // will be incremented by the `cl_modint_ring' constructor type = &cl_class_modint_ring; - if (minusp(m)) cl_abort(); + if (minusp(m)) throw runtime_exception(); if (!cln::zerop(m)) { var uintC b = integer_length(m-1); // m <= 2^b, hence one needs b bits for a representative mod m. @@ -172,7 +172,7 @@ const cl_modint_ring find_modint_ring (const cl_I& m) store_modint_ring(R); ring_in_table = get_modint_ring(m); if (!ring_in_table) - cl_abort(); + throw runtime_exception(); } return *ring_in_table; }} diff --git a/src/modinteger/cl_MI_err_comp.cc b/src/modinteger/cl_MI_err_comp.cc index 536cf93..4859061 100644 --- a/src/modinteger/cl_MI_err_comp.cc +++ b/src/modinteger/cl_MI_err_comp.cc @@ -10,7 +10,6 @@ // Implementation. #include "cln/io.h" -#include "cln/abort.h" namespace cln { diff --git a/src/modinteger/cl_MI_int.h b/src/modinteger/cl_MI_int.h index fe70d49..0fbfe52 100644 --- a/src/modinteger/cl_MI_int.h +++ b/src/modinteger/cl_MI_int.h @@ -31,8 +31,7 @@ static const _cl_MI int_random (cl_heap_modint_ring* R, random_state& randomstat { unused R; unused randomstate; - fprint(std::cerr, "Z / 0 Z not a finite set - no equidistributed random function.\n"); - cl_abort(); + throw runtime_exception("Z / 0 Z not a finite set - no equidistributed random function."); #if ((defined(__sparc__) || defined(__sparc64__)) && !defined(__GNUC__)) // Sun CC wants a return value return _cl_MI(R, 0); #endif @@ -83,7 +82,7 @@ static const cl_MI_x int_recip (cl_heap_modint_ring* R, const _cl_MI& x) { var const cl_I& xr = x.rep; if (eq(xr,1) || eq(xr,-1)) { return cl_MI(R,x); } - if (zerop(xr)) { cl_error_division_by_0(); } + if (zerop(xr)) { throw division_by_0_exception(); } return cl_notify_composite(R,xr); } @@ -92,7 +91,7 @@ static const cl_MI_x int_div (cl_heap_modint_ring* R, const _cl_MI& x, const _cl var const cl_I& yr = y.rep; if (eq(yr,1)) { return cl_MI(R,x.rep); } if (eq(yr,-1)) { return cl_MI(R,-x.rep); } - if (zerop(yr)) { cl_error_division_by_0(); } + if (zerop(yr)) { throw division_by_0_exception(); } return cl_notify_composite(R,yr); } @@ -112,7 +111,7 @@ static const cl_MI_x int_expt (cl_heap_modint_ring* R, const _cl_MI& x, const cl return cl_MI(R,expt_pos(x.rep,y)); } // y < 0, x nonunit. - if (zerop(x.rep)) { cl_error_division_by_0(); } + if (zerop(x.rep)) { throw division_by_0_exception(); } return cl_notify_composite(R,x.rep); } diff --git a/src/modinteger/cl_MI_montgom.h b/src/modinteger/cl_MI_montgom.h index c5c7a4c..0f944c3 100644 --- a/src/modinteger/cl_MI_montgom.h +++ b/src/modinteger/cl_MI_montgom.h @@ -135,7 +135,7 @@ static const cl_MI_x montgom_recip (cl_heap_modint_ring* _R, const _cl_MI& x) if (eq(g,1)) return cl_MI(R, mod((minusp(u) ? u + R->modulus : u) << (2*R->n), R->modulus)); if (zerop(xr)) - cl_error_division_by_0(); + throw division_by_0_exception(); return cl_notify_composite(R,xr); } @@ -149,7 +149,7 @@ static const cl_MI_x montgom_div (cl_heap_modint_ring* _R, const _cl_MI& x, cons if (eq(g,1)) return cl_MI(R, mod((x.rep * (minusp(u) ? u + R->modulus : u)) << R->n, R->modulus)); if (zerop(yr)) - cl_error_division_by_0(); + throw division_by_0_exception(); return cl_notify_composite(R,yr); } @@ -230,7 +230,7 @@ static cl_heap_modint_ring* try_make_modint_ring_montgom (const cl_I& M) var cl_I U = DS_to_I(U_LSDptr lspop U_len,U_len); var cl_I V_N = 1 - U*M; if (ldb_test(V_N,cl_byte(n,0))) - cl_abort(); + throw runtime_exception(); var cl_I V = V_N >> n; return new cl_heap_modint_ring_montgom(M,m,n,V); } diff --git a/src/modinteger/cl_MI_pow2.h b/src/modinteger/cl_MI_pow2.h index 8511600..c891a1a 100644 --- a/src/modinteger/cl_MI_pow2.h +++ b/src/modinteger/cl_MI_pow2.h @@ -85,7 +85,7 @@ static const cl_MI_x pow2_recip (cl_heap_modint_ring* _R, const _cl_MI& x) if (R->m1 == 0) return cl_MI(R, 0); if (zerop(xr)) - cl_error_division_by_0(); + throw division_by_0_exception(); else return cl_notify_composite(R,xr); } else @@ -110,7 +110,7 @@ static const cl_MI_x pow2_div (cl_heap_modint_ring* _R, const _cl_MI& x, const _ if (R->m1 == 0) return cl_MI(R, 0); if (zerop(yr)) - cl_error_division_by_0(); + throw division_by_0_exception(); else return cl_notify_composite(R,yr); } else diff --git a/src/modinteger/cl_MI_rshift.cc b/src/modinteger/cl_MI_rshift.cc index 957d170..a5a4ffe 100644 --- a/src/modinteger/cl_MI_rshift.cc +++ b/src/modinteger/cl_MI_rshift.cc @@ -10,7 +10,7 @@ // Implementation. #include "cln/integer.h" -#include "cl_N.h" +#include "cln/exception.h" #include "cl_MI.h" namespace cln { @@ -22,7 +22,7 @@ const cl_MI operator>> (const cl_MI& x, sintC y) // assume 0 <= y < 2^(intCsize- var const cl_modint_ring& R = x.ring(); if (!oddp(R->modulus)) { if (R->modulus == 2) - cl_error_division_by_0(); + throw division_by_0_exception(); else return (cl_MI_x)cl_notify_composite(R,2); } @@ -37,7 +37,7 @@ const cl_MI operator>> (const cl_MI& x, sintC y) // assume 0 <= y < 2^(intCsize- // Use algorithm 1 for small y, algorithm 2 for large y. #if 0 if (y <= 2*R->bits) - cl_abort(); // not yet implemented + throw runtime_exception(); // not yet implemented else #endif return R->div(x, expt_pos(R->canonhom(2), (cl_I)(long)y)); diff --git a/src/modinteger/cl_MI_std.h b/src/modinteger/cl_MI_std.h index 04fd37b..e704cc8 100644 --- a/src/modinteger/cl_MI_std.h +++ b/src/modinteger/cl_MI_std.h @@ -82,7 +82,7 @@ static const cl_MI_x std_recip (cl_heap_modint_ring* R, const _cl_MI& x) if (eq(g,1)) return cl_MI(R, (minusp(u) ? u + R->modulus : u)); if (zerop(xr)) - cl_error_division_by_0(); + throw division_by_0_exception(); return cl_notify_composite(R,xr); } @@ -95,7 +95,7 @@ static const cl_MI_x std_div (cl_heap_modint_ring* R, const _cl_MI& x, const _cl if (eq(g,1)) return cl_MI(R, mod(x.rep * (minusp(u) ? u + R->modulus : u), R->modulus)); if (zerop(yr)) - cl_error_division_by_0(); + throw division_by_0_exception(); return cl_notify_composite(R,yr); } @@ -258,7 +258,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const // Compute a = x^n_digits[nnk-1]. { var uintL d = n_digits[nnk-1]; - if (d == 0) cl_abort(); + if (d == 0) throw runtime_exception(); var uintL d2; if (k <= 8) d2 = ord2_table[d]; @@ -271,7 +271,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const if (d==0 && maxodd > 1 && d2>0) { a = x2; d2--; } - if (!(d2 < k)) cl_abort(); + if (!(d2 < k)) throw runtime_exception(); for ( ; d2>0; d2--) a = R->_square(a); } @@ -292,7 +292,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const } else d2 = k; // Square d2 times. - if (!(d2 <= k)) cl_abort(); + if (!(d2 <= k)) throw runtime_exception(); for ( ; d2>0; d2--) a = R->_square(a); } diff --git a/src/numtheory/cl_nt_cornacchia1.cc b/src/numtheory/cl_nt_cornacchia1.cc index dfdb89f..e43405a 100644 --- a/src/numtheory/cl_nt_cornacchia1.cc +++ b/src/numtheory/cl_nt_cornacchia1.cc @@ -80,7 +80,7 @@ const cornacchia_t cornacchia1 (const cl_I& d, const cl_I& p) if (init.condition) return init.condition; if (init.solutions != 2) - cl_abort(); + throw runtime_exception(); // Euclidean algorithm. var cl_I a = p; var cl_I b = R->retract(init.solution[0]); diff --git a/src/numtheory/cl_nt_cornacchia4.cc b/src/numtheory/cl_nt_cornacchia4.cc index 0d91abf..38204f3 100644 --- a/src/numtheory/cl_nt_cornacchia4.cc +++ b/src/numtheory/cl_nt_cornacchia4.cc @@ -92,7 +92,7 @@ const cornacchia_t cornacchia4 (const cl_I& d, const cl_I& p) if (init.condition) return init.condition; if (init.solutions != 2) - cl_abort(); + throw runtime_exception(); // Compute x with x^2+d == 0 mod 4*p. var cl_I x0 = R->retract(init.solution[0]); if (evenp(x0)) { x0 = p-x0; } // Enforce x0^2+d == 0 mod 4. diff --git a/src/numtheory/cl_nt_isprobprime.cc b/src/numtheory/cl_nt_isprobprime.cc index a761cf9..031fe29 100644 --- a/src/numtheory/cl_nt_isprobprime.cc +++ b/src/numtheory/cl_nt_isprobprime.cc @@ -10,14 +10,20 @@ // Implementation. #include "cl_IF.h" -#include "cln/abort.h" +#include "cln/integer_io.h" +#include "cln/exception.h" +#include <sstream> namespace cln { cl_boolean isprobprime (const cl_I& n) { - if (!(n > 0)) - cl_abort(); + if (!(n > 0)) { + std::ostringstream buf; + fprint(buf, n); + fprint(buf, " is not a positive integer."); + throw runtime_exception(buf.str()); + } // With a Miller-Rabin count = 50 the final error probability is // 4^-50 < 10^-30. var int count = 50; diff --git a/src/numtheory/cl_nt_jacobi.cc b/src/numtheory/cl_nt_jacobi.cc index 03a1169..e4cf10c 100644 --- a/src/numtheory/cl_nt_jacobi.cc +++ b/src/numtheory/cl_nt_jacobi.cc @@ -11,7 +11,7 @@ #include "cln/integer.h" #include "cl_I.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_xmacros.h" namespace cln { @@ -20,9 +20,9 @@ int jacobi (const cl_I& a, const cl_I& b) { // Check b > 0, b odd. if (!(b > 0)) - cl_abort(); + throw runtime_exception(); if (!oddp(b)) - cl_abort(); + throw runtime_exception(); { Mutable(cl_I,a); Mutable(cl_I,b); // Ensure 0 <= a < b. diff --git a/src/numtheory/cl_nt_jacobi_low.cc b/src/numtheory/cl_nt_jacobi_low.cc index 6a55823..7b706a2 100644 --- a/src/numtheory/cl_nt_jacobi_low.cc +++ b/src/numtheory/cl_nt_jacobi_low.cc @@ -9,7 +9,7 @@ // Implementation. -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_xmacros.h" namespace cln { @@ -33,7 +33,7 @@ inline int jacobi_aux (uintV a, uintV b) switch (b % 4) { case 1: break; case 3: v = -v; break; - default: cl_abort(); + default: throw runtime_exception(); } continue; } @@ -44,7 +44,7 @@ inline int jacobi_aux (uintV a, uintV b) switch (b % 8) { case 1: case 7: break; case 3: case 5: v = -v; break; - default: cl_abort(); + default: throw runtime_exception(); } continue; } @@ -65,9 +65,9 @@ int jacobi (sintV a, sintV b) { // Check b > 0, b odd. if (!(b > 0)) - cl_abort(); + throw runtime_exception(); if ((b & 1) == 0) - cl_abort(); + throw runtime_exception(); // Ensure 0 <= a < b. if (a >= 0) a = (uintV)a % (uintV)b; diff --git a/src/numtheory/cl_nt_sqrtmodp.cc b/src/numtheory/cl_nt_sqrtmodp.cc index 3b95574..8c0741e 100644 --- a/src/numtheory/cl_nt_sqrtmodp.cc +++ b/src/numtheory/cl_nt_sqrtmodp.cc @@ -10,7 +10,7 @@ // Implementation. #include "cl_I.h" -#include "cln/abort.h" +#include "cln/exception.h" #undef floor #include <cmath> @@ -287,7 +287,7 @@ static const sqrt_mod_p_t tonelli_shanks_sqrt (const cl_modint_ring& R, const cl const sqrt_mod_p_t sqrt_mod_p (const cl_modint_ring& R, const cl_MI& a) { - if (!(a.ring() == R)) cl_abort(); + if (!(a.ring() == R)) throw runtime_exception(); var cl_I& p = R->modulus; var cl_I aa = R->retract(a); switch (jacobi(aa,p)) { diff --git a/src/polynomial/elem/cl_UP_GF2.h b/src/polynomial/elem/cl_UP_GF2.h index fa2c5b1..5306030 100644 --- a/src/polynomial/elem/cl_UP_GF2.h +++ b/src/polynomial/elem/cl_UP_GF2.h @@ -4,7 +4,7 @@ #include "cln/modinteger.h" #include "cln/GV_integer.h" #include "cl_DS.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -966,7 +966,7 @@ static const _cl_UP gf2_square (cl_heap_univpoly_ring* UPR, const _cl_UP& x) // Scalar multiplication of GF(2)-polynomials is trivial: 0*y = 0, 1*y = y. static const _cl_UP gf2_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, const _cl_UP& y) { - if (!(UPR->basering() == x.ring())) cl_abort(); + if (!(UPR->basering() == x.ring())) throw runtime_exception(); { DeclarePoly(_cl_MI,x); var cl_heap_modint_ring* R = TheModintRing(UPR->basering()); @@ -981,7 +981,7 @@ static const _cl_UP gf2_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_eleme static const cl_ring_element gf2_eval (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const cl_ring_element& y) {{ DeclarePoly(cl_GV_MI,x); - if (!(UPR->basering() == y.ring())) cl_abort(); + if (!(UPR->basering() == y.ring())) throw runtime_exception(); { DeclarePoly(_cl_MI,y); var cl_heap_modint_ring* R = TheModintRing(UPR->basering()); var const cl_heap_GV_I_bits1 * xv = (const cl_heap_GV_I_bits1 *) x.heappointer; diff --git a/src/polynomial/elem/cl_UP_MI.h b/src/polynomial/elem/cl_UP_MI.h index 62b2ea6..f76977a 100644 --- a/src/polynomial/elem/cl_UP_MI.h +++ b/src/polynomial/elem/cl_UP_MI.h @@ -2,7 +2,7 @@ #include "cln/GV_modinteger.h" #include "cln/modinteger.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -154,7 +154,7 @@ static const _cl_UP modint_uminus (cl_heap_univpoly_ring* UPR, const _cl_UP& x) // Negate. No normalization necessary, since the degree doesn't change. var sintL i = xlen-1; var _cl_MI hicoeff = R->_uminus(x[i]); - if (R->_zerop(hicoeff)) cl_abort(); + if (R->_zerop(hicoeff)) throw runtime_exception(); var cl_GV_MI result = cl_GV_MI(xlen,R); result[i] = hicoeff; for (i-- ; i >= 0; i--) @@ -269,7 +269,7 @@ static const _cl_UP modint_mul (cl_heap_univpoly_ring* UPR, const _cl_UP& x, con } // Normalize (not necessary in integral domains). //modint_normalize(R,result,len); - if (R->_zerop(result[len-1])) cl_abort(); + if (R->_zerop(result[len-1])) throw runtime_exception(); return _cl_UP(UPR, result); }} @@ -308,7 +308,7 @@ static const _cl_UP modint_square (cl_heap_univpoly_ring* UPR, const _cl_UP& x) result[0] = R->_square(x[0]); // Normalize (not necessary in integral domains). //modint_normalize(R,result,len); - if (R->_zerop(result[len-1])) cl_abort(); + if (R->_zerop(result[len-1])) throw runtime_exception(); return _cl_UP(UPR, result); }} @@ -328,7 +328,7 @@ static const _cl_UP modint_exptpos (cl_heap_univpoly_ring* UPR, const _cl_UP& x, static const _cl_UP modint_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, const _cl_UP& y) { - if (!(UPR->basering() == x.ring())) cl_abort(); + if (!(UPR->basering() == x.ring())) throw runtime_exception(); { DeclarePoly(_cl_MI,x); DeclarePoly(cl_GV_MI,y); @@ -367,7 +367,7 @@ static sintL modint_ldegree (cl_heap_univpoly_ring* UPR, const _cl_UP& x) static const _cl_UP modint_monomial (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, uintL e) { - if (!(UPR->basering() == x.ring())) cl_abort(); + if (!(UPR->basering() == x.ring())) throw runtime_exception(); { DeclarePoly(_cl_MI,x); var cl_heap_modint_ring* R = TheModintRing(UPR->basering()); if (R->_zerop(x)) @@ -404,9 +404,9 @@ static const _cl_UP modint_create (cl_heap_univpoly_ring* UPR, sintL deg) static void modint_set_coeff (cl_heap_univpoly_ring* UPR, _cl_UP& x, uintL index, const cl_ring_element& y) {{ DeclareMutablePoly(cl_GV_MI,x); - if (!(UPR->basering() == y.ring())) cl_abort(); + if (!(UPR->basering() == y.ring())) throw runtime_exception(); { DeclarePoly(_cl_MI,y); - if (!(index < x.length())) cl_abort(); + if (!(index < x.length())) throw runtime_exception(); x[index] = y; }}} @@ -426,7 +426,7 @@ static const cl_ring_element modint_eval (cl_heap_univpoly_ring* UPR, const _cl_ // If y = 0, return x[0]. // Else compute (...(x[len-1]*y+x[len-2])*y ...)*y + x[0]. DeclarePoly(cl_GV_MI,x); - if (!(UPR->basering() == y.ring())) cl_abort(); + if (!(UPR->basering() == y.ring())) throw runtime_exception(); { DeclarePoly(_cl_MI,y); var cl_heap_modint_ring* R = TheModintRing(UPR->basering()); var uintL len = x.length(); diff --git a/src/polynomial/elem/cl_UP_gen.h b/src/polynomial/elem/cl_UP_gen.h index 9c11643..dcfd6c7 100644 --- a/src/polynomial/elem/cl_UP_gen.h +++ b/src/polynomial/elem/cl_UP_gen.h @@ -2,7 +2,7 @@ #include "cln/SV_ringelt.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -142,7 +142,7 @@ static const _cl_UP gen_uminus (cl_heap_univpoly_ring* UPR, const _cl_UP& x) // Negate. No normalization necessary, since the degree doesn't change. var sintL i = xlen-1; var _cl_ring_element hicoeff = R->_uminus(x[i]); - if (R->_zerop(hicoeff)) cl_abort(); + if (R->_zerop(hicoeff)) throw runtime_exception(); var cl_SV_ringelt result = cl_SV_ringelt(cl_make_heap_SV_ringelt_uninit(xlen)); init1(_cl_ring_element, result[i]) (hicoeff); for (i-- ; i >= 0; i--) @@ -253,7 +253,7 @@ static const _cl_UP gen_mul (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const } // Normalize (not necessary in integral domains). //gen_normalize(R,result,len); - if (R->_zerop(result[len-1])) cl_abort(); + if (R->_zerop(result[len-1])) throw runtime_exception(); return _cl_UP(UPR, result); }} @@ -292,7 +292,7 @@ static const _cl_UP gen_square (cl_heap_univpoly_ring* UPR, const _cl_UP& x) init1(_cl_ring_element, result[0]) (R->_square(x[0])); // Normalize (not necessary in integral domains). //gen_normalize(R,result,len); - if (R->_zerop(result[len-1])) cl_abort(); + if (R->_zerop(result[len-1])) throw runtime_exception(); return _cl_UP(UPR, result); }} @@ -312,7 +312,7 @@ static const _cl_UP gen_exptpos (cl_heap_univpoly_ring* UPR, const _cl_UP& x, co static const _cl_UP gen_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, const _cl_UP& y) { - if (!(UPR->basering() == x.ring())) cl_abort(); + if (!(UPR->basering() == x.ring())) throw runtime_exception(); { DeclarePoly(cl_SV_ringelt,y); var cl_heap_ring* R = TheRing(UPR->basering()); @@ -326,7 +326,7 @@ static const _cl_UP gen_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_eleme init1(_cl_ring_element, result[i]) (R->_mul(x,y[i])); // Normalize (not necessary in integral domains). //gen_normalize(R,result,ylen); - if (R->_zerop(result[ylen-1])) cl_abort(); + if (R->_zerop(result[ylen-1])) throw runtime_exception(); return _cl_UP(UPR, result); }} @@ -350,7 +350,7 @@ static sintL gen_ldegree (cl_heap_univpoly_ring* UPR, const _cl_UP& x) static const _cl_UP gen_monomial (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, uintL e) { - if (!(UPR->basering() == x.ring())) cl_abort(); + if (!(UPR->basering() == x.ring())) throw runtime_exception(); var cl_heap_ring* R = TheRing(UPR->basering()); if (R->_zerop(x)) return _cl_UP(UPR, cl_null_SV_ringelt); @@ -385,8 +385,8 @@ static const _cl_UP gen_create (cl_heap_univpoly_ring* UPR, sintL deg) static void gen_set_coeff (cl_heap_univpoly_ring* UPR, _cl_UP& x, uintL index, const cl_ring_element& y) {{ DeclareMutablePoly(cl_SV_ringelt,x); - if (!(UPR->basering() == y.ring())) cl_abort(); - if (!(index < x.length())) cl_abort(); + if (!(UPR->basering() == y.ring())) throw runtime_exception(); + if (!(index < x.length())) throw runtime_exception(); x[index] = y; }} @@ -407,7 +407,7 @@ static const cl_ring_element gen_eval (cl_heap_univpoly_ring* UPR, const _cl_UP& // Else compute (...(x[len-1]*y+x[len-2])*y ...)*y + x[0]. DeclarePoly(cl_SV_ringelt,x); var cl_heap_ring* R = TheRing(UPR->basering()); - if (!(y.ring() == R)) cl_abort(); + if (!(y.ring() == R)) throw runtime_exception(); var uintL len = x.length(); if (len==0) return R->zero(); diff --git a/src/polynomial/elem/cl_UP_named.cc b/src/polynomial/elem/cl_UP_named.cc index 38a2994..a81adaa 100644 --- a/src/polynomial/elem/cl_UP_named.cc +++ b/src/polynomial/elem/cl_UP_named.cc @@ -70,7 +70,7 @@ const cl_univpoly_ring find_univpoly_ring (const cl_ring& r, const cl_symbol& va store_univpoly_ring(R); ring_in_table = get_univpoly_ring(r,varname); if (!ring_in_table) - cl_abort(); + throw runtime_exception(); } return *ring_in_table; } diff --git a/src/polynomial/elem/cl_UP_no_ring.cc b/src/polynomial/elem/cl_UP_no_ring.cc index f04886e..334f40c 100644 --- a/src/polynomial/elem/cl_UP_no_ring.cc +++ b/src/polynomial/elem/cl_UP_no_ring.cc @@ -12,70 +12,44 @@ CL_PROVIDE(cl_UP_no_ring) // Implementation. #include "cln/io.h" -#include "cln/abort.h" namespace cln { -nonreturning_function(static, uninitialized_ring, (void)); -static void uninitialized_ring () -{ - 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(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(); -} - -#if ((defined(__sparc__) || defined(__sparc64__)) && !defined(__GNUC__)) - // avoid Sun C++ 4.1 compiler bug - #define RETDUMMY return *(_cl_UP*)R -#else - #define RETDUMMY return *(_cl_UP*)0 -#endif - static const _cl_UP dummy_op0 (cl_heap_univpoly_ring* R) { unused R; - uninitialized_ring(); RETDUMMY; + throw uninitialized_ring_exception(); } static const _cl_UP dummy_op1 (cl_heap_univpoly_ring* R, const _cl_UP& x) { unused R; - uninitialized_error(x); RETDUMMY; + throw uninitialized_exception(x); } static const _cl_UP dummy_op2 (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y) { unused R; - uninitialized_error(x); uninitialized_error(y); RETDUMMY; + throw uninitialized_exception(x, y); } static void dummy_fprint (cl_heap_univpoly_ring* R, std::ostream& stream, const _cl_UP& x) { unused R; unused stream; - uninitialized_error(x); + throw uninitialized_exception(x); } static cl_boolean dummy_equal (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y) { unused R; - uninitialized_error(x); uninitialized_error(y); return cl_false; + throw uninitialized_exception(x, y); } #define dummy_zero dummy_op0 static cl_boolean dummy_zerop (cl_heap_univpoly_ring* R, const _cl_UP& x) { unused R; - uninitialized_error(x); return cl_false; + throw uninitialized_exception(x); } #define dummy_plus dummy_op2 #define dummy_minus dummy_op2 @@ -86,7 +60,7 @@ static const _cl_UP dummy_canonhom (cl_heap_univpoly_ring* R, const cl_I& x) { unused R; (void)&x; // unused x; - uninitialized_ring(); RETDUMMY; + throw uninitialized_ring_exception(); } #define dummy_mul dummy_op2 #define dummy_square dummy_op1 @@ -94,62 +68,62 @@ static const _cl_UP dummy_expt_pos (cl_heap_univpoly_ring* R, const _cl_UP& x, c { unused R; (void)&y; // unused y; - uninitialized_error(x); RETDUMMY; + throw uninitialized_exception(x); } static const _cl_UP dummy_scalmul (cl_heap_univpoly_ring* R, const cl_ring_element& x, const _cl_UP& y) { unused R; unused x; - uninitialized_error(y); RETDUMMY; + throw uninitialized_exception(y); } static sintL dummy_degree (cl_heap_univpoly_ring* R, const _cl_UP& x) { unused R; - uninitialized_error(x); return 0; + throw uninitialized_exception(x); } static sintL dummy_ldegree (cl_heap_univpoly_ring* R, const _cl_UP& x) { unused R; - uninitialized_error(x); return 0; + throw uninitialized_exception(x); } static const _cl_UP dummy_monomial (cl_heap_univpoly_ring* R, const cl_ring_element& x, uintL e) { unused R; unused x; unused e; - uninitialized_ring(); RETDUMMY; + throw uninitialized_ring_exception(); } static const cl_ring_element dummy_coeff (cl_heap_univpoly_ring* R, const _cl_UP& x, uintL index) { unused R; unused index; - uninitialized_error(x); return *(cl_ring_element*)0; + throw uninitialized_exception(x); } static const _cl_UP dummy_create (cl_heap_univpoly_ring* R, sintL deg) { unused R; unused deg; - uninitialized_ring(); RETDUMMY; + throw uninitialized_ring_exception(); } static void dummy_set_coeff (cl_heap_univpoly_ring* R, _cl_UP& x, uintL index, const cl_ring_element& y) { unused R; unused index; unused y; - uninitialized_error(x); + throw uninitialized_exception(x); } static void dummy_finalize (cl_heap_univpoly_ring* R, _cl_UP& x) { unused R; - uninitialized_error(x); + throw uninitialized_exception(x); } static const cl_ring_element dummy_eval (cl_heap_univpoly_ring* R, const _cl_UP& x, const cl_ring_element& y) { unused R; unused y; - uninitialized_error(x); return *(cl_ring_element*)0; + throw uninitialized_exception(x); } static cl_univpoly_setops dummy_setops = { diff --git a/src/polynomial/elem/cl_UP_number.h b/src/polynomial/elem/cl_UP_number.h index 4b8e906..4966ec0 100644 --- a/src/polynomial/elem/cl_UP_number.h +++ b/src/polynomial/elem/cl_UP_number.h @@ -3,7 +3,7 @@ #include "cln/SV_number.h" #include "cln/number.h" #include "cln/integer.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -142,7 +142,7 @@ static const _cl_UP num_uminus (cl_heap_univpoly_ring* UPR, const _cl_UP& x) // Negate. No normalization necessary, since the degree doesn't change. var sintL i = xlen-1; var cl_number hicoeff = ops.uminus(x[i]); - if (ops.zerop(hicoeff)) cl_abort(); + if (ops.zerop(hicoeff)) throw runtime_exception(); var cl_SV_number result = cl_SV_number(cl_make_heap_SV_number_uninit(xlen)); init1(cl_number, result[i]) (hicoeff); for (i-- ; i >= 0; i--) @@ -251,7 +251,7 @@ static const _cl_UP num_mul (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const } // Normalize (not necessary in integral domains). //num_normalize(ops,result,len); - if (ops.zerop(result[len-1])) cl_abort(); + if (ops.zerop(result[len-1])) throw runtime_exception(); return _cl_UP(UPR, result); }} @@ -290,7 +290,7 @@ static const _cl_UP num_square (cl_heap_univpoly_ring* UPR, const _cl_UP& x) init1(cl_number, result[0]) (ops.square(x[0])); // Normalize (not necessary in integral domains). //num_normalize(ops,result,len); - if (ops.zerop(result[len-1])) cl_abort(); + if (ops.zerop(result[len-1])) throw runtime_exception(); return _cl_UP(UPR, result); }} @@ -310,7 +310,7 @@ static const _cl_UP num_exptpos (cl_heap_univpoly_ring* UPR, const _cl_UP& x, co static const _cl_UP num_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, const _cl_UP& y) { - if (!(UPR->basering() == x.ring())) cl_abort(); + if (!(UPR->basering() == x.ring())) throw runtime_exception(); { DeclarePoly(cl_number,x); DeclarePoly(cl_SV_number,y); @@ -349,7 +349,7 @@ static sintL num_ldegree (cl_heap_univpoly_ring* UPR, const _cl_UP& x) static const _cl_UP num_monomial (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, uintL e) { - if (!(UPR->basering() == x.ring())) cl_abort(); + if (!(UPR->basering() == x.ring())) throw runtime_exception(); { DeclarePoly(cl_number,x); var cl_number_ring_ops<cl_number>& ops = *TheNumberRing(UPR->basering())->ops; if (ops.zerop(x)) @@ -385,9 +385,9 @@ static const _cl_UP num_create (cl_heap_univpoly_ring* UPR, sintL deg) static void num_set_coeff (cl_heap_univpoly_ring* UPR, _cl_UP& x, uintL index, const cl_ring_element& y) {{ DeclareMutablePoly(cl_SV_number,x); - if (!(UPR->basering() == y.ring())) cl_abort(); + if (!(UPR->basering() == y.ring())) throw runtime_exception(); { DeclarePoly(cl_number,y); - if (!(index < x.length())) cl_abort(); + if (!(index < x.length())) throw runtime_exception(); x[index] = y; }}} @@ -407,7 +407,7 @@ static const cl_ring_element num_eval (cl_heap_univpoly_ring* UPR, const _cl_UP& // If y = 0, return x[0]. // Else compute (...(x[len-1]*y+x[len-2])*y ...)*y + x[0]. DeclarePoly(cl_SV_number,x); - if (!(UPR->basering() == y.ring())) cl_abort(); + if (!(UPR->basering() == y.ring())) throw runtime_exception(); { DeclarePoly(cl_number,y); var cl_heap_number_ring* R = TheNumberRing(UPR->basering()); var cl_number_ring_ops<cl_number>& ops = *R->ops; diff --git a/src/polynomial/elem/cl_UP_unnamed.cc b/src/polynomial/elem/cl_UP_unnamed.cc index 5bb8ad6..98d93e3 100644 --- a/src/polynomial/elem/cl_UP_unnamed.cc +++ b/src/polynomial/elem/cl_UP_unnamed.cc @@ -55,7 +55,7 @@ const cl_univpoly_ring find_univpoly_ring (const cl_ring& r) store_univpoly_ring(R); ring_in_table = get_univpoly_ring(r); if (!ring_in_table) - cl_abort(); + throw runtime_exception(); } return *ring_in_table; } diff --git a/src/rational/elem/cl_RA_from_I_I_div.cc b/src/rational/elem/cl_RA_from_I_I_div.cc index 3b7fa35..823bddb 100644 --- a/src/rational/elem/cl_RA_from_I_I_div.cc +++ b/src/rational/elem/cl_RA_from_I_I_div.cc @@ -9,8 +9,8 @@ // Implementation. +#include "cln/exception.h" #include "cl_I.h" -#include "cl_N.h" namespace cln { @@ -21,7 +21,7 @@ const cl_RA I_I_div_RA (const cl_I& a, const cl_I& b) // Falls b>0: I_posI_div_RA anwenden. // Falls b<0: I_posI_div_RA auf (- a) und (- b) anwenden. if (eq(b,0)) - cl_error_division_by_0(); + throw division_by_0_exception(); if (minusp(b)) return I_posI_div_RA(-a,-b); else diff --git a/src/rational/elem/cl_RA_recip.cc b/src/rational/elem/cl_RA_recip.cc index 120d2d6..bacd0eb 100644 --- a/src/rational/elem/cl_RA_recip.cc +++ b/src/rational/elem/cl_RA_recip.cc @@ -9,8 +9,8 @@ // Implementation. +#include "cln/exception.h" #include "cl_RA.h" -#include "cl_N.h" #include "cl_I.h" namespace cln { @@ -23,7 +23,7 @@ const cl_RA recip (const cl_RA& r) // a>0 -> Ergebnis b/a (mit ggT(b,a)=1). // a<0 -> Ergebnis (- b)/(- a) (mit ggT(-b,-a)=1). if (zerop(r)) - cl_error_division_by_0(); + throw division_by_0_exception(); var cl_I a; var cl_I b; RA_numden_I_I(r, a = , b = ); diff --git a/src/rational/input/cl_RA_read.cc b/src/rational/input/cl_RA_read.cc index 7fae713..6d06522 100644 --- a/src/rational/input/cl_RA_read.cc +++ b/src/rational/input/cl_RA_read.cc @@ -13,11 +13,12 @@ // Implementation. #include <cstring> +#include <sstream> #include "cln/input.h" #include "cln/integer.h" #include "cln/integer_io.h" #include "cl_I.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -49,7 +50,7 @@ static const char * skip_digits (const char * ptr, const char * string_limit, un if (end_of_parse) \ { *end_of_parse = (ptr); } \ else \ - { if ((ptr) != string_limit) { read_number_junk((ptr),string,string_limit); } } + { if ((ptr) != string_limit) { throw read_number_junk_exception((ptr),string,string_limit); } } const cl_RA read_rational (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse) { @@ -83,10 +84,10 @@ const cl_RA read_rational (const cl_read_flags& flags, const char * string, cons goto not_rational_syntax; var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr); if (!((base >= 2) && (base <= 36))) { - 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(); + std::ostringstream buf; + fprint(buf, "Base must be an integer in the range from 2 to 36, not "); + fprint(buf, base); + throw runtime_exception(buf.str()); } rational_base = FN_to_UV(base); ptr = base_end_ptr; break; @@ -146,7 +147,7 @@ not_rational_syntax: *end_of_parse = string; return 0; // dummy return } - read_number_bad_syntax(string,string_limit); + throw read_number_bad_syntax_exception(string,string_limit); } } // namespace cln diff --git a/src/rational/input/cl_RA_read_stream.cc b/src/rational/input/cl_RA_read_stream.cc index a54f861..f14ddce 100644 --- a/src/rational/input/cl_RA_read_stream.cc +++ b/src/rational/input/cl_RA_read_stream.cc @@ -99,10 +99,10 @@ const cl_RA read_rational (std::istream& stream, const cl_read_flags& flags) // Handle syntax error. syntax1: buffer.push(c); - read_number_bad_syntax(buffer.start_pointer(),buffer.end_pointer()); + throw read_number_bad_syntax_exception(buffer.start_pointer(),buffer.end_pointer()); // Handle premature EOF. -eof: read_number_eof(); +eof: throw read_number_eof_exception(); } } // namespace cln diff --git a/src/rational/input/cl_RA_readparsed.cc b/src/rational/input/cl_RA_readparsed.cc index 417a8fd..480560a 100644 --- a/src/rational/input/cl_RA_readparsed.cc +++ b/src/rational/input/cl_RA_readparsed.cc @@ -21,7 +21,7 @@ const cl_RA read_rational (unsigned int base, cl_signean sign, const char * stri var cl_I den = // Nenner digits_to_I(&string[index3_1],index2-index3_1,(uintD)base); if (zerop(den)) // Division durch 0 abfangen - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } var cl_I num = // Z�hler digits_to_I(&string[index1],index3-index1,(uintD)base); if (!(sign == 0)) diff --git a/src/rational/misc/cl_RA_as.cc b/src/rational/misc/cl_RA_as.cc index d9bdea5..0a35a8d 100644 --- a/src/rational/misc/cl_RA_as.cc +++ b/src/rational/misc/cl_RA_as.cc @@ -36,7 +36,7 @@ const cl_RA& cl_RA_As (const cl_number& x, const char * filename, int line) DeclareType(cl_RA,x); return x; } else - cl_as_error(x,"a rational number",filename,line); + throw as_exception(x,"a rational number",filename,line); } } // namespace cln diff --git a/src/real/elem/cl_R_div.cc b/src/real/elem/cl_R_div.cc index ba65336..46e6d02 100644 --- a/src/real/elem/cl_R_div.cc +++ b/src/real/elem/cl_R_div.cc @@ -34,7 +34,7 @@ const cl_R operator/ (const cl_R& x, const cl_R& y) if (eq(x,0)) // 0 / y = exakte 0, au�er wenn y=0 { if (zerop(y)) - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } else return 0; } diff --git a/src/real/format-output/cl_fmt_cardinal.cc b/src/real/format-output/cl_fmt_cardinal.cc index 220be8b..3580e41 100644 --- a/src/real/format-output/cl_fmt_cardinal.cc +++ b/src/real/format-output/cl_fmt_cardinal.cc @@ -9,9 +9,10 @@ // Implementation. +#include <sstream> #include "cln/integer.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { @@ -107,10 +108,10 @@ void format_cardinal (std::ostream& stream, const cl_I& argument) var uintL * small_piece_ptr = &small_pieces[0]; do { if (*illion_ptr == NULL) { - fprint(std::cerr, "format_cardinal: argument too large: "); - fprint(std::cerr, argument); - fprint(std::cerr, "\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "format_cardinal: argument too large: "); + fprint(buf, argument); + throw runtime_exception(buf.str()); } var cl_I_div_t div = floor2(arg,1000); var const cl_I& thousands = div.quotient; diff --git a/src/real/format-output/cl_fmt_newroman.cc b/src/real/format-output/cl_fmt_newroman.cc index 0732820..63e94d5 100644 --- a/src/real/format-output/cl_fmt_newroman.cc +++ b/src/real/format-output/cl_fmt_newroman.cc @@ -9,19 +9,21 @@ // Implementation. +#include <sstream> #include "cln/integer.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { void format_new_roman (std::ostream& stream, const cl_I& arg) { if (!(0 < arg && arg < 4000)) { - 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(); + std::ostringstream buf; + fprint(buf, "format_new_roman: argument should be in the range 1 - 3999, not "); + fprint(buf, arg); + fprint(buf, "."); + throw runtime_exception(buf.str()); } var uintL value = cl_I_to_UL(arg); struct roman { char symbol; uintL value; }; diff --git a/src/real/format-output/cl_fmt_oldroman.cc b/src/real/format-output/cl_fmt_oldroman.cc index b69029b..9ca5c6f 100644 --- a/src/real/format-output/cl_fmt_oldroman.cc +++ b/src/real/format-output/cl_fmt_oldroman.cc @@ -9,19 +9,21 @@ // Implementation. +#include <sstream> #include "cln/integer.h" #include "cln/integer_io.h" -#include "cln/abort.h" +#include "cln/exception.h" namespace cln { void format_old_roman (std::ostream& stream, const cl_I& arg) { if (!(0 < arg && arg < 5000)) { - 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(); + std::ostringstream buf; + fprint(buf, "format_old_roman: argument should be in the range 1 - 4999, not "); + fprint(buf, arg); + fprint(buf, "\n"); + throw runtime_exception(buf.str()); } var uintL value = cl_I_to_UL(arg); struct roman { char symbol; uintL value; }; diff --git a/src/real/input/cl_R_read.cc b/src/real/input/cl_R_read.cc index d31cf69..940e9e9 100644 --- a/src/real/input/cl_R_read.cc +++ b/src/real/input/cl_R_read.cc @@ -12,6 +12,7 @@ // Implementation. #include <cstring> +#include <sstream> #include "cln/input.h" #include "cln/rational_io.h" #include "cln/integer_io.h" @@ -19,7 +20,7 @@ #include "cln/integer.h" #include "cl_I.h" #include "cl_F.h" -#include "cln/abort.h" +#include "cln/exception.h" #undef floor #include <cmath> @@ -56,7 +57,7 @@ static const char * skip_digits (const char * ptr, const char * string_limit, un if (end_of_parse) \ { *end_of_parse = (ptr); } \ else \ - { if ((ptr) != string_limit) { read_number_junk((ptr),string,string_limit); } } + { if ((ptr) != string_limit) { throw read_number_junk_exception((ptr),string,string_limit); } } const cl_R read_real (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse) { @@ -90,10 +91,10 @@ const cl_R read_real (const cl_read_flags& flags, const char * string, const cha goto not_rational_syntax; var cl_I base = read_integer(10,0,ptr,0,base_end_ptr-ptr); if (!((base >= 2) && (base <= 36))) { - 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(); + std::ostringstream buf; + fprint(buf, "Base must be an integer in the range from 2 to 36, not "); + fprint(buf, base); + throw runtime_exception(buf.str()); } rational_base = FN_to_UV(base); ptr = base_end_ptr; break; @@ -264,7 +265,7 @@ not_float_syntax: *end_of_parse = string; return 0; // dummy return } - read_number_bad_syntax(string,string_limit); + throw read_number_bad_syntax_exception(string,string_limit); } } // namespace cln diff --git a/src/real/input/cl_R_read_stream.cc b/src/real/input/cl_R_read_stream.cc index e75221d..3f5979e 100644 --- a/src/real/input/cl_R_read_stream.cc +++ b/src/real/input/cl_R_read_stream.cc @@ -98,10 +98,10 @@ const cl_R read_real (std::istream& stream, const cl_read_flags& flags) // Handle syntax error. syntax1: buffer.push(c); - read_number_bad_syntax(buffer.start_pointer(),buffer.end_pointer()); + throw read_number_bad_syntax_exception(buffer.start_pointer(),buffer.end_pointer()); // Handle premature EOF. -eof: read_number_eof(); +eof: throw read_number_eof_exception(); } } // namespace cln diff --git a/src/real/misc/cl_R_as.cc b/src/real/misc/cl_R_as.cc index fa66200..a219e23 100644 --- a/src/real/misc/cl_R_as.cc +++ b/src/real/misc/cl_R_as.cc @@ -40,7 +40,7 @@ const cl_R& cl_R_As (const cl_number& x, const char * filename, int line) DeclareType(cl_R,x); return x; } else - cl_as_error(x,"a real number",filename,line); + throw as_exception(x,"a real number",filename,line); } } // namespace cln diff --git a/src/real/random/cl_R_random.cc b/src/real/random/cl_R_random.cc index 473e897..6c4a9b1 100644 --- a/src/real/random/cl_R_random.cc +++ b/src/real/random/cl_R_random.cc @@ -13,7 +13,8 @@ #include "cl_RA.h" #include "cln/io.h" #include "cln/real_io.h" -#include "cln/abort.h" +#include "cln/exception.h" +#include <sstream> namespace cln { @@ -32,10 +33,10 @@ const cl_R random_R (random_state& r, const cl_R& n) } } } - fprint(std::cerr, "random: argument should be positive and an integer or float: "); - fprint(std::cerr, n); - fprint(std::cerr, "\n"); - cl_abort(); + std::ostringstream buf; + fprint(buf, "random: argument should be positive and an integer or float: "); + fprint(buf, n); + throw runtime_exception(buf.str()); } } // namespace cln diff --git a/src/real/transcendental/cl_R_atan2.cc b/src/real/transcendental/cl_R_atan2.cc index 0546e14..a5d7260 100644 --- a/src/real/transcendental/cl_R_atan2.cc +++ b/src/real/transcendental/cl_R_atan2.cc @@ -34,7 +34,7 @@ const cl_R atan (const cl_R& x, const cl_R& y) if (eq(y,0)) { // y=0 (exakt) if (zerop(x)) // x=0 -> Error - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } if (minusp(x)) // x<0 -> pi in Default-Float-Genauigkeit { return pi(); } return 0; // x>0 -> 0 @@ -42,7 +42,7 @@ const cl_R atan (const cl_R& x, const cl_R& y) elif (eq(x,0)) { // x=0 (exakt) if (zerop(y)) // y=0 -> Error - { cl_error_division_by_0(); } + { throw division_by_0_exception(); } if (minusp(y)) // y<0 -> -pi/2 { return - scale_float(pi(),-1); } return scale_float(pi(),-1); // y>0 -> pi/2 diff --git a/src/real/transcendental/cl_R_log.cc b/src/real/transcendental/cl_R_log.cc index 2834b54..00d42fe 100644 --- a/src/real/transcendental/cl_R_log.cc +++ b/src/real/transcendental/cl_R_log.cc @@ -30,7 +30,7 @@ const cl_R log (const cl_R& a, const cl_R& b) Mutable(cl_R,b); if (rationalp(b)) { // b rational - if (eq(b,1)) { cl_error_division_by_0(); } + if (eq(b,1)) { throw division_by_0_exception(); } if (rationalp(a)) { // a,b beide rational var cl_RA l; diff --git a/src/vector/cl_GV_I.cc b/src/vector/cl_GV_I.cc index 1471cef..456388b 100644 --- a/src/vector/cl_GV_I.cc +++ b/src/vector/cl_GV_I.cc @@ -13,7 +13,7 @@ CL_PROVIDE(cl_GV_I) #include "cl_I.h" #include "cl_DS.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_offsetof.h" namespace cln { @@ -70,9 +70,9 @@ static inline cl_GV_I_vectorops* outcast (cl_GV_vectorops<cl_I>* vectorops) struct cl_heap_GV_I_general : public cl_heap_GV_I { cl_I data[1]; // Standard allocation disabled. - void* operator new (size_t size) { unused size; cl_abort(); return (void*)1; } + void* operator new (size_t size) { unused size; throw runtime_exception(); } // Standard deallocation disabled. - void operator delete (void* ptr) { unused ptr; cl_abort(); } + void operator delete (void* ptr) { unused ptr; throw runtime_exception(); } // No default constructor. cl_heap_GV_I_general (); }; @@ -105,9 +105,9 @@ static void general_copy_elements (const cl_GV_inner<cl_I>* srcvec, uintC srcind var uintC srclen = srcv->v.length(); var uintC destlen = destv->v.length(); if (!(srcindex <= srcindex+count && srcindex+count <= srclen)) - cl_abort(); + throw runtime_exception(); if (!(destindex <= destindex+count && destindex+count <= destlen)) - cl_abort(); + throw runtime_exception(); do { destv->data[destindex++] = srcv->data[srcindex++]; } while (--count > 0); @@ -140,9 +140,9 @@ cl_heap_GV_I* cl_make_heap_GV_I (uintC len) struct cl_heap_GV_I_bits##m : public cl_heap_GV_I { \ uint_t data[1]; \ /* Standard allocation disabled. */ \ - void* operator new (size_t size) { unused size; cl_abort(); return (void*)1; } \ + void* operator new (size_t size) { unused size; throw runtime_exception(); } \ /* Standard deallocation disabled. */ \ - void operator delete (void* ptr) { unused ptr; cl_abort(); } \ + void operator delete (void* ptr) { unused ptr; throw runtime_exception(); } \ /* No default constructor. */ \ cl_heap_GV_I_bits##m (); \ }; \ @@ -158,9 +158,9 @@ static void bits##m##_copy_elements (const cl_GV_inner<cl_I>* srcvec, uintC srci var uintC srclen = srcv->v.length(); \ var uintC destlen = destv->v.length(); \ if (!(srcindex <= srcindex+count && srcindex+count <= srclen)) \ - cl_abort(); \ + throw runtime_exception(); \ if (!(destindex <= destindex+count && destindex+count <= destlen)) \ - cl_abort(); \ + throw runtime_exception(); \ if (m == intDsize) { \ var const uintD* srcptr = &srcv->data[srcindex]; \ var uintD* destptr = &destv->data[destindex]; \ @@ -293,7 +293,7 @@ static void bits1_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -315,7 +315,7 @@ static void bits2_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -337,7 +337,7 @@ static void bits4_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -369,7 +369,7 @@ static void bits8_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -401,7 +401,7 @@ static void bits16_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } diff --git a/src/vector/cl_GV_number.cc b/src/vector/cl_GV_number.cc index 20af58a..7a65eb9 100644 --- a/src/vector/cl_GV_number.cc +++ b/src/vector/cl_GV_number.cc @@ -11,7 +11,7 @@ CL_PROVIDE(cl_GV_number) // Implementation. -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_offsetof.h" namespace cln { @@ -46,9 +46,9 @@ static inline const cl_heap_GV_number * outcast (const cl_GV_inner<cl_number>* v struct cl_heap_GV_number_general : public cl_heap_GV_number { cl_number data[1]; // Standard allocation disabled. - void* operator new (size_t size) { unused size; cl_abort(); return (void*)1; } + void* operator new (size_t size) { unused size; throw runtime_exception(); } // Standard deallocation disabled. - void operator delete (void* ptr) { unused ptr; cl_abort(); } + void operator delete (void* ptr) { unused ptr; throw runtime_exception(); } // No default constructor. cl_heap_GV_number_general (); }; @@ -81,9 +81,9 @@ static void general_copy_elements (const cl_GV_inner<cl_number>* srcvec, uintC s var uintC srclen = srcv->v.length(); var uintC destlen = destv->v.length(); if (!(srcindex <= srcindex+count && srcindex+count <= srclen)) - cl_abort(); + throw runtime_exception(); if (!(destindex <= destindex+count && destindex+count <= destlen)) - cl_abort(); + throw runtime_exception(); do { destv->data[destindex++] = srcv->data[srcindex++]; } while (--count > 0); diff --git a/src/vector/cl_SV_number.cc b/src/vector/cl_SV_number.cc index 80b5a5d..55801a4 100644 --- a/src/vector/cl_SV_number.cc +++ b/src/vector/cl_SV_number.cc @@ -11,8 +11,6 @@ CL_PROVIDE(cl_SV_number) // Implementation. -#include "cln/abort.h" - namespace cln { static void cl_svector_number_destructor (cl_heap* pointer) diff --git a/src/vector/cl_SV_ringelt.cc b/src/vector/cl_SV_ringelt.cc index 48587ae..b867b72 100644 --- a/src/vector/cl_SV_ringelt.cc +++ b/src/vector/cl_SV_ringelt.cc @@ -11,8 +11,6 @@ CL_PROVIDE(cl_SV_ringelt) // Implementation. -#include "cln/abort.h" - namespace cln { static void cl_svector_ringelt_destructor (cl_heap* pointer) diff --git a/tests/timediv2adic-compare.cc b/tests/timediv2adic-compare.cc index a87984a..e8dabb0 100644 --- a/tests/timediv2adic-compare.cc +++ b/tests/timediv2adic-compare.cc @@ -5,7 +5,6 @@ #include "cl_2DS.h" #include <cln/random.h> #include "cl_random_impl.h" -#include <cln/abort.h> #include <cstdlib> #include <cstring> #include <cln/timing.h> @@ -46,7 +45,7 @@ int main (int argc, char * argv[]) div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q_LSDptr); div2adic_algo = 1; div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q1_LSDptr); - if (compare_loop_msp(q_MSDptr,q1_MSDptr,a_len)) cl_abort(); + if (compare_loop_msp(q_MSDptr,q1_MSDptr,a_len)) abort(); // Time. div2adic_algo = 0; { CL_TIMING; diff --git a/tests/timediv2adic.cc b/tests/timediv2adic.cc index 4f6896a..9ccc777 100644 --- a/tests/timediv2adic.cc +++ b/tests/timediv2adic.cc @@ -5,7 +5,6 @@ #include "cl_2DS.h" #include <cln/random.h> #include "cl_random_impl.h" -#include <cln/abort.h> #include <cstdlib> #include <cstring> #include <cln/timing.h> diff --git a/tests/timeprint-compare.cc b/tests/timeprint-compare.cc index a231c9c..0e4b235 100644 --- a/tests/timeprint-compare.cc +++ b/tests/timeprint-compare.cc @@ -7,7 +7,6 @@ #include <cln/timing.h> #include <cl_print.h> #include <cln/malloc.h> -#include <cln/abort.h> int main (int argc, char * argv[]) { @@ -26,7 +25,7 @@ int main (int argc, char * argv[]) { char* p = (cl_digits_algo = 0, cl_decimal_string(a)); char* q = (cl_digits_algo = 1, cl_decimal_string(a)); - if (strcmp(p,q)) cl_abort(); + if (strcmp(p,q)) abort(); free_hook(p); free_hook(q); } diff --git a/tests/timeprint.cc b/tests/timeprint.cc index 799872d..bc1d224 100644 --- a/tests/timeprint.cc +++ b/tests/timeprint.cc @@ -7,7 +7,6 @@ #include <cstring> #include <cln/timing.h> #include <cln/malloc.h> -#include <cln/abort.h> using namespace cln; int main (int argc, char * argv[]) diff --git a/tests/timerecip2adic-compare.cc b/tests/timerecip2adic-compare.cc index 6c6e9ef..4e8857f 100644 --- a/tests/timerecip2adic-compare.cc +++ b/tests/timerecip2adic-compare.cc @@ -5,7 +5,6 @@ #include "cl_2DS.h" #include <cln/random.h> #include "cl_random_impl.h" -#include <cln/abort.h> #include <cstdlib> #include <cstring> #include <cln/timing.h> @@ -40,7 +39,7 @@ int main (int argc, char * argv[]) recip2adic(len,a_LSDptr,b_LSDptr); recip2adic_threshold = threshold; recip2adic(len,a_LSDptr,bn_LSDptr); - if (compare_loop_msp(b_MSDptr,bn_MSDptr,len)) cl_abort(); + if (compare_loop_msp(b_MSDptr,bn_MSDptr,len)) abort(); // Time. recip2adic_threshold = 1000000; { CL_TIMING;