C++ bool, true, and false.
+2007-08-01 Richard B. Kreckel <kreckel@ginac.de>
+
+ * */*: Remove cl_boolean, cl_true, and cl_false in favor of built-in
+ C++ bool, true, and false.
+
2007-07-28 Richard B. Kreckel <kreckel@ginac.de>
Remove exception hooks in favor of real C++ exceptions:
* Added support for huge numbers...
* CLN now uses C++ exceptions for error handling.
+* Removed cl_boolean. Use built-in C++ bool instead.
* Dropped the cln-config script. Please use pkg-config instead.
the same according to @code{==}. This hash code depends on the number's value,
not its type or precision.
-@item cl_boolean zerop (const @var{type}& x)
+@item bool zerop (const @var{type}& x)
@cindex @code{zerop ()}
Compare against zero: @code{x == 0}
@end table
@cindex @code{operator > ()}
Comparison, as in C and C++.
-@item cl_boolean minusp (const @var{type}& x)
+@item bool minusp (const @var{type}& x)
@cindex @code{minusp ()}
Compare against zero: @code{x < 0}
-@item cl_boolean plusp (const @var{type}& x)
+@item bool plusp (const @var{type}& x)
@cindex @code{plusp ()}
Compare against zero: @code{x > 0}
The classes @code{cl_RA}, @code{cl_I} define the following operation:
@table @code
-@item cl_boolean sqrtp (const @var{type}& x, @var{type}* root)
+@item bool sqrtp (const @var{type}& x, @var{type}* root)
@cindex @code{sqrtp ()}
This tests whether @code{x} is a perfect square. If so, it returns true
and the exact square root in @code{*root}, else it returns false.
Furthermore, for integers, similarly:
@table @code
-@item cl_boolean isqrt (const @var{type}& x, @var{type}* root)
+@item bool isqrt (const @var{type}& x, @var{type}* root)
@cindex @code{isqrt ()}
@code{x} should be >= 0. This function sets @code{*root} to
@code{floor(sqrt(x))} and returns the same value as @code{sqrtp}:
define the following operation:
@table @code
-@item cl_boolean rootp (const @var{type}& x, const cl_I& n, @var{type}* root)
+@item bool rootp (const @var{type}& x, const cl_I& n, @var{type}* root)
@cindex @code{rootp ()}
@code{x} must be >= 0. @code{n} must be > 0.
This tests whether @code{x} is an @code{n}th power of a rational number.
Other functions that view integers as bit strings:
@table @code
-@item cl_boolean logtest (const cl_I& x, const cl_I& y)
+@item bool logtest (const cl_I& x, const cl_I& y)
@cindex @code{logtest ()}
Returns true if some bit is set in both @code{x} and @code{y}, i.e. if
@code{logand(x,y) != 0}.
-@item cl_boolean logbitp (const cl_I& n, const cl_I& x)
+@item bool logbitp (const cl_I& n, const cl_I& x)
@cindex @code{logbitp ()}
Returns true if the @code{n}th bit (from the right) of @code{x} is set.
Bit 0 is the least significant bit.
extracts the bits of @code{n} described by the bit interval @code{b}
and returns them as a nonnegative integer with @code{b.size} bits.
-@item cl_boolean ldb_test (const cl_I& n, const cl_byte& b)
+@item bool ldb_test (const cl_I& n, const cl_byte& b)
@cindex @code{ldb_test ()}
Returns true if some bit described by the bit interval @code{b} is set in
@code{n}.
for common arithmetic operations:
@table @code
-@item cl_boolean oddp (const cl_I& x)
+@item bool oddp (const cl_I& x)
@cindex @code{oddp ()}
Returns true if the least significant bit of @code{x} is 1. Equivalent to
@code{mod(x,2) != 0}.
-@item cl_boolean evenp (const cl_I& x)
+@item bool evenp (const cl_I& x)
@cindex @code{evenp ()}
Returns true if the least significant bit of @code{x} is 0. Equivalent to
@code{mod(x,2) == 0}.
This function returns the least common multiple of @code{a} and @code{b},
normalized to be >= 0.
-@item cl_boolean logp (const cl_I& a, const cl_I& b, cl_RA* l)
+@item bool logp (const cl_I& a, const cl_I& b, cl_RA* l)
@cindex @code{logp ()}
-@itemx cl_boolean logp (const cl_RA& a, const cl_RA& b, cl_RA* l)
+@itemx bool logp (const cl_RA& a, const cl_RA& b, cl_RA* l)
@code{a} must be > 0. @code{b} must be >0 and != 1. If log(a,b) is
rational number, this function returns true and sets *l = log(a,b), else
it returns false.
@code{a,b} must be integers, @code{b>0} and odd. The result is 0
iff gcd(a,b)>1.
-@item cl_boolean isprobprime (const cl_I& n)
+@item bool isprobprime (const cl_I& n)
@cindex prime
@cindex @code{isprobprime()}
Returns true if @code{n} is a small prime or passes the Miller-Rabin
@item float_format_t float_flags.default_lfloat_format
The float format used when reading floats with exponent marker @samp{l}.
-@item cl_boolean float_flags.mantissa_dependent_float_format
+@item bool float_flags.mantissa_dependent_float_format
When this flag is true, floats specified with more digits than corresponding
to the exponent marker they contain, but without @var{_nnn} suffix, will get a
precision corresponding to their number of significant digits.
@item unsigned int rational_base
The base in which rational numbers are printed. Default is @code{10}.
-@item cl_boolean rational_readably
+@item bool rational_readably
If this flag is true, rational numbers are printed with radix specifiers in
Common Lisp syntax (@code{#@var{n}R} or @code{#b} or @code{#o} or @code{#x}
prefixes, trailing dot). Default is false.
-@item cl_boolean float_readably
+@item bool float_readably
If this flag is true, type specific exponent markers have precedence over 'E'.
Default is false.
Floating point numbers of this format will be printed using the 'E' exponent
marker. Default is @code{float_format_ffloat}.
-@item cl_boolean complex_readably
+@item bool complex_readably
If this flag is true, complex numbers will be printed using the Common Lisp
syntax @code{#C(@var{realpart} @var{imagpart})}. Default is false.
@table @code
@item void R->fprint (std::ostream& stream, const cl_ring_element& x)
@cindex @code{fprint ()}
-@itemx cl_boolean R->equal (const cl_ring_element& x, const cl_ring_element& y)
+@itemx bool R->equal (const cl_ring_element& x, const cl_ring_element& y)
@cindex @code{equal ()}
@itemx cl_ring_element R->zero ()
@cindex @code{zero ()}
-@itemx cl_boolean R->zerop (const cl_ring_element& x)
+@itemx bool R->zerop (const cl_ring_element& x)
@cindex @code{zerop ()}
@itemx cl_ring_element R->plus (const cl_ring_element& x, const cl_ring_element& y)
@cindex @code{plus ()}
@code{cl_RA_ring}, @code{cl_I_ring}:
@table @code
-@item cl_boolean instanceof (const cl_number& x, const cl_number_ring& R)
+@item bool instanceof (const cl_number& x, const cl_number_ring& R)
@cindex @code{instanceof ()}
Tests whether the given number is an element of the number ring R.
@end table
Compares two modular integers, belonging to the same modular integer ring,
for equality.
-@item cl_boolean zerop (const cl_MI& x)
+@item bool zerop (const cl_MI& x)
@cindex @code{zerop ()}
Returns true if @code{x} is @code{0 mod N}.
@end table
Compares two univariate polynomials, belonging to the same univariate
polynomial ring, for equality.
-@item cl_boolean zerop (const cl_UP& x)
+@item bool zerop (const cl_UP& x)
@cindex @code{zerop ()}
Returns true if @code{x} is @code{0 in R}.
@code{floating_point_exception}) to be thrown. If you set the global
variable
@example
-cl_boolean cl_inhibit_floating_point_underflow
+bool cl_inhibit_floating_point_underflow
@end example
-to @code{cl_true}, the exception will be inhibited, and a floating-point
+to @code{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}.
+@code{cl_inhibit_floating_point_underflow} is @code{false}.
@section Customizing I/O
// zerop(x) testet, ob (= x 0).
-extern cl_boolean zerop (const cl_N& x);
+extern bool zerop (const cl_N& x);
// Liefert zu reellen Zahlen a und b die komplexe Zahl a+bi.
extern const cl_N sqrt (const cl_N& x);
// equal(x,y) vergleicht zwei Zahlen x und y auf Gleichheit.
-extern cl_boolean equal (const cl_N& x, const cl_N& y);
+extern bool equal (const cl_N& x, const cl_N& y);
// equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
extern uint32 equal_hashcode (const cl_N& x);
{ return compare(x,y)>0; }
// minusp(x) == (< x 0)
-extern cl_boolean minusp (const cl_DF& x);
+extern bool minusp (const cl_DF& x);
// zerop(x) stellt fest, ob ein Double-Float x = 0.0 ist.
-extern cl_boolean zerop (const cl_DF& x);
+extern bool zerop (const cl_DF& x);
// plusp(x) == (> x 0)
-extern cl_boolean plusp (const cl_DF& x);
+extern bool plusp (const cl_DF& x);
// Liefert zu zwei Double-Float x und y : (+ x y), ein DF.
extern const cl_DF operator+ (const cl_DF& x, const cl_DF& y);
// Assignment operators.
cl_DF& operator= (const cl_DF&);
// Optimization of method pointer_p().
- cl_boolean pointer_p() const
- { return cl_true; }
+ bool pointer_p() const
+ { return true; }
// Faster pointer_p() gives a faster copy constructor (but not destructor!!!).
cl_DF (const cl_DF& x);
// Constructors and assignment operators from C numeric types.
{ return compare(x,y)>0; }
// minusp(x) == (< x 0)
-extern cl_boolean minusp (const cl_FF& x);
+extern bool minusp (const cl_FF& x);
// zerop(x) stellt fest, ob ein Single-Float x = 0.0 ist.
-extern cl_boolean zerop (const cl_FF& x);
+extern bool zerop (const cl_FF& x);
// plusp(x) == (> x 0)
-extern cl_boolean plusp (const cl_FF& x);
+extern bool plusp (const cl_FF& x);
// Liefert zu zwei Single-Float x und y : (+ x y), ein FF.
extern const cl_FF operator+ (const cl_FF& x, const cl_FF& y);
// Assignment operators.
cl_FF& operator= (const cl_FF&);
// Optimization of method pointer_p().
- cl_boolean pointer_p() const
+ bool pointer_p() const
#if defined(CL_WIDE_POINTERS)
- { return cl_false; }
+ { return false; }
#else
- { return cl_true; }
+ { return true; }
#endif
// Faster pointer_p() gives a faster copy constructor (but not destructor!!!).
cl_FF (const cl_FF& x);
// zerop(x) testet, ob (= x 0).
-extern cl_boolean zerop (const cl_F& x);
+extern bool zerop (const cl_F& x);
// minusp(x) testet, ob (< x 0).
-extern cl_boolean minusp (const cl_F& x);
+extern bool minusp (const cl_F& x);
// plusp(x) testet, ob (> x 0).
-extern cl_boolean plusp (const cl_F& x);
+extern bool plusp (const cl_F& x);
// cl_F_to_SF(x) wandelt ein Float x in ein Short-Float um und rundet dabei.
// If this is true, floating point underflow returns zero instead of throwing an exception.
-extern cl_boolean cl_inhibit_floating_point_underflow;
+extern bool cl_inhibit_floating_point_underflow;
} // namespace cln
// Flag whether floats specified with more digits than corresponding
// to the exponent marker they contain, but without _nnn suffix, will
// get a precision corresponding to their number of significant digits.
- cl_boolean mantissa_dependent_float_format;
+ bool mantissa_dependent_float_format;
};
// Specifies the possible results of a read operation.
// Prüft, ob (LOGTEST x y), wo x und y Integers sind.
// (LOGTEST x y) = (NOT (ZEROP (LOGAND x y))).
// < ergebnis: /=0, falls ja; =0, falls nein.
-extern cl_boolean logtest (const cl_I& x, const cl_I& y);
+extern bool logtest (const cl_I& x, const cl_I& y);
// Prüft, ob (LOGBITP x y), wo x und y Integers sind.
// Ergebnis: /=0, wenn ja; =0, wenn nein.
-extern cl_boolean logbitp (uintC x, const cl_I& y);
-extern cl_boolean logbitp (const cl_I& x, const cl_I& y);
+extern bool logbitp (uintC x, const cl_I& y);
+extern bool logbitp (const cl_I& x, const cl_I& y);
// Prüft, ob (ODDP x), wo x ein Integer ist.
// Ergebnis: /=0, falls ja; =0, falls nein.
-extern cl_boolean oddp (const cl_I& x);
+extern bool oddp (const cl_I& x);
// Prüft, ob (EVENP x), wo x ein Integer ist.
// Ergebnis: /=0, falls ja; =0, falls nein.
-inline cl_boolean evenp (const cl_I& x)
- { return (cl_boolean) (!oddp(x)); }
+inline bool evenp (const cl_I& x)
+ { return !oddp(x); }
// (ASH x y), wo x und y Integers sind. Ergebnis Integer.
extern const cl_I ash (const cl_I& x, sintC y);
// Vergleich von Integers
// equal(x,y) vergleicht zwei Integers x und y auf Gleichheit.
-extern cl_boolean equal (const cl_I& x, const cl_I& y);
+extern bool equal (const cl_I& x, const cl_I& y);
// equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
extern uint32 equal_hashcode (const cl_I& x);
{ return compare(x,y)>0; }
// minusp(x) == (< x 0)
-extern cl_boolean minusp (const cl_I& x);
+extern bool minusp (const cl_I& x);
// plusp(x) == (> x 0)
-extern cl_boolean plusp (const cl_I& x);
+extern bool plusp (const cl_I& x);
// zerop(x) stellt fest, ob ein Integer = 0 ist.
-extern cl_boolean zerop (const cl_I& x);
+extern bool zerop (const cl_I& x);
// BYTE-Operationen auf Integers
extern const cl_I ldb (const cl_I& n, const cl_byte& b);
// ldb_test(n,byte) führt (LDB-TEST byte n) aus, wobei n ein Integer ist.
-// Ergebnis: cl_false wenn nein (also alle fraglichen Bits =0), cl_true wenn ja.
-extern cl_boolean ldb_test (const cl_I& n, const cl_byte& b);
+// Ergebnis: false wenn nein (also alle fraglichen Bits =0), true wenn ja.
+extern bool ldb_test (const cl_I& n, const cl_byte& b);
// (MASK-FIELD byte n), wo n ein Integer ist.
extern const cl_I mask_field (const cl_I& n, const cl_byte& b);
// isqrt(x,&w)
// > x: Integer (sollte >=0 sein)
// < w: (isqrt x)
-// < ergebnis: cl_true falls x Quadratzahl, cl_false sonst
- extern cl_boolean isqrt (const cl_I& x, cl_I* w);
+// < ergebnis: true falls x Quadratzahl, false sonst
+ extern bool isqrt (const cl_I& x, cl_I* w);
// Wenn das boolesche Ergebnis uninteressant ist:
inline const cl_I isqrt (const cl_I& x) { cl_I w; isqrt(x,&w); return w; }
// sqrtp(x,&w)
// > x: ein Integer >=0
// < w: Integer (sqrt x) falls x Quadratzahl
-// < ergebnis: cl_true ..................., cl_false sonst
- extern cl_boolean sqrtp (const cl_I& x, cl_I* w);
+// < ergebnis: true ..................., false sonst
+ extern bool sqrtp (const cl_I& x, cl_I* w);
// Stellt fest, ob ein Integer >=0 eine n-te Potenz ist.
// rootp(x,n,&w)
// > x: ein Integer >=0
// > n: ein Integer >0
// < w: Integer (expt x (/ n)) falls x eine n-te Potenz
-// < ergebnis: cl_true ........................, cl_false sonst
- extern cl_boolean rootp (const cl_I& x, uintL n, cl_I* w);
- extern cl_boolean rootp (const cl_I& x, const cl_I& n, cl_I* w);
+// < ergebnis: true ........................, false sonst
+ extern bool rootp (const cl_I& x, uintL n, cl_I* w);
+ extern bool rootp (const cl_I& x, const cl_I& n, cl_I* w);
// max(x,y) liefert (max x y), wo x und y ganze Zahlen sind.
{ return compare(x,y)>0; }
// minusp(x) == (< x 0)
-extern cl_boolean minusp (const cl_LF& x);
+extern bool minusp (const cl_LF& x);
// zerop(x) stellt fest, ob ein Long-Float x = 0.0 ist.
-extern cl_boolean zerop (const cl_LF& x);
+extern bool zerop (const cl_LF& x);
// plusp(x) == (> x 0)
-extern cl_boolean plusp (const cl_LF& x);
+extern bool plusp (const cl_LF& x);
// Liefert zu zwei Long-Float x und y : (+ x y), ein LF.
extern const cl_LF operator+ (const cl_LF& x, const cl_LF& y);
// Assignment operators.
cl_LF& operator= (const cl_LF&);
// Optimization of method pointer_p().
- cl_boolean pointer_p() const
- { return cl_true; }
+ bool pointer_p() const
+ { return true; }
// Faster pointer_p() gives a faster copy constructor (but not destructor!!!).
cl_LF (const cl_LF& x);
// Other constructors.
// print
void (* fprint) (cl_heap_modint_ring* R, std::ostream& stream, const _cl_MI& x);
// equality
- cl_boolean (* equal) (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y);
+ bool (* equal) (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y);
// random number
const _cl_MI (* random) (cl_heap_modint_ring* R, random_state& randomstate);
};
struct _cl_modint_addops /* cf. _cl_ring_addops */ {
// 0
const _cl_MI (* zero) (cl_heap_modint_ring* R);
- cl_boolean (* zerop) (cl_heap_modint_ring* R, const _cl_MI& x);
+ bool (* zerop) (cl_heap_modint_ring* R, const _cl_MI& x);
// x+y
const _cl_MI (* plus) (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y);
// x-y
// Low-level operations.
void _fprint (std::ostream& stream, const _cl_MI& x)
{ setops->fprint(this,stream,x); }
- cl_boolean _equal (const _cl_MI& x, const _cl_MI& y)
+ bool _equal (const _cl_MI& x, const _cl_MI& y)
{ return setops->equal(this,x,y); }
const _cl_MI _random (random_state& randomstate)
{ return setops->random(this,randomstate); }
const _cl_MI _zero ()
{ return addops->zero(this); }
- cl_boolean _zerop (const _cl_MI& x)
+ bool _zerop (const _cl_MI& x)
{ return addops->zerop(this,x); }
const _cl_MI _plus (const _cl_MI& x, const _cl_MI& y)
{ return addops->plus(this,x,y); }
if (!(x.ring() == this)) throw runtime_exception();
_fprint(stream,x);
}
- cl_boolean equal (const cl_MI& x, const cl_MI& y)
+ bool equal (const cl_MI& x, const cl_MI& y)
{
if (!(x.ring() == this)) throw runtime_exception();
if (!(y.ring() == this)) throw runtime_exception();
{
return cl_MI(this,_zero());
}
- cl_boolean zerop (const cl_MI& x)
+ bool zerop (const cl_MI& x)
{
if (!(x.ring() == this)) throw runtime_exception();
return _zerop(x);
{ return !y.ring()->equal(y.ring()->canonhom(x),y); }
// Compare against 0.
-inline cl_boolean zerop (const cl_MI& x)
+inline bool zerop (const cl_MI& x)
{ return x.ring()->zerop(x); }
// Multiply.
// isprobprime(n), n integer > 0,
// returns true when n is probably prime.
// This is pretty quick, but no caching is done.
- extern cl_boolean isprobprime (const cl_I& n);
+ extern bool isprobprime (const cl_I& n);
// nextprobprime(x) returns the smallest probable prime >= x.
extern const cl_I nextprobprime (const cl_R& x);
#endif
// Distinguish immediate data from pointers.
-inline cl_boolean cl_pointer_p (cl_uint word)
+inline bool cl_pointer_p (cl_uint word)
{
- return (cl_boolean)((word & (cl_word_alignment-1)) == 0);
+ return (word & (cl_word_alignment-1)) == 0;
}
-inline cl_boolean cl_immediate_p (cl_uint word)
+inline bool cl_immediate_p (cl_uint word)
{
- return (cl_boolean)((word & (cl_word_alignment-1)) != 0);
+ return (word & (cl_word_alignment-1)) != 0;
}
// Immediate data: Fixnum, Short Float, maybe Single Float.
// Assignment operator.
cl_gcobject& operator= (const cl_gcobject&);
// Distinguish immediate data from pointer.
- cl_boolean pointer_p() const
+ bool pointer_p() const
{ return cl_pointer_p(word); }
// Reference counting.
void inc_pointer_refcount () const
// Assignment operator.
cl_gcpointer& operator= (const cl_gcpointer&);
// Distinguish immediate data from pointer.
- cl_boolean pointer_p() const
- { return cl_true; }
+ bool pointer_p() const
+ { return true; }
// Reference counting.
void inc_pointer_refcount () const
{ cl_inc_pointer_refcount(heappointer); }
// Assignment operator.
cl_rcobject& operator= (const cl_rcobject&);
// Distinguish immediate data from pointer.
- cl_boolean pointer_p() const
+ bool pointer_p() const
{ return cl_pointer_p(word); }
// Reference counting.
void inc_pointer_refcount () const
// Assignment operator.
cl_rcpointer& operator= (const cl_rcpointer&);
// Distinguish immediate data from pointer.
- cl_boolean pointer_p() const
- { return cl_true; }
+ bool pointer_p() const
+ { return true; }
// Reference counting.
void inc_pointer_refcount () const
{ cl_inc_pointer_refcount(heappointer); }
unsigned int rational_base;
// Flag whether to print radix specifiers in Common Lisp syntax for
// rational numbers (#nR or #b or #o or #x prefixes, trailing dot).
- cl_boolean rational_readably;
+ bool rational_readably;
// Constructor.
cl_print_rational_flags () :
rational_base (10),
- rational_readably (cl_false) {}
+ rational_readably (false) {}
};
struct cl_print_float_flags {
// Flag whether to prefer type specific exponent markers over 'E'.
- cl_boolean float_readably;
+ bool float_readably;
// If !float_readably, the format which earns the 'E' exponent marker.
float_format_t default_float_format;
// Constructor.
cl_print_float_flags () :
- float_readably (cl_false),
+ float_readably (false),
default_float_format (float_format_ffloat) {}
};
struct cl_print_complex_flags {
// Flag whether to use the Common Lisp #C(realpart imagpart) syntax,
- cl_boolean complex_readably;
+ bool complex_readably;
// Constructor.
cl_print_complex_flags () :
- complex_readably (cl_false) {}
+ complex_readably (false) {}
};
struct cl_print_number_flags : cl_print_real_flags, cl_print_complex_flags {};
extern const cl_RA abs (const cl_RA& r);
// equal(r,s) vergleicht zwei rationale Zahlen r und s auf Gleichheit.
-extern cl_boolean equal (const cl_RA& r, const cl_RA& s);
+extern bool equal (const cl_RA& r, const cl_RA& s);
// equal_hashcode(r) liefert einen equal-invarianten Hashcode für r.
extern uint32 equal_hashcode (const cl_RA& r);
{ return compare(x,y)>0; }
// minusp(x) == (< x 0)
-extern cl_boolean minusp (const cl_RA& x);
+extern bool minusp (const cl_RA& x);
// zerop(x) stellt fest, ob eine rationale Zahl = 0 ist.
-extern cl_boolean zerop (const cl_RA& x);
+extern bool zerop (const cl_RA& x);
// plusp(x) == (> x 0)
-extern cl_boolean plusp (const cl_RA& x);
+extern bool plusp (const cl_RA& x);
// Kehrwert (/ r), wo r eine rationale Zahl ist.
extern const cl_RA recip (const cl_RA& r);
// sqrtp(x,&w)
// > x: eine rationale Zahl >=0
// < w: rationale Zahl (sqrt x) falls x Quadratzahl
-// < ergebnis: cl_true ..................., cl_false sonst
- extern cl_boolean sqrtp (const cl_RA& x, cl_RA* w);
+// < ergebnis: true ..................., false sonst
+ extern bool sqrtp (const cl_RA& x, cl_RA* w);
// Stellt fest, ob eine rationale Zahl >=0 die n-te Potenz einer rationalen Zahl
// ist.
// > x: eine rationale Zahl >=0
// > n: ein Integer >0
// < w: exakte n-te Wurzel (expt x (/ n)) falls x eine n-te Potenz
-// < ergebnis: cl_true ........................, cl_false sonst
- extern cl_boolean rootp (const cl_RA& x, uintL n, cl_RA* w);
- extern cl_boolean rootp (const cl_RA& x, const cl_I& n, cl_RA* w);
+// < ergebnis: true ........................, false sonst
+ extern bool rootp (const cl_RA& x, uintL n, cl_RA* w);
+ extern bool rootp (const cl_RA& x, const cl_I& n, cl_RA* w);
// Liefert zu Integers a>0, b>1 den Logarithmus log(a,b),
// falls er eine rationale Zahl ist.
// > a: ein Integer >0
// > b: ein Integer >1
// < l: log(a,b) falls er eine exakte rationale Zahl ist
-// < ergebnis: cl_true ......................................., cl_false sonst
- extern cl_boolean logp (const cl_I& a, const cl_I& b, cl_RA* l);
+// < ergebnis: true ......................................., false sonst
+ extern bool logp (const cl_I& a, const cl_I& b, cl_RA* l);
// Liefert zu rationalen Zahlen a>0, b>0 den Logarithmus log(a,b),
// falls er eine rationale Zahl ist.
// > a: eine rationale Zahl >0
// > b: eine rationale Zahl >0, /=1
// < l: log(a,b) falls er eine exakte rationale Zahl ist
-// < ergebnis: cl_true ......................................., cl_false sonst
- extern cl_boolean logp (const cl_RA& a, const cl_RA& b, cl_RA* l);
+// < ergebnis: true ......................................., false sonst
+ extern bool logp (const cl_RA& a, const cl_RA& b, cl_RA* l);
// Konversion zu einem C "float".
extern float float_approx (const cl_RA& x);
// zerop(x) testet, ob (= x 0).
-extern cl_boolean zerop (const cl_R& x);
+extern bool zerop (const cl_R& x);
// minusp(x) testet, ob (< x 0).
-extern cl_boolean minusp (const cl_R& x);
+extern bool minusp (const cl_R& x);
// plusp(x) testet, ob (> x 0).
-extern cl_boolean plusp (const cl_R& x);
+extern bool plusp (const cl_R& x);
// R_to_SF(x) wandelt eine reelle Zahl x in ein Short-Float um.
// equal(x,y) vergleicht zwei reelle Zahlen x und y auf Gleichheit.
-extern cl_boolean equal (const cl_R& x, const cl_R& y);
+extern bool equal (const cl_R& x, const cl_R& y);
// equal_hashcode(x) liefert einen equal-invarianten Hashcode für x.
extern uint32 equal_hashcode (const cl_R& x);
// print
void (* fprint) (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x);
// equality
- cl_boolean (* equal) (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y);
+ bool (* equal) (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y);
// ...
};
struct _cl_ring_addops {
// 0
const _cl_ring_element (* zero) (cl_heap_ring* R);
- cl_boolean (* zerop) (cl_heap_ring* R, const _cl_ring_element& x);
+ bool (* zerop) (cl_heap_ring* R, const _cl_ring_element& x);
// x+y
const _cl_ring_element (* plus) (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y);
// x-y
// Low-level operations.
void _fprint (std::ostream& stream, const _cl_ring_element& x)
{ setops->fprint(this,stream,x); }
- cl_boolean _equal (const _cl_ring_element& x, const _cl_ring_element& y)
+ bool _equal (const _cl_ring_element& x, const _cl_ring_element& y)
{ return setops->equal(this,x,y); }
const _cl_ring_element _zero ()
{ return addops->zero(this); }
- cl_boolean _zerop (const _cl_ring_element& x)
+ bool _zerop (const _cl_ring_element& x)
{ return addops->zerop(this,x); }
const _cl_ring_element _plus (const _cl_ring_element& x, const _cl_ring_element& y)
{ return addops->plus(this,x,y); }
if (!(x.ring() == this)) throw runtime_exception();
_fprint(stream,x);
}
- cl_boolean equal (const cl_ring_element& x, const cl_ring_element& y)
+ bool equal (const cl_ring_element& x, const cl_ring_element& y)
{
if (!(x.ring() == this)) throw runtime_exception();
if (!(y.ring() == this)) throw runtime_exception();
{
return cl_ring_element(this,_zero());
}
- cl_boolean zerop (const cl_ring_element& x)
+ bool zerop (const cl_ring_element& x)
{
if (!(x.ring() == this)) throw runtime_exception();
return _zerop(x);
{ return !x.ring()->equal(x,y); }
// Compare against 0.
-inline cl_boolean zerop (const cl_ring_element& x)
+inline bool zerop (const cl_ring_element& x)
{ return x.ring()->zerop(x); }
// Multiply.
template <class T>
struct cl_number_ring_ops {
- cl_boolean (* contains) (const cl_number&);
- cl_boolean (* equal) (const T&, const T&);
- cl_boolean (* zerop) (const T&);
+ bool (* contains) (const cl_number&);
+ bool (* equal) (const T&, const T&);
+ bool (* zerop) (const T&);
const T (* plus) (const T&, const T&);
const T (* minus) (const T&, const T&);
const T (* uminus) (const T&);
};
// Type test.
-inline cl_boolean instanceof (const cl_number& x, const cl_number_ring& R)
+inline bool instanceof (const cl_number& x, const cl_number_ring& R)
{
return ((cl_heap_number_ring*) R.heappointer)->ops->contains(x);
}
{ return compare(x,y)>0; }
// minusp(x) == (< x 0)
-extern cl_boolean minusp (const cl_SF& x);
+extern bool minusp (const cl_SF& x);
// zerop(x) stellt fest, ob ein Short-Float x = 0.0 ist.
-extern cl_boolean zerop (const cl_SF& x);
+extern bool zerop (const cl_SF& x);
// plusp(x) == (> x 0)
-extern cl_boolean plusp (const cl_SF& x);
+extern bool plusp (const cl_SF& x);
// Liefert zu zwei Short-Float x und y : (+ x y), ein SF.
extern const cl_SF operator+ (const cl_SF& x, const cl_SF& y);
// Assignment operators.
cl_SF& operator= (const cl_SF&);
// Optimization of method pointer_p().
- cl_boolean pointer_p() const
- { return cl_false; }
+ bool pointer_p() const
+ { return false; }
// Faster pointer_p() gives a faster copy constructor (but not destructor!!!).
cl_SF (const cl_SF& x);
// Other constructors.
typedef uint64 uintQ;
#endif
-// Boolean type.
-#if 1
- typedef enum { cl_false = 0, cl_true = 1 }
- cl_boolean;
-#else
- typedef bool cl_boolean;
- #define cl_false 0
- #define cl_true 1
-#endif
-
// Type for three values (0, +1, -1).
typedef int cl_signean;
#define signean_plus 1
// equality
// (Be careful: This is not well-defined for polynomials with
// floating-point coefficients.)
- cl_boolean (* equal) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
+ bool (* equal) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
};
struct _cl_univpoly_addops /* cf. _cl_ring_addops */ {
// 0
const _cl_UP (* zero) (cl_heap_univpoly_ring* R);
- cl_boolean (* zerop) (cl_heap_univpoly_ring* R, const _cl_UP& x);
+ bool (* zerop) (cl_heap_univpoly_ring* R, const _cl_UP& x);
// x+y
const _cl_UP (* plus) (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y);
// x-y
// Low-level operations.
void _fprint (std::ostream& stream, const _cl_UP& x)
{ setops->fprint(this,stream,x); }
- cl_boolean _equal (const _cl_UP& x, const _cl_UP& y)
+ bool _equal (const _cl_UP& x, const _cl_UP& y)
{ return setops->equal(this,x,y); }
const _cl_UP _zero ()
{ return addops->zero(this); }
- cl_boolean _zerop (const _cl_UP& x)
+ bool _zerop (const _cl_UP& x)
{ return addops->zerop(this,x); }
const _cl_UP _plus (const _cl_UP& x, const _cl_UP& y)
{ return addops->plus(this,x,y); }
if (!(x.ring() == this)) throw runtime_exception();
_fprint(stream,x);
}
- cl_boolean equal (const cl_UP& x, const cl_UP& y)
+ bool equal (const cl_UP& x, const cl_UP& y)
{
if (!(x.ring() == this)) throw runtime_exception();
if (!(y.ring() == this)) throw runtime_exception();
{
return cl_UP(this,_zero());
}
- cl_boolean zerop (const cl_UP& x)
+ bool zerop (const cl_UP& x)
{
if (!(x.ring() == this)) throw runtime_exception();
return _zerop(x);
{ return !x.ring()->equal(x,y); }
// Compare against 0.
-inline cl_boolean zerop (const cl_UP& x)
+inline bool zerop (const cl_UP& x)
{ return x.ring()->zerop(x); }
// Multiply.
{
cl_heap_univpoly_ring::fprint(stream,x);
}
- cl_boolean equal (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
+ bool equal (const cl_UP_specialized<T>& x, const cl_UP_specialized<T>& y)
{
return cl_heap_univpoly_ring::equal(x,y);
}
{
return The2(cl_UP_specialized<T>)(cl_heap_univpoly_ring::zero());
}
- cl_boolean zerop (const cl_UP_specialized<T>& x)
+ bool zerop (const cl_UP_specialized<T>& x)
{
return cl_heap_univpoly_ring::zerop(x);
}
{
cl_heap_univpoly_ring::fprint(stream,x);
}
- cl_boolean equal (const cl_UP_N& x, const cl_UP_N& y)
+ bool equal (const cl_UP_N& x, const cl_UP_N& y)
{
return cl_heap_univpoly_ring::equal(x,y);
}
{
return The2(cl_UP_N)(cl_heap_univpoly_ring::zero());
}
- cl_boolean zerop (const cl_UP_N& x)
+ bool zerop (const cl_UP_N& x)
{
return cl_heap_univpoly_ring::zerop(x);
}
{
cl_heap_univpoly_ring::fprint(stream,x);
}
- cl_boolean equal (const cl_UP_I& x, const cl_UP_I& y)
+ bool equal (const cl_UP_I& x, const cl_UP_I& y)
{
return cl_heap_univpoly_ring::equal(x,y);
}
{
return The2(cl_UP_I)(cl_heap_univpoly_ring::zero());
}
- cl_boolean zerop (const cl_UP_I& x)
+ bool zerop (const cl_UP_I& x)
{
return cl_heap_univpoly_ring::zerop(x);
}
{
cl_heap_univpoly_ring::fprint(stream,x);
}
- cl_boolean equal (const cl_UP_MI& x, const cl_UP_MI& y)
+ bool equal (const cl_UP_MI& x, const cl_UP_MI& y)
{
return cl_heap_univpoly_ring::equal(x,y);
}
{
return The2(cl_UP_MI)(cl_heap_univpoly_ring::zero());
}
- cl_boolean zerop (const cl_UP_MI& x)
+ bool zerop (const cl_UP_MI& x)
{
return cl_heap_univpoly_ring::zerop(x);
}
{
cl_heap_univpoly_ring::fprint(stream,x);
}
- cl_boolean equal (const cl_UP_RA& x, const cl_UP_RA& y)
+ bool equal (const cl_UP_RA& x, const cl_UP_RA& y)
{
return cl_heap_univpoly_ring::equal(x,y);
}
{
return The2(cl_UP_RA)(cl_heap_univpoly_ring::zero());
}
- cl_boolean zerop (const cl_UP_RA& x)
+ bool zerop (const cl_UP_RA& x)
{
return cl_heap_univpoly_ring::zerop(x);
}
{
cl_heap_univpoly_ring::fprint(stream,x);
}
- cl_boolean equal (const cl_UP_R& x, const cl_UP_R& y)
+ bool equal (const cl_UP_R& x, const cl_UP_R& y)
{
return cl_heap_univpoly_ring::equal(x,y);
}
{
return The2(cl_UP_R)(cl_heap_univpoly_ring::zero());
}
- cl_boolean zerop (const cl_UP_R& x)
+ bool zerop (const cl_UP_R& x)
{
return cl_heap_univpoly_ring::zerop(x);
}
//
// Break-even-point. When in doubt, prefer to choose the standard algorithm.
#if CL_USE_GMP
- static inline cl_boolean cl_recip_suitable (uintC m, uintC n) // n <= m
+ static inline bool cl_recip_suitable (uintC m, uintC n) // n <= m
{ if (n < 2000)
- return cl_false;
+ return false;
else // when n >= 4400/(m/n)^2, i.e. (m/66)^2 > n
{ var uintC mq = floor(m,66);
if ((mq >= bit(intCsize/2)) || (mq*mq > n))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}
}
#else
// 1.8*N / N : Newton for N >= 500
// 1.9*N / N : Newton for N >= 500
// 2.0*N / N : Newton for N >= 500
- static inline cl_boolean cl_recip_suitable (uintC m, uintC n) // n <= m
+ static inline bool cl_recip_suitable (uintC m, uintC n) // n <= m
{ if (n < 500)
- return cl_false;
+ return false;
else // when n >= 2100/(m/n)^2, i.e. (m/46)^2 > n
{ var uintC mq = floor(m,46);
if ((mq >= bit(intCsize/2)) || (mq*mq > n))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}
}
#endif
#ifdef TEST_LOOPS
-extern cl_boolean test_loop_up (const uintD* ptr, uintC count);
+extern bool test_loop_up (const uintD* ptr, uintC count);
-extern cl_boolean test_loop_down (const uintD* ptr, uintC count);
+extern bool test_loop_down (const uintD* ptr, uintC count);
#endif
#ifdef TEST_LOOPS
-extern cl_boolean and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count);
+extern bool and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count);
extern cl_signean compare_loop_up (const uintD* xptr, const uintD* yptr, uintC count);
#ifdef TEST_LOOPS
-extern cl_boolean and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count);
+extern bool and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count);
extern cl_signean compare_loop_down (const uintD* xptr, const uintD* yptr, uintC count);
// test_loop_up(ptr,count)
// testet count (uintC>=0) Digits aufwärts ab ptr, ob darunter eines /=0 ist.
// Ergebnis /=0, falls ja.
- inline cl_boolean test_loop_up (const uintD* ptr, uintC count)
- { dotimesC(count,count, { if (*ptr++) return cl_true; } );
- return cl_false;
+ inline bool test_loop_up (const uintD* ptr, uintC count)
+ { dotimesC(count,count, { if (*ptr++) return true; } );
+ return false;
}
// Test-Schleife:
// test_loop_down(ptr,count)
// testet count (uintC>=0) Digits abwärts ab ptr, ob darunter eines /=0 ist.
// Ergebnis /=0, falls ja.
- inline cl_boolean test_loop_down (const uintD* ptr, uintC count)
- { dotimesC(count,count, { if (*--ptr) return cl_true; } );
- return cl_false;
+ inline bool test_loop_down (const uintD* ptr, uintC count)
+ { dotimesC(count,count, { if (*--ptr) return true; } );
+ return false;
}
#endif
// AND-Test-Schleife:
// and_test_loop_up(xptr,yptr,count);
// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr durch AND
-// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis cl_true, falls ja.
- inline cl_boolean and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count)
- { dotimesC(count,count, { if (*xptr++ & *yptr++) return cl_true; } );
- return cl_false;
+// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis true, falls ja.
+ inline bool and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count)
+ { dotimesC(count,count, { if (*xptr++ & *yptr++) return true; } );
+ return false;
}
// Vergleichsschleife:
// AND-Test-Schleife:
// and_test_loop_down(xptr,yptr,count);
// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr durch AND
-// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis cl_true, falls ja.
- inline cl_boolean and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count)
- { dotimesC(count,count, { if (*--xptr & *--yptr) return cl_true; } );
- return cl_false;
+// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis true, falls ja.
+ inline bool and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count)
+ { dotimesC(count,count, { if (*--xptr & *--yptr) return true; } );
+ return false;
}
// Vergleichsschleife:
// UDS_sqrt(a_MSDptr,a_len,a_LSDptr, &b, squarep=)
// > a_MSDptr/a_len/a_LSDptr: eine UDS
// < NUDS b: Gaußklammer der Wurzel aus a
-// < squarep: cl_true falls a = b^2, cl_false falls b^2 < a < (b+1)^2.
+// < squarep: true falls a = b^2, false falls b^2 < a < (b+1)^2.
// a wird nicht modifiziert.
// Vorzeichenerweiterung von b ist erlaubt.
// num_stack wird erniedrigt.
num_stack_alloc_1(ceiling(_a_len,2),(b_)->MSDptr=,); \
squarep_zuweisung cl_UDS_sqrt(a_MSDptr,_a_len,a_LSDptr,b_); \
}
- extern cl_boolean cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDptr, DS* b_);
+ extern bool cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDptr, DS* b_);
// Auxiliary function for approximately computing 1/x
// Break-even-point, should be acceptable for both architectures.
// When in doubt, prefer to choose the standard algorithm.
#if CL_USE_GMP
- static inline cl_boolean cl_recip_suitable (uintL m, uintL n) // m > n
+ static inline bool cl_recip_suitable (uintL m, uintL n) // m > n
{ if (n < 900)
- return cl_false;
+ return false;
else
if (n < 2200)
- return (cl_boolean)((m >= n+50) && (m < 2*n-600));
+ return (m >= n+50) && (m < 2*n-600);
else
- return (cl_boolean)(m >= n+30);
+ return m >= n+30;
}
#else
// Use the old default values from CLN version <= 1.0.3 as a crude estimate.
// n = 2000: Newton faster for m >= 2020
// n = 2500: Newton faster for m >= 2520
// n = 5000: Newton faster for m >= 5020
- static inline cl_boolean cl_recip_suitable (uintL m, uintL n) // m > n
+ static inline bool cl_recip_suitable (uintL m, uintL n) // m > n
{ if (n < 500)
- return cl_false;
+ return false;
else
if (n < 1000)
- return (cl_boolean)((m >= n+30) && (m < 3*n-600));
+ return (m >= n+30) && (m < 3*n-600);
else
- return (cl_boolean)(m >= n+20);
+ return m >= n+20;
}
#endif
const unsigned int cl_fftm_threshold2 = 2*cl_fftm_threshold;
// len1 > cl_fftm_threshold1 && len2 > cl_fftm_threshold2
// && len1 >= cl_fftm_threshold1 + cl_fftm_threshold/(len2-cl_fftm_threshold1)*(cl_fftm_threshold-cl_fftm_threshold1).
- static inline cl_boolean cl_fftm_suitable (uintC len1, uintC len2)
+ static inline bool cl_fftm_suitable (uintC len1, uintC len2)
{ if (len1 >= cl_fftm_threshold)
- return cl_true;
+ return true;
if (len1 > cl_fftm_threshold1)
if (len2 > cl_fftm_threshold2)
{ const unsigned int prod_threshold = cl_fftm_threshold*(cl_fftm_threshold-cl_fftm_threshold1);
if (len1-cl_fftm_threshold1 >= prod_threshold)
- return cl_true;
+ return true;
if (len2-cl_fftm_threshold1 >= prod_threshold)
- return cl_true;
+ return true;
var uint32 hi;
var uint32 lo;
mulu32(len1-cl_fftm_threshold1,len2-cl_fftm_threshold1, hi=,lo=);
if (hi > 0 || lo >= prod_threshold)
- return cl_true;
+ return true;
}
- return cl_false;
+ return false;
}
#if 0 // Doesn't seem to be worth the effort
if (sourceptr1 == sourceptr2)
if (len1 == len2)
{ mulu_karatsuba_square(sourceptr1,len1,destptr); return; }
- var cl_boolean first_part = cl_true; // Flag, ob jetzt das erste Teilprodukt berechnet wird
+ var bool first_part = true; // Flag, ob jetzt das erste Teilprodukt berechnet wird
if (len2 >= 2*len1)
{ CL_SMALL_ALLOCA_STACK;
// Teilprodukte von jeweils len1 mal len1 Digits bilden:
if (first_part)
{ copy_loop_lsp(prod_LSDptr,destptr,2*len1);
destptr = destptr lspop len1;
- first_part = cl_false;
+ first_part = false;
}
else
{ var uintD carry =
// Newton faster for 3200<N Newton faster for 2750<N
// When in doubt, prefer to choose the standard algorithm.
#if CL_USE_GMP
- static inline cl_boolean cl_recipsqrt_suitable (uintC n)
- { return (cl_boolean)(n >= 3200); }
+ static inline bool cl_recipsqrt_suitable (uintC n)
+ { return n >= 3200; }
#else
// Use the old default values from CLN version <= 1.0.3 as a crude estimate.
// Time for square root of a_len = 2*N by b_len = N digits,
// 5000 24.1 10.7
// 10000 98 23.2
// -----> Newton faster for 1570 <= N <= 1790 and for N >= 2100.
- static inline cl_boolean cl_recipsqrt_suitable (uintC n)
- { return (cl_boolean)(n >= 2100); }
+ static inline bool cl_recipsqrt_suitable (uintC n)
+ { return n >= 2100; }
#endif
// Bildet zu einer Unsigned Digit sequence a die Wurzel
// squarep = cl_UDS_sqrt(a_MSDptr,a_len,a_LSDptr, &b);
// > a_MSDptr/a_len/a_LSDptr: eine UDS
// < NUDS b: Gaußklammer der Wurzel aus a
-// < squarep: cl_true falls a = b^2, cl_false falls b^2 < a < (b+1)^2.
+// < squarep: true falls a = b^2, false falls b^2 < a < (b+1)^2.
// Methode:
// erst A normalisieren. A=0 --> B=0, fertig.
// Wähle n so, daß beta^(2n-2) <= A < beta^(2n).
// Ergebnis ist [b[n-1],...,b[0]] * 2^(-s), schiebe also im Speicher
// [b[n],...,b[0]] um s+1 Bits nach rechts.
// Das Ergebnis ist eine NUDS der Länge n.
-cl_boolean cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDptr, DS* b_)
+bool cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDptr, DS* b_)
{
// A normalisieren:
while ((a_len>0) && (mspref(a_MSDptr,0)==0)) { msshrink(a_MSDptr); a_len--; }
if (a_len==0) // A=0 -> B := NUDS 0
- { b_->LSDptr = b_->MSDptr; b_->len = 0; return cl_true; }
+ { b_->LSDptr = b_->MSDptr; b_->len = 0; return true; }
CL_ALLOCA_STACK;
// n und s bestimmen:
var uintC n = ceiling(a_len,2); // a_len = 2n oder 2n-1, n>0.
shiftright_loop_msp(b_->MSDptr,n,s);
// Teste, ob alle a[n],...,a[0]=0 sind:
if (test_loop_msp(a_MSDptr mspop (n-1),n+1))
- return cl_false;
+ return false;
else
- return cl_true; // ja -> Wurzel exakt
+ return true; // ja -> Wurzel exakt
}
// Platz für B belegen:
{ var uintD* b_MSDptr = b_->MSDptr mspop -1; // ab hier n+1 Digits Platz
b_->MSDptr = b_MSDptr; b_->len = n; b_->LSDptr = b_ptr;
// Teste, ob alle a[n],...,a[0]=0 sind:
if (test_loop_msp(a_mptr,n+1))
- { return cl_false; }
+ { return false; }
else
- { return cl_true; } // ja -> Wurzel exakt
+ { return true; } // ja -> Wurzel exakt
}}
}
// Bit complexity (N := a_len): O(M(N)).
long * _slots; // vector of length _modulus
htxentry * _entries; // vector of length _size
void* _total_vector;
- cl_boolean (*_garcol_fun) (cl_heap*); // Function to make room in the table.
+ bool (*_garcol_fun) (cl_heap*); // Function to make room in the table.
// Putting some intelligent function here turns
// a normal hash table into a "weak" hash table.
public:
}
private:
// Default function to make room in a hash table.
- static cl_boolean no_garcol (cl_heap* ht) { unused ht; return cl_false; }
+ static bool no_garcol (cl_heap* ht) { unused ht; return false; }
};
template <class htentry>
void operator delete (void* ptr) { free_hook(ptr); }
public:
// Function which tells when an unused entry may be garbage collected.
- cl_boolean (* const _maygc_htentry) (const cl_htentry1<key1_type,value_type>&);
+ bool (* const _maygc_htentry) (const cl_htentry1<key1_type,value_type>&);
// Constructor.
- cl_heap_weak_hashtable_1 (cl_boolean (*maygc_htentry) (const cl_htentry1<key1_type,value_type>&))
+ cl_heap_weak_hashtable_1 (bool (*maygc_htentry) (const cl_htentry1<key1_type,value_type>&))
: cl_heap_hashtable_1 <key1_type,value_type> (),
_maygc_htentry (maygc_htentry)
{
// Garbage collection.
// Before growing the table, we check whether we can remove unused
// entries.
- static cl_boolean garcol (cl_heap* _ht)
+ static bool garcol (cl_heap* _ht)
{
var cl_heap_weak_hashtable_1* ht = (cl_heap_weak_hashtable_1*)_ht;
// Now ht->_garcol_fun = garcol.
// It is not worth doing a garbage collection if the table
// is small, say, has fewer than 100 entries.
if (ht->_count < 100)
- return cl_false;
+ return false;
// Do a garbage collection.
var long removed = 0;
for (long i = 0; i < ht->_size; i++)
}
if (removed == 0)
// Unsuccessful. Let the table grow immediately.
- return cl_false;
+ return false;
else if (2*removed < ht->_count) {
// Table shrank by less than a factor of 1/1.5.
// Don't expand the table now, but expand it next time.
ht->_garcol_fun = cl_heap_weak_hashtable_1<key1_type,value_type>::garcol_nexttime;
- return cl_true;
+ return true;
} else {
// Table shrank much. Don't expand the table now,
// and try a GC next time.
- return cl_true;
+ return true;
}
}
- static cl_boolean garcol_nexttime (cl_heap* _ht)
+ static bool garcol_nexttime (cl_heap* _ht)
{
var cl_heap_weak_hashtable_1* ht = (cl_heap_weak_hashtable_1*)_ht;
// Now ht->_garcol_fun = garcol_nexttime.
ht->_garcol_fun = cl_heap_weak_hashtable_1<key1_type,value_type>::garcol;
- return cl_false;
+ return false;
}
};
void operator delete (void* ptr) { free_hook(ptr); }
public:
// Function which tells when an unused entry may be garbage collected.
- cl_boolean (* const _maygc_htentry) (const cl_htentry2<key1_type,key2_type,value_type>&);
+ bool (* const _maygc_htentry) (const cl_htentry2<key1_type,key2_type,value_type>&);
// Constructor.
- cl_heap_weak_hashtable_2 (cl_boolean (*maygc_htentry) (const cl_htentry2<key1_type,key2_type,value_type>&))
+ cl_heap_weak_hashtable_2 (bool (*maygc_htentry) (const cl_htentry2<key1_type,key2_type,value_type>&))
: cl_heap_hashtable_2 <key1_type,key2_type,value_type> (),
_maygc_htentry (maygc_htentry)
{
// Garbage collection.
// Before growing the table, we check whether we can remove unused
// entries.
- static cl_boolean garcol (cl_heap* _ht)
+ static bool garcol (cl_heap* _ht)
{
var cl_heap_weak_hashtable_2* ht = (cl_heap_weak_hashtable_2*)_ht;
// Now ht->_garcol_fun = garcol.
// It is not worth doing a garbage collection if the table
// is small, say, has fewer than 100 entries.
if (ht->_count < 100)
- return cl_false;
+ return false;
// Do a garbage collection.
var long removed = 0;
for (long i = 0; i < ht->_size; i++)
}
if (removed == 0)
// Unsuccessful. Let the table grow immediately.
- return cl_false;
+ return false;
else if (2*removed < ht->_count) {
// Table shrank by less than a factor of 1/1.5.
// Don't expand the table now, but expand it next time.
ht->_garcol_fun = garcol_nexttime;
- return cl_true;
+ return true;
} else {
// Table shrank much. Don't expand the table now,
// and try a GC next time.
- return cl_true;
+ return true;
}
}
- static cl_boolean garcol_nexttime (cl_heap* _ht)
+ static bool garcol_nexttime (cl_heap* _ht)
{
var cl_heap_weak_hashtable_2* ht = (cl_heap_weak_hashtable_2*)_ht;
// Now ht->_garcol_fun = garcol_nexttime.
ht->_garcol_fun = cl_heap_weak_hashtable_2<key1_type,key2_type,value_type>::garcol;
- return cl_false;
+ return false;
}
};
// Garbage collection.
// Before growing the table, we check whether we can remove unused
// entries.
- static cl_boolean garcol (cl_heap* _ht)
+ static bool garcol (cl_heap* _ht)
{
var cl_heap_weak_hashtable_uniq* ht = (cl_heap_weak_hashtable_uniq*)_ht;
// Now ht->_garcol_fun = garcol.
// It is not worth doing a garbage collection if the table
// is small, say, has fewer than 100 entries.
if (ht->_count < 100)
- return cl_false;
+ return false;
// Do a garbage collection.
var long removed = 0;
for (long i = 0; i < ht->_size; i++)
}
if (removed == 0)
// Unsuccessful. Let the table grow immediately.
- return cl_false;
+ return false;
else if (2*removed < ht->_count) {
// Table shrank by less than a factor of 1/1.5.
// Don't expand the table now, but expand it next time.
ht->_garcol_fun = garcol_nexttime;
- return cl_true;
+ return true;
} else {
// Table shrank much. Don't expand the table now,
// and try a GC next time.
- return cl_true;
+ return true;
}
}
- static cl_boolean garcol_nexttime (cl_heap* _ht)
+ static bool garcol_nexttime (cl_heap* _ht)
{
var cl_heap_weak_hashtable_uniq* ht = (cl_heap_weak_hashtable_uniq*)_ht;
// Now ht->_garcol_fun = garcol_nexttime.
ht->_garcol_fun = garcol;
- return cl_false;
+ return false;
}
};
// These are not inline, because they tend to duplicate a lot of template code.
-cl_wht_from_rcpointer2_to_rcpointer::cl_wht_from_rcpointer2_to_rcpointer (cl_boolean (*maygc_htentry) (const cl_htentry_from_rcpointer2_to_rcpointer&))
+cl_wht_from_rcpointer2_to_rcpointer::cl_wht_from_rcpointer2_to_rcpointer (bool (*maygc_htentry) (const cl_htentry_from_rcpointer2_to_rcpointer&))
{
var cl_heap_weak_hashtable_from_rcpointer2_to_rcpointer* ht = new cl_heap_weak_hashtable_from_rcpointer2_to_rcpointer (maygc_htentry);
ht->refcount = 1;
struct cl_wht_from_rcpointer2_to_rcpointer : public cl_rcpointer {
// Constructors.
- cl_wht_from_rcpointer2_to_rcpointer (cl_boolean (*maygc_htentry) (const cl_htentry_from_rcpointer2_to_rcpointer&));
+ cl_wht_from_rcpointer2_to_rcpointer (bool (*maygc_htentry) (const cl_htentry_from_rcpointer2_to_rcpointer&));
cl_wht_from_rcpointer2_to_rcpointer (const cl_wht_from_rcpointer2_to_rcpointer&);
// Assignment operators.
cl_wht_from_rcpointer2_to_rcpointer& operator= (const cl_wht_from_rcpointer2_to_rcpointer&);
// These are not inline, because they tend to duplicate a lot of template code.
-cl_wht_from_rcpointer_to_rcpointer::cl_wht_from_rcpointer_to_rcpointer (cl_boolean (*maygc_htentry) (const cl_htentry_from_rcpointer_to_rcpointer&))
+cl_wht_from_rcpointer_to_rcpointer::cl_wht_from_rcpointer_to_rcpointer (bool (*maygc_htentry) (const cl_htentry_from_rcpointer_to_rcpointer&))
{
var cl_heap_weak_hashtable_from_rcpointer_to_rcpointer* ht = new cl_heap_weak_hashtable_from_rcpointer_to_rcpointer (maygc_htentry);
ht->refcount = 1;
struct cl_wht_from_rcpointer_to_rcpointer : public cl_rcpointer {
// Constructors.
- cl_wht_from_rcpointer_to_rcpointer (cl_boolean (*maygc_htentry) (const cl_htentry_from_rcpointer_to_rcpointer&));
+ cl_wht_from_rcpointer_to_rcpointer (bool (*maygc_htentry) (const cl_htentry_from_rcpointer_to_rcpointer&));
cl_wht_from_rcpointer_to_rcpointer (const cl_wht_from_rcpointer_to_rcpointer&);
// Assignment operators.
cl_wht_from_rcpointer_to_rcpointer& operator= (const cl_wht_from_rcpointer_to_rcpointer&);
AT_INITIALIZATION(default_print_flags)
{
default_print_flags.rational_base = 10;
- default_print_flags.rational_readably = cl_false;
- default_print_flags.float_readably = cl_false;
+ default_print_flags.rational_readably = false;
+ default_print_flags.float_readably = false;
default_print_flags.default_float_format = float_format_ffloat;
- default_print_flags.complex_readably = cl_false;
+ default_print_flags.complex_readably = false;
default_print_flags.vector_syntax = vsyntax_pretty;
default_print_flags.univpoly_varname = "x";
}
unused stream;
throw uninitialized_exception(x);
}
-static cl_boolean dummy_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
+static bool dummy_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
{
unused R;
throw uninitialized_exception(x, y);
}
#define dummy_zero dummy_op0
-static cl_boolean dummy_zerop (cl_heap_ring* R, const _cl_ring_element& x)
+static bool dummy_zerop (cl_heap_ring* R, const _cl_ring_element& x)
{
unused R;
throw uninitialized_exception(x);
#endif
// Type tests
-inline cl_boolean realp (const cl_N& x)
+inline bool realp (const cl_N& x)
{
if (x.pointer_p())
if (x.heappointer->type == &cl_class_complex)
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}
-inline cl_boolean complexp (const cl_N& x)
+inline bool complexp (const cl_N& x)
{
if (x.pointer_p())
if (x.heappointer->type == &cl_class_complex)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
// Comparison with a fixnum.
-inline cl_boolean eq (const cl_N& x, sint32 y)
+inline bool eq (const cl_N& x, sint32 y)
{
- return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
+ return x.word == cl_combine(cl_FN_tag,y);
}
-inline cl_boolean exact_zerop (const cl_N& x)
+inline bool exact_zerop (const cl_N& x)
{
return eq(x,0);
}
public:
};
-inline cl_boolean realp (const cl_C& x)
- { unused x; return cl_false; }
-inline cl_boolean complexp (const cl_C& x)
- { unused x; return cl_true; }
+inline bool realp (const cl_C& x)
+ { unused x; return false; }
+inline bool complexp (const cl_C& x)
+ { unused x; return true; }
// Liefert zu reellen Zahlen a und b /= Fixnum 0 die komplexe Zahl a+bi.
namespace cln {
-cl_boolean equal (const cl_N& x, const cl_N& y)
+bool equal (const cl_N& x, const cl_N& y)
{
// Methode:
// Falls beide reell, klar.
DeclareType(cl_C,y);
// x reell, y komplex
if (!zerop(imagpart(y)))
- return cl_false;
+ return false;
return equal(x,realpart(y));
}
} else {
DeclareType(cl_R,y);
// x komplex, y reell
if (!zerop(imagpart(x)))
- return cl_false;
+ return false;
return equal(realpart(x),y);
} else {
DeclareType(cl_C,y);
// x,y beide komplex
if (!equal(realpart(x),realpart(y)))
- return cl_false;
+ return false;
if (!equal(imagpart(x),imagpart(y)))
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}
}
}
namespace cln {
-cl_boolean zerop (const cl_N& x)
+bool zerop (const cl_N& x)
{
if (realp(x)) {
DeclareType(cl_R,x);
var const cl_R& b = imagpart(x);
if (zerop(a))
if (zerop(b))
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
}
syntax_number,
lsyntax_all,
10,
- { float_format_ffloat, float_format_lfloat_min, cl_true }
+ { float_format_ffloat, float_format_lfloat_min, true }
};
cl_N::cl_N (const char * string)
}
var const char * ptr_after_sign = ptr;
var const char * ptr_after_intpart = skip_digits(ptr_after_sign,string_limit,float_base);
- var cl_boolean have_dot = cl_false;
+ var bool have_dot = false;
var const char * ptr_before_fracpart = ptr_after_intpart;
var const char * ptr_after_fracpart = ptr_after_intpart;
ptr = ptr_after_intpart;
if (ptr != string_limit)
if (*ptr == '.') {
- have_dot = cl_true;
+ have_dot = true;
ptr_before_fracpart = ptr+1;
ptr_after_fracpart = skip_digits(ptr_before_fracpart,string_limit,float_base);
}
ptr = ptr_after_fracpart;
var char exponent_marker;
- var cl_boolean have_exponent;
+ var bool have_exponent;
var const char * ptr_in_exponent = ptr;
var const char * ptr_after_exponent = ptr;
if ((ptr == string_limit) || !(((*ptr >= '0') && (*ptr <= '9')) || ((*ptr >= 'A') && (*ptr <= 'Z') && (*ptr != 'I')) || ((*ptr >= 'a') && (*ptr <= 'z') && (*ptr != 'i')) || (*ptr == '.') || (*ptr == '/'))) {
// No exponent.
- have_exponent = cl_false;
+ have_exponent = false;
// Must have at least one fractional part digit.
if (ptr_after_fracpart == ptr_before_fracpart) goto not_float_syntax;
exponent_marker = 'E';
} else {
- have_exponent = cl_true;
+ have_exponent = true;
// Must have at least one digit.
if (ptr_after_sign == ptr_after_intpart)
if (ptr_after_fracpart == ptr_before_fracpart)
char* end_pointer (void) { return buffer+index; }
};
-static cl_boolean number_char_p (char c)
+static bool number_char_p (char c)
{
if ((c >= '0') && (c <= '9'))
- return cl_true;
+ return true;
if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
- return cl_true;
+ return true;
switch (c) {
case '+': case '-': case '.': case '_': case '/':
- return cl_true;
+ return true;
default:
- return cl_false;
+ return false;
}
}
return expt(x,y);
}
if (eq(y,0)) { return 1; } // y=0 -> Ergebnis 1
- var cl_boolean y_negative = minusp(y);
+ var bool y_negative = minusp(y);
var cl_I abs_y = (y_negative ? -y : y); // Betrag von y nehmen
var cl_N z = expt_pos(x,abs_y); // (expt x (abs y))
return (y_negative ? recip(z) : z); // evtl. noch Kehrwert nehmen
// Cf. cl_N_p in cl_C_ring.cc.
// But here, for better inlining in g++, it is preferrable to finish every
-// alternative with either "return cl_true;" or "return cl_false;".
+// alternative with either "return true;" or "return false;".
-inline cl_boolean cl_N_p (const cl_number& x)
+inline bool cl_N_p (const cl_number& x)
{
if (!x.pointer_p())
switch (x.nonpointer_tag()) {
#if defined(CL_WIDE_POINTERS)
case cl_FF_tag:
#endif
- return cl_true;
+ return true;
}
else
if (x.pointer_type()->flags & cl_class_flags_subclass_complex)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_N& cl_N_As (const cl_number& x, const char * filename, int line)
fprint(stream,The(cl_N)(x));
}
-static cl_boolean N_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
+static bool N_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
{
unused R;
return equal(The(cl_N)(x),The(cl_N)(y));
return _cl_ring_element(R, (cl_N)0);
}
-static cl_boolean N_zerop (cl_heap_ring* R, const _cl_ring_element& x)
+static bool N_zerop (cl_heap_ring* R, const _cl_ring_element& x)
{
unused R;
// Here we return true only if x is the *exact* zero. Because we
return _cl_ring_element(R, expt(The(cl_N)(x),y));
}
-static cl_boolean cl_N_p (const cl_number& x)
+static bool cl_N_p (const cl_number& x)
{
- return (cl_boolean)
- (!x.pointer_p()
- || (x.pointer_type()->flags & cl_class_flags_subclass_complex) != 0
- );
+ return (!x.pointer_p()
+ || (x.pointer_type()->flags & cl_class_flags_subclass_complex) != 0);
}
static cl_ring_setops N_setops = {
if (rationalp(realpart(x)) && rationalp(imagpart(x)))
goto complex_rational;
}
- if (cl_false) {
+ if (false) {
complex_rational:
// x in Q(i)
var uintC k = power2p(n);
namespace cln {
-cl_boolean cl_inhibit_floating_point_underflow = cl_false;
+bool cl_inhibit_floating_point_underflow = false;
float_format_t default_float_format = float_format_ffloat;
extern cl_class cl_class_lfloat;
// Type test.
-inline cl_boolean longfloatp (const cl_F& x)
+inline bool longfloatp (const cl_F& x)
{
if (x.pointer_p())
if (x.pointer_type() == &cl_class_lfloat)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
// Macro: verteilt je nach Float-Typ eines Floats x auf 4 Statements.
#endif
{CL_ALLOCA_STACK;
var DS wurzel;
- var cl_boolean exactp;
+ var bool exactp;
UDS_sqrt(arrayMSDptr(mant,128/intDsize),128/intDsize,arrayLSDptr(mant,128/intDsize), &wurzel, exactp=);
// wurzel = isqrt(2^74_75 * mant), eine 64-Bit-Zahl.
mantx = get_64_Dptr(wurzel.MSDptr);
#endif
{CL_ALLOCA_STACK;
var DS wurzel;
- var cl_boolean exactp;
+ var bool exactp;
UDS_sqrt(arrayMSDptr(mant,128/intDsize),128/intDsize,arrayLSDptr(mant,128/intDsize), &wurzel, exactp=);
// wurzel = isqrt(2^74_75 * mant), eine 64-Bit-Zahl.
{var uintD* ptr = wurzel.MSDptr;
// NDS zu |x|>0 bilden:
var const uintD* MSDptr;
var uintC len;
- I_to_NDS_nocopy(abs_x, MSDptr=,len=,,cl_false,);
+ I_to_NDS_nocopy(abs_x, MSDptr=,len=,,false,);
// MSDptr/len/LSDptr ist die NDS zu x, len>0.
// Führende Digits holen: Brauche DF_mant_len+1 Bits, dazu intDsize
// Bits (die NDS kann mit bis zu intDsize Nullbits anfangen).
// NDS zu |x|>0 bilden:
var const uintD* MSDptr;
var uintC len;
- I_to_NDS_nocopy(abs_x, MSDptr=,len=,,cl_false,);
+ I_to_NDS_nocopy(abs_x, MSDptr=,len=,,false,);
// MSDptr/len/LSDptr ist die NDS zu x, len>0.
// Führende Digits holen: Brauche DF_mant_len+1 Bits, dazu intDsize
// Bits (die NDS kann mit bis zu intDsize Nullbits anfangen).
namespace cln {
MAYBE_INLINE
-cl_boolean minusp (const cl_DF& x)
+bool minusp (const cl_DF& x)
{
#if (cl_word_size==64)
- return (cl_boolean) ((sint64)TheDfloat(x)->dfloat_value_semhi < 0);
+ return (sint64)TheDfloat(x)->dfloat_value_semhi < 0;
#else
- return (cl_boolean) ((sint32)TheDfloat(x)->dfloat_value_semhi < 0);
+ return (sint32)TheDfloat(x)->dfloat_value_semhi < 0;
#endif
}
namespace cln {
MAYBE_INLINE2
-cl_boolean plusp (const cl_DF& x)
+bool plusp (const cl_DF& x)
{
if (minusp(x))
- return cl_false; // x<0 -> nein
+ return false; // x<0 -> nein
elif (zerop(x))
- return cl_false; // x=0 -> nein
+ return false; // x=0 -> nein
else
- return cl_true; // sonst ist x>0.
+ return true; // sonst ist x>0.
}
} // namespace cln
namespace cln {
MAYBE_INLINE
-cl_boolean zerop (const cl_DF& x)
+bool zerop (const cl_DF& x)
{
#if 0
- return (cl_boolean) (DF_uexp(TheDfloat(x)->dfloat_value_semhi) == 0);
+ return DF_uexp(TheDfloat(x)->dfloat_value_semhi) == 0;
#else // this is faster
- return (cl_boolean) (TheDfloat(x)->dfloat_value_semhi == 0);
+ return TheDfloat(x)->dfloat_value_semhi == 0;
#endif
}
syntax_dfloat,
lsyntax_all,
10,
- { float_format_dfloat, float_format_lfloat_min, cl_false }
+ { float_format_dfloat, float_format_lfloat_min, false }
};
cl_DF::cl_DF (const char * string)
namespace cln {
-inline cl_boolean cl_DF_p (const cl_number& x)
+inline bool cl_DF_p (const cl_number& x)
{
if (x.pointer_p())
if (x.heappointer->type == &cl_class_dfloat)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_DF& cl_DF_As (const cl_number& x, const char * filename, int line)
namespace cln {
-cl_boolean minusp (const cl_F& x)
+bool minusp (const cl_F& x)
{
floatcase(x
, return minusp(x);
namespace cln {
-cl_boolean plusp (const cl_F& x)
+bool plusp (const cl_F& x)
{
floatcase(x
, return plusp(x);
namespace cln {
-cl_boolean zerop (const cl_F& x)
+bool zerop (const cl_F& x)
{
floatcase(x
, return zerop(x);
// NDS zu |x|>0 bilden:
var const uintD* MSDptr;
var uintC len;
- I_to_NDS_nocopy(abs_x, MSDptr=,len=,,cl_false,);
+ I_to_NDS_nocopy(abs_x, MSDptr=,len=,,false,);
// MSDptr/len/LSDptr ist die NDS zu x, len>0.
// Führende Digits holen: Brauche FF_mant_len+1 Bits, dazu intDsize
// Bits (die NDS kann mit bis zu intDsize Nullbits anfangen).
// NDS zu |x|>0 bilden:
var const uintD* MSDptr;
var uintC len;
- I_to_NDS_nocopy(abs_x, MSDptr=,len=,,cl_false,);
+ I_to_NDS_nocopy(abs_x, MSDptr=,len=,,false,);
// MSDptr/len/LSDptr ist die NDS zu x, len>0.
// Führende Digits holen: Brauche FF_mant_len+1 Bits, dazu intDsize
// Bits (die NDS kann mit bis zu intDsize Nullbits anfangen).
namespace cln {
MAYBE_INLINE
-cl_boolean minusp (const cl_FF& x)
+bool minusp (const cl_FF& x)
{
- return (cl_boolean) ((sint32)cl_ffloat_value(x) < 0);
+ return (sint32)cl_ffloat_value(x) < 0;
}
} // namespace cln
namespace cln {
MAYBE_INLINE2
-cl_boolean plusp (const cl_FF& x)
+bool plusp (const cl_FF& x)
{
if (minusp(x))
- return cl_false; // x<0 -> nein
+ return false; // x<0 -> nein
elif (zerop(x))
- return cl_false; // x=0 -> nein
+ return false; // x=0 -> nein
else
- return cl_true; // sonst ist x>0.
+ return true; // sonst ist x>0.
}
} // namespace cln
namespace cln {
MAYBE_INLINE
-cl_boolean zerop (const cl_FF& x)
+bool zerop (const cl_FF& x)
{
- return (cl_boolean) (cl_ffloat_value(x) == 0);
+ return cl_ffloat_value(x) == 0;
}
} // namespace cln
syntax_ffloat,
lsyntax_all,
10,
- { float_format_ffloat, float_format_lfloat_min, cl_false }
+ { float_format_ffloat, float_format_lfloat_min, false }
};
cl_FF::cl_FF (const char * string)
namespace cln {
-inline cl_boolean cl_FF_p (const cl_number& x)
+inline bool cl_FF_p (const cl_number& x)
{
#if defined(CL_WIDE_POINTERS)
if (!x.pointer_p())
if (cl_tag((x).word) == cl_FF_tag)
- return cl_true;
+ return true;
#else
if (x.pointer_p())
if (x.heappointer->type == &cl_class_ffloat)
- return cl_true;
+ return true;
#endif
- return cl_false;
+ return false;
}
const cl_FF& cl_FF_As (const cl_number& x, const char * filename, int line)
syntax_float,
lsyntax_all,
10,
- { float_format_ffloat, float_format_lfloat_min, cl_true }
+ { float_format_ffloat, float_format_lfloat_min, true }
};
cl_F::cl_F (const char * string)
}
var const char * ptr_after_sign = ptr;
var const char * ptr_after_intpart = skip_digits(ptr_after_sign,string_limit,float_base);
- var cl_boolean have_dot = cl_false;
+ var bool have_dot = false;
var const char * ptr_before_fracpart = ptr_after_intpart;
var const char * ptr_after_fracpart = ptr_after_intpart;
ptr = ptr_after_intpart;
if (ptr != string_limit)
if (*ptr == '.') {
- have_dot = cl_true;
+ have_dot = true;
ptr_before_fracpart = ptr+1;
ptr_after_fracpart = skip_digits(ptr_before_fracpart,string_limit,float_base);
}
ptr = ptr_after_fracpart;
var char exponent_marker;
- var cl_boolean have_exponent;
+ var bool have_exponent;
var const char * ptr_in_exponent = ptr;
var const char * ptr_after_exponent = ptr;
if ((ptr == string_limit) || !(((*ptr >= '0') && (*ptr <= '9')) || ((*ptr >= 'A') && (*ptr <= 'Z') && (*ptr != 'I')) || ((*ptr >= 'a') && (*ptr <= 'z') && (*ptr != 'i')) || (*ptr == '.') || (*ptr == '/'))) {
// No exponent.
- have_exponent = cl_false;
+ have_exponent = false;
// Must have at least one fractional part digit.
if (ptr_after_fracpart == ptr_before_fracpart) goto not_float_syntax;
exponent_marker = 'E';
} else {
- have_exponent = cl_true;
+ have_exponent = true;
// Must have at least one digit.
if (ptr_after_sign == ptr_after_intpart)
if (ptr_after_fracpart == ptr_before_fracpart)
char* end_pointer (void) { return buffer+index; }
};
-static cl_boolean number_char_p (char c)
+static bool number_char_p (char c)
{
if ((c >= '0') && (c <= '9'))
- return cl_true;
+ return true;
if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
- return cl_true;
+ return true;
switch (c) {
case '+': case '-': case '.': case '_': case '/':
- return cl_true;
+ return true;
default:
- return cl_false;
+ return false;
}
}
}
#endif
var DS w;
- var cl_boolean exactp;
+ var bool exactp;
UDS_sqrt(r_MSDptr,r_len,r_LSDptr, &w, exactp=);
// w ist die Ganzzahl-Wurzel, eine n+1-Digit-Zahl.
copy_loop_msp(w.MSDptr,y_mantMSDptr,len); // NUDS nach y kopieren
var const uintD* y_MSDptr;
var uintC y_len;
var const uintD* y_LSDptr;
- I_to_NDS_nocopy(abs_y, y_MSDptr=,y_len=,y_LSDptr=,cl_false,); // NDS zu y bilden, y_len>0
+ I_to_NDS_nocopy(abs_y, y_MSDptr=,y_len=,y_LSDptr=,false,); // NDS zu y bilden, y_len>0
// y nicht zu einer NUDS normalisieren! (Damit ein Bit Spielraum ist.)
// Zähler bilden: x * 2^(intDsize*y_len)
var uintD* z_MSDptr;
var const uintD* y_MSDptr;
var uintC y_len;
var const uintD* y_LSDptr;
- I_to_NDS_nocopy(abs_y, y_MSDptr=,y_len=,y_LSDptr=,cl_false,); // NDS zu y bilden, y_len>0
+ I_to_NDS_nocopy(abs_y, y_MSDptr=,y_len=,y_LSDptr=,false,); // NDS zu y bilden, y_len>0
if (mspref(y_MSDptr,0)==0) y_len--; // NUDS zu y bilden, y_len>0
// Multiplizieren.
var uintD* prodMSDptr;
var uintD* y_mantMSDptr = arrayMSDptr(TheLfloat(y)->data,len);
var const uintD* x_MSDptr;
var uintC x_len;
- I_to_NDS_nocopy(abs_x, x_MSDptr=,x_len=,,cl_false,); // NDS zu x bilden, x_len>0
+ I_to_NDS_nocopy(abs_x, x_MSDptr=,x_len=,,false,); // NDS zu x bilden, x_len>0
// x_MSDptr/x_len/.. um (exp mod 16) Bits nach rechts shiften und in
// y einfüllen (genauer: nur maximal len Digits davon):
{var uintL shiftcount = exp % intDsize;
namespace cln {
MAYBE_INLINE
-cl_boolean minusp (const cl_LF& x)
+bool minusp (const cl_LF& x)
{
- return (cl_boolean) (- TheLfloat(x)->sign);
+ return -TheLfloat(x)->sign;
}
} // namespace cln
namespace cln {
MAYBE_INLINE2
-cl_boolean plusp (const cl_LF& x)
+bool plusp (const cl_LF& x)
{
if (minusp(x))
- return cl_false; // x<0 -> nein
+ return false; // x<0 -> nein
elif (zerop(x))
- return cl_false; // x=0 -> nein
+ return false; // x=0 -> nein
else
- return cl_true; // sonst ist x>0.
+ return true; // sonst ist x>0.
}
} // namespace cln
namespace cln {
MAYBE_INLINE
-cl_boolean zerop (const cl_LF& x)
+bool zerop (const cl_LF& x)
{
- return (cl_boolean) (TheLfloat(x)->expo == 0);
+ return TheLfloat(x)->expo == 0;
}
} // namespace cln
syntax_lfloat,
lsyntax_all,
10,
- { float_format_lfloat_min, float_format_lfloat_min, cl_false }
+ { float_format_lfloat_min, float_format_lfloat_min, false }
};
cl_LF::cl_LF (const char * string)
namespace cln {
-inline cl_boolean cl_LF_p (const cl_number& x)
+inline bool cl_LF_p (const cl_number& x)
{
if (x.pointer_p())
if (x.heappointer->type == &cl_class_lfloat)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_LF& cl_LF_As (const cl_number& x, const char * filename, int line)
namespace cln {
-inline cl_boolean cl_F_p (const cl_number& x)
+inline bool cl_F_p (const cl_number& x)
{
if (!x.pointer_p())
switch (cl_tag((x).word)) {
#if defined(CL_WIDE_POINTERS)
case cl_FF_tag:
#endif
- return cl_true;
+ return true;
}
else
if (x.heappointer->type->flags & cl_class_flags_subclass_float)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_F& cl_F_As (const cl_number& x, const char * filename, int line)
// wird er gewählt, die anderen vergessen.
// 3. Sonst wird unter allen noch möglichen Werten der zu x
// nächstgelegene gewählt.
- var cl_boolean d_shift = cl_false; // Flag, ob im 1. Schritt d incrementiert wurde
+ var bool d_shift = false; // Flag, ob im 1. Schritt d incrementiert wurde
var cl_I a; // das ausgewählte a
// 1.
{
var cl_I b1 = ceiling1(a1,10);
var cl_I b2 = floor1(a2,10);
if (b1 <= b2) // noch eine durch 10 teilbare Zahl a ?
- { a1 = b1; a2 = b2; d = d+1; d_shift = cl_true; }
+ { a1 = b1; a2 = b2; d = d+1; d_shift = true; }
else
goto keine_10_mehr;
}
// NDS zu |x|>0 bilden:
var const uintD* MSDptr;
var uintC len;
- I_to_NDS_nocopy(abs_x, MSDptr=,len=,,cl_false,);
+ I_to_NDS_nocopy(abs_x, MSDptr=,len=,,false,);
// MSDptr/len/LSDptr ist die NDS zu x, len>0.
// Führende Digits holen: Brauche SF_mant_len+1 Bits, dazu intDsize
// Bits (die NDS kann mit bis zu intDsize Nullbits anfangen).
namespace cln {
MAYBE_INLINE
-cl_boolean minusp (const cl_SF& x)
+bool minusp (const cl_SF& x)
{
- return (cl_boolean) ((x.word & bit(SF_sign_shift)) != 0);
+ return (x.word & bit(SF_sign_shift)) != 0;
}
} // namespace cln
namespace cln {
MAYBE_INLINE2
-cl_boolean plusp (const cl_SF& x)
+bool plusp (const cl_SF& x)
{
if (minusp(x))
- return cl_false; // x<0 -> nein
+ return false; // x<0 -> nein
elif (zerop(x))
- return cl_false; // x=0 -> nein
+ return false; // x=0 -> nein
else
- return cl_true; // sonst ist x>0.
+ return true; // sonst ist x>0.
}
} // namespace cln
namespace cln {
MAYBE_INLINE
-cl_boolean zerop (const cl_SF& x)
+bool zerop (const cl_SF& x)
{
- return (cl_boolean) (x.word == make_SF_word(0,0,0));
+ return x.word == make_SF_word(0,0,0);
}
} // namespace cln
syntax_sfloat,
lsyntax_all,
10,
- { float_format_sfloat, float_format_lfloat_min, cl_false }
+ { float_format_sfloat, float_format_lfloat_min, false }
};
cl_SF::cl_SF (const char * string)
namespace cln {
-inline cl_boolean cl_SF_p (const cl_number& x)
+inline bool cl_SF_p (const cl_number& x)
{
if (!x.pointer_p())
if (cl_tag((x).word) == cl_SF_tag)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_SF& cl_SF_As (const cl_number& x, const char * filename, int line)
var uintE me = cl_I_to_UE(- y_.exponent);
var cl_I p;
var uintE lq;
- var cl_boolean last_step = cl_false;
+ var bool last_step = false;
if (lm >= me) { // |y| >= 1/2 ?
p = y_.sign; // 1 or -1
lq = 1;
// after the next big multiplication. This saves one
// big multiplication at the end.
if (2*n >= lm)
- last_step = cl_true;
+ last_step = true;
}
z = z + scale_float(cl_I_to_LF(p,len),-(sintE)lq);
if (last_step)
// (b) 311 317 305 312 295 291 286 293 291 284 295 284 293 287 288 305
// (a): N=300, time in 0.01 sec. (b): N=1000, time in 0.1 sec.
// Values 2.5 <= c <= 3.2 seem best. Let's choose c = 2.875.
- var cl_boolean first_factor = cl_true;
+ var bool first_factor = true;
var cl_LF product;
var uintE b1;
var uintE b2;
var cl_LF factor = cl_exp_aux(pk,lqk,len);
if (first_factor) {
product = factor;
- first_factor = cl_false;
+ first_factor = false;
} else
product = product * factor;
}
var uintE me = cl_I_to_UE(- x1_.exponent);
var cl_I p;
var uintE lq;
- var cl_boolean last_step = cl_false;
+ var bool last_step = false;
if (lm >= me) { // |x'| >= 1/2 ?
p = x1_.sign; // 1 or -1
lq = 1;
// after the next big multiplication. This saves one
// big multiplication at the end.
if (2*n >= lm)
- last_step = cl_true;
+ last_step = true;
}
y = y + scale_float(cl_I_to_LF(p,len),-(sintE)lq);
if (last_step)
var uintE lq = cl_I_to_UE(- x_.exponent);
var const cl_I& p = x_.mantissa;
// Compute sinh(p/2^lq) and cosh(p/2^lq) by splitting into pieces.
- var cl_boolean first_factor = cl_true;
+ var bool first_factor = true;
var cl_LF_cosh_sinh_t product;
var uintE b1;
var uintE b2;
var cl_LF_cosh_sinh_t factor = cl_coshsinh_aux(pk,lqk,len);
if (first_factor) {
product = factor;
- first_factor = cl_false;
+ first_factor = false;
} else
product = product * factor;
}
var uintE lq = cl_I_to_UE(- x_.exponent);
var const cl_I& p = x_.mantissa;
// Compute sin(p/2^lq) and cos(p/2^lq) by splitting into pieces.
- var cl_boolean first_factor = cl_true;
+ var bool first_factor = true;
var cl_LF_cos_sin_t product;
var uintE b1;
var uintE b2;
var cl_LF_cos_sin_t factor = cl_cossin_aux(pk,lqk,len);
if (first_factor) {
product = factor;
- first_factor = cl_false;
+ first_factor = false;
} else
product = product * factor;
}
namespace cln {
-void eval_pqcd_series_aux (uintC N, cl_pqcd_series_term* args, cl_pqcd_series_result& Z, cl_boolean rightmost)
+void eval_pqcd_series_aux (uintC N, cl_pqcd_series_term* args, cl_pqcd_series_result& Z, bool rightmost)
{
// N = N2-N1
switch (N) {
var uintC Nm = N/2; // midpoint
// Compute left part.
var cl_pqcd_series_result L;
- eval_pqcd_series_aux(Nm,args+0,L,cl_false);
+ eval_pqcd_series_aux(Nm,args+0,L,false);
// Compute right part.
var cl_pqcd_series_result R;
eval_pqcd_series_aux(N-Nm,args+Nm,R,rightmost);
namespace cln {
-void eval_pqd_series_aux (uintC N, cl_pqd_series_term* args, cl_pqd_series_result& Z, cl_boolean rightmost)
+void eval_pqd_series_aux (uintC N, cl_pqd_series_term* args, cl_pqd_series_result& Z, bool rightmost)
{
// N = N2-N1
switch (N) {
var uintC Nm = N/2; // midpoint
// Compute left part.
var cl_pqd_series_result L;
- eval_pqd_series_aux(Nm,args+0,L,cl_false);
+ eval_pqd_series_aux(Nm,args+0,L,false);
// Compute right part.
var cl_pqd_series_result R;
eval_pqd_series_aux(N-Nm,args+Nm,R,rightmost);
cl_I D;
cl_I V;
};
-extern void eval_pqcd_series_aux (uintC N, cl_pqcd_series_term* args, cl_pqcd_series_result& Z, cl_boolean rightmost = cl_true);
+extern void eval_pqcd_series_aux (uintC N, cl_pqcd_series_term* args, cl_pqcd_series_result& Z, bool rightmost = true);
// Ditto, but returns U/S.
extern const cl_LF eval_pqcd_series (uintC N, cl_pqcd_series_term* args, uintC len);
cl_I D;
cl_I V;
};
-extern void eval_pqd_series_aux (uintC N, cl_pqd_series_term* args, cl_pqd_series_result& Z, cl_boolean rightmost = cl_true);
+extern void eval_pqd_series_aux (uintC N, cl_pqd_series_term* args, cl_pqd_series_result& Z, bool rightmost = true);
// Ditto, but returns U/S.
extern const cl_LF eval_pqd_series (uintC N, cl_pqd_series_term* args, uintC len);
// Falls n >= integer_length(x): NEIN. (Da y>=2, müßte x>=2^n gelten.)
// Hier also n>0 klein...
-cl_boolean rootp (const cl_I& x, uintL n, cl_I* w)
+bool rootp (const cl_I& x, uintL n, cl_I* w)
{
if (eq(x,0) || eq(x,1)) // x=0 oder x=1 ?
- { *w = x; return cl_true; } // ja -> x als Ergebnis
+ { *w = x; return true; } // ja -> x als Ergebnis
if (n >= integer_length(x))
- { return cl_false; }
+ { return false; }
return cl_rootp_aux(x,n,w);
}
// Falls n >= integer_length(x): NEIN. (Da y>=2, müßte x>=2^n gelten.)
// Hier also n>0 klein...
-cl_boolean rootp (const cl_I& x, const cl_I& n, cl_I* w)
+bool rootp (const cl_I& x, const cl_I& n, cl_I* w)
{
if (eq(x,0) || eq(x,1)) // x=0 oder x=1 ?
- { *w = x; return cl_true; } // ja -> x als Ergebnis
+ { *w = x; return true; } // ja -> x als Ergebnis
if (n >= (cl_I)(unsigned long)integer_length(x))
- { return cl_false; }
+ { return false; }
// Nun ist n < (integer-length x). Also paßt n in ein uintC.
return cl_rootp_aux(x,cl_I_to_ulong(n),w);
}
// > n: ein Integer >0
// > Annahme: x > 1 und n < (integer-length x).
// < w: Integer (expt x (/ n)) falls x eine n-te Potenz
-// < ergebnis: cl_true ........................, cl_false sonst
+// < ergebnis: true ........................, false sonst
-cl_boolean cl_rootp_aux (cl_I x, uintL n, cl_I* w)
+bool cl_rootp_aux (cl_I x, uintL n, cl_I* w)
{
// Methode:
while ((n % 2) == 0) // n gerade?
{ if (!sqrtp(x,&x)) // Quadratwurzel ziehen versuchen
- { return cl_false; } // nicht ganzzahlig -> fertig
+ { return false; } // nicht ganzzahlig -> fertig
n = n >> 1; // n := (/ n 2)
}
// Nun ist n ungerade.
- if (n==1) { *w = x; return cl_true; } // n=1 -> x als Ergebnis
+ if (n==1) { *w = x; return true; } // n=1 -> x als Ergebnis
var uintC oq = 0; // Shift von y am Schluß
{var uintC o = ord2(x);
if (!(o==0))
{var uintL o_r; divu_3232_3232(o,n, oq=,o_r=); // o_r = o mod n
- if (!(o_r==0)) { return cl_false; } // o nicht durch n teilbar -> fertig
+ if (!(o_r==0)) { return false; } // o nicht durch n teilbar -> fertig
// oq = o/n.
// dividiere x durch 2^o:
x = ash(x,-(sintC)o);
n_UDS_ok: ; // n_MSDptr/n_len/n_LSDptr ist NUDS zu n.
}
#endif
- I_to_NDS_nocopy(x, ,x_len=,x_LSDptr=,cl_false,); // UDS zu x bilden, x_len>0
+ I_to_NDS_nocopy(x, ,x_len=,x_LSDptr=,false,); // UDS zu x bilden, x_len>0
var uintD x_lsd = lspref(x_LSDptr,0); // letztes Digit von x
var uintD y_lsd; // n-te Wurzel von x_lsd mod 2^intDsize
y_lsd = 1; // Wurzel mod 2^1
// mit x vergleichen:
if (!(x == c))
// Die ganze Rechnung war umsonst.
- { return cl_false; }
+ { return false; }
}
// y ist tatsächlich n-te Wurzel von x.
// Noch mit 2^oq multiplizieren:
{ *w = y; }
else
{ *w = ash(y,oq); }
- return cl_true;
+ return true;
}
}
namespace cln {
-cl_boolean isqrt (const cl_I& x, cl_I* w)
+bool isqrt (const cl_I& x, cl_I* w)
{
if (minusp(x)) {
std::ostringstream buf;
var const uintD* x_MSDptr;
var uintC x_len;
var const uintD* x_LSDptr;
- I_to_NDS_nocopy(x, x_MSDptr=,x_len=,x_LSDptr=,cl_true,); // Digit sequence >=0 zu x
+ I_to_NDS_nocopy(x, x_MSDptr=,x_len=,x_LSDptr=,true,); // Digit sequence >=0 zu x
var DS y;
- var cl_boolean squarep;
+ var bool squarep;
UDS_sqrt(x_MSDptr,x_len,x_LSDptr, &y, squarep=); // Wurzel ziehen
*w = NUDS_to_I(y.MSDptr,y.len); // als Integer
return squarep;
namespace cln {
-cl_boolean sqrtp (const cl_I& x, cl_I* w)
+bool sqrtp (const cl_I& x, cl_I* w)
{
// Methode:
// [Henri Cohen: A course in computational algebraic number theory, 2nd prnt.,
var uintC x_len;
var const uintD* x_LSDptr;
I_to_NDS_nocopy(x, x_MSDptr=,x_len=,x_LSDptr=, // Digit sequence >=0 zu x
- cl_true, { *w = 0; return cl_true; } // 0 is a square
+ true, { *w = 0; return true; } // 0 is a square
);
// Check mod 64.
{ var uintD lsd = lspref(x_LSDptr,0);
if (!squares_mod_64[lsd & 63])
- { return cl_false; } // not a square mod 64 -> not a square
+ { return false; } // not a square mod 64 -> not a square
}
// Check mod 63.
{ var cl_I_div_t div63 = cl_divide(x,L_to_FN(63));
if (!squares_mod_63[FN_to_UV(div63.remainder)])
- { return cl_false; } // not a square mod 63 -> not a square
+ { return false; } // not a square mod 63 -> not a square
}
// Check mod 65.
{ var cl_I_div_t div65 = cl_divide(x,L_to_FN(65));
if (!squares_mod_65[FN_to_UV(div65.remainder)])
- { return cl_false; } // not a square mod 65 -> not a square
+ { return false; } // not a square mod 65 -> not a square
}
// Check mod 11.
{ var cl_I_div_t div11 = cl_divide(x,L_to_FN(11));
if (!squares_mod_11[FN_to_UV(div11.remainder)])
- { return cl_false; } // not a square mod 11 -> not a square
+ { return false; } // not a square mod 11 -> not a square
}
// Check with full precision.
{ var DS y;
- var cl_boolean squarep;
+ var bool squarep;
UDS_sqrt(x_MSDptr,x_len,x_LSDptr, &y, squarep=); // Wurzel ziehen
if (squarep)
{ *w = NUDS_to_I(y.MSDptr,y.len); } // als Integer
var uintD* LSDptr;
var uintC len;
var const uintD* x_LSDptr;
- I_to_NDS_nocopy(x, ,len=,x_LSDptr=,cl_false,); // DS zu x bilden.
+ I_to_NDS_nocopy(x, ,len=,x_LSDptr=,false,); // DS zu x bilden.
if (k >= (uintC)(~len)) // kann len+k+1 Überlauf geben?
{ throw ash_exception(y); } // ja -> Fehler
num_stack_alloc_1(len+k,,LSDptr=);
var uintD* LSDptr;
var uintC len;
var const uintD* x_LSDptr;
- I_to_NDS_nocopy(x, ,len=,x_LSDptr=,cl_false,); // DS zu x bilden.
+ I_to_NDS_nocopy(x, ,len=,x_LSDptr=,false,); // DS zu x bilden.
if (k >= (uintC)(~len)) // kann len+k+1 Überlauf geben?
{ throw ash_exception(y); } // ja -> Fehler
num_stack_alloc_1(len+k,,LSDptr=);
// Teste, ob eines der Bits p,...,q-1 der Zahl x /=0 ist,
// wobei 0 <= p <= q <= l = (integer-length x).
-// Ergebnis (wie bei LDB-TEST) cl_false wenn nein, cl_true wenn ja.
-extern cl_boolean ldb_extract_test (const cl_I& x, uintC p, uintC q);
+// Ergebnis (wie bei LDB-TEST) false wenn nein, true wenn ja.
+extern bool ldb_extract_test (const cl_I& x, uintC p, uintC q);
// Extrahiere die Bits p,...,q-1 der Zahl x,
// wobei 0 <= p <= q <= l = (integer-length x).
namespace cln {
-cl_boolean ldb_test (const cl_I& n, const cl_byte& b)
+bool ldb_test (const cl_I& n, const cl_byte& b)
{
// Methode:
// (ldb-test (byte s p) n)
// extrahiere die Bits p,...,p+s-1 von n und teste sie.
var uintC s = b.size;
var uintC p = b.position;
- if (s==0) return cl_false;
+ if (s==0) return false;
var uintC l = integer_length(n); // l = (integer-length n)
if (l<=p)
// l<=p
if (!minusp(n))
- return cl_false; // n>=0
+ return false; // n>=0
else
- return cl_true; // n<0
+ return true; // n<0
else
// l>p
{ var uintC ps = p+s;
if (ps>l) // p+s>l ?
- return cl_true;
+ return true;
// Bits p,...,q-1 mit q = min(p+s,l) = p+s extrahieren und testen:
return ldb_extract_test(n,p,ps);
}
var const uintD* MSDptr;
var uintC len;
var const uintD* LSDptr;
- I_to_NDS_nocopy(x, MSDptr=,len=,LSDptr=,cl_true, { return 0; } ); // NDS zu x bilden
+ I_to_NDS_nocopy(x, MSDptr=,len=,LSDptr=,true, { return 0; } ); // NDS zu x bilden
// MSDptr erhöhen und len erniedrigen, so daß len = ceiling(q/intDsize) wird:
{ var uintC qD = ceiling(q,intDsize); // ceiling(q/intDsize)
// wegen q<=l ist qD = ceiling(q/intDsize) <= ceiling((l+1)/intDsize) = len, also
namespace cln {
-cl_boolean ldb_extract_test (const cl_I& x, uintC p, uintC q)
+bool ldb_extract_test (const cl_I& x, uintC p, uintC q)
{ var const uintD* MSDptr;
var uintC len;
var const uintD* LSDptr;
- I_to_NDS_nocopy(x, MSDptr=,len=,LSDptr=,cl_true, { return cl_false; } ); // NDS zu x bilden
+ I_to_NDS_nocopy(x, MSDptr=,len=,LSDptr=,true, { return false; } ); // NDS zu x bilden
// MSDptr erhöhen und len erniedrigen, so daß len = ceiling(q/intDsize) wird:
{ var uintC qD = ceiling(q,intDsize); // ceiling(q/intDsize)
// wegen q<=l ist qD = ceiling(q/intDsize) <= ceiling((l+1)/intDsize) = len, also
len -= pD;
}
// Jetzt enthält MSDptr/len/LSDptr genau die maßgeblichen Digits.
- if (len==0) return cl_false; // len=0 -> keine Bits abzutesten
+ if (len==0) return false; // len=0 -> keine Bits abzutesten
q = ((q-1)%intDsize); // q := intDsize - (intDsize*ceiling(q/intDsize) - q) - 1
p = p%intDsize; // p := p - intDsize*floor(p/intDsize)
// Jetzt ist 0 <= q < intDsize, 0 <= p < intDsize.
// 1 Digit maßgeblich, wird von beiden Seiten angeschnitten:
// Ein AND 2^(q+1)-2^p erreicht dies.
if (!(((uintD)(bitm(q+1)-bit(p)) & mspref(MSDptr,0)) == 0))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
// mindestens 2 Digits. Teste erst die Randdigits, dann die inneren:
if (!(((msprefnext(MSDptr) & (uintD)(bitm(q+1)-1)) == 0) &&
((lsprefnext(LSDptr) & (uintD)(minus_bit(p))) == 0)
) )
- return cl_true;
+ return true;
len--; // die beiden Randdigits sind jetzt abgezogen.
- if (DS_test_loop(MSDptr,len,LSDptr)) { return cl_true; } else { return cl_false; }
+ if (DS_test_loop(MSDptr,len,LSDptr)) { return true; } else { return false; }
}
} // namespace cln
namespace cln {
-cl_boolean logbitp (uintC x, const cl_I& y)
+bool logbitp (uintC x, const cl_I& y)
{
// Methode:
// Falls x>=intDsize*Länge(y), teste Vorzeichen von y.
var const uintD* yMSDptr;
var uintC ylen;
var const uintD* yLSDptr;
- I_to_NDS_nocopy(y, yMSDptr=,ylen=,yLSDptr=,cl_true, { return cl_false; } ); // DS zu y
+ I_to_NDS_nocopy(y, yMSDptr=,ylen=,yLSDptr=,true, { return false; } ); // DS zu y
if (x < intDsize*ylen)
// x ist >=0, < intDsize*ylen
{ if (lspref(yLSDptr,floor(x,intDsize)) & bit(x%intDsize))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}
// Vorzeichen von y testen
if (/* (ylen > 0) && */ ((sintD)mspref(yMSDptr,0) < 0))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}
} // namespace cln
namespace cln {
-cl_boolean logbitp (const cl_I& x, const cl_I& y)
+bool logbitp (const cl_I& x, const cl_I& y)
{
// Methode:
// Falls x<0, Error.
{ var uintV x_ = FN_to_V(x);
var uintC ylen;
var const uintD* yLSDptr;
- I_to_NDS_nocopy(y, ,ylen=,yLSDptr=,cl_true, { return cl_false; } ); // DS zu y
+ I_to_NDS_nocopy(y, ,ylen=,yLSDptr=,true, { return false; } ); // DS zu y
if (x_ < intDsize*ylen)
// x ist ein Fixnum >=0, < intDsize*ylen
{ if (lspref(yLSDptr,floor(x_,intDsize)) & bit(x_%intDsize))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
} }
// Vorzeichen von y testen
if (minusp(y))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}
else
// x<0
namespace cln {
-cl_boolean logtest (const cl_I& x, const cl_I& y)
+bool logtest (const cl_I& x, const cl_I& y)
{
// Methode:
// Fixnums separat behandeln.
if (fixnump(y))
// beides Fixnums
{ if ((x.word & y.word & cl_combine(0,~(cl_uint)0))==0)
- return cl_false;
+ return false;
else
- return cl_true;
+ return true;
}
else
// x Fixnum, y Bignum, also ist x echt kürzer
- { if (FN_V_minusp(x,FN_to_V(x))) return cl_true; // x<0 -> ja.
+ { if (FN_V_minusp(x,FN_to_V(x))) return true; // x<0 -> ja.
// x>=0. Kombiniere x mit den pFN_maxlength letzten Digits von y.
{var const uintD* yLSDptr;
var uintV x_ = FN_to_V(x);
BN_to_NDS_nocopy(y, ,,yLSDptr=);
#if (pFN_maxlength > 1)
doconsttimes(pFN_maxlength-1,
- if (lsprefnext(yLSDptr) & (uintD)x_) return cl_true;
+ if (lsprefnext(yLSDptr) & (uintD)x_) return true;
x_ = x_ >> intDsize;
);
#endif
- if (lsprefnext(yLSDptr) & (uintD)x_) return cl_true;
- return cl_false;
+ if (lsprefnext(yLSDptr) & (uintD)x_) return true;
+ return false;
}}
else
if (fixnump(y))
// x Bignum, y Fixnum, analog wie oben, nur x und y vertauscht
- { if (FN_V_minusp(y,FN_to_V(y))) return cl_true; // y<0 -> ja.
+ { if (FN_V_minusp(y,FN_to_V(y))) return true; // y<0 -> ja.
// y>=0. Kombiniere y mit den pFN_maxlength letzten Digits von x.
{var const uintD* xLSDptr;
var uintV y_ = FN_to_V(y);
BN_to_NDS_nocopy(x, ,,xLSDptr=);
#if (pFN_maxlength > 1)
doconsttimes(pFN_maxlength-1,
- if (lsprefnext(xLSDptr) & (uintD)y_) return cl_true;
+ if (lsprefnext(xLSDptr) & (uintD)y_) return true;
y_ = y_ >> intDsize;
);
#endif
- if (lsprefnext(xLSDptr) & (uintD)y_) return cl_true;
- return cl_false;
+ if (lsprefnext(xLSDptr) & (uintD)y_) return true;
+ return false;
}}
else
// x,y Bignums
{ if (xlen<ylen)
{ // x ist die echt kürzere DS.
if ((sintD)mspref(xMSDptr,0)<0) // der echt kürzere ist negativ?
- return cl_true;
+ return true;
// Der echt kürzere ist positiv.
yMSDptr = yMSDptr mspop (ylen-xlen);
}
else
{ // y ist die echt kürzere DS.
if ((sintD)mspref(yMSDptr,0)<0) // der echt kürzere ist negativ?
- return cl_true;
+ return true;
// Der echt kürzere ist positiv.
xMSDptr = xMSDptr mspop (xlen-ylen);
xlen = ylen;
var const uintD* MSDptr;
var uintC len;
var const uintD* LSDptr;
- I_to_NDS_nocopy(x, MSDptr=,len=,LSDptr=,cl_true, { return 0; } ); // NDS zu x bilden
+ I_to_NDS_nocopy(x, MSDptr=,len=,LSDptr=,true, { return 0; } ); // NDS zu x bilden
// MSDptr erhöhen und len erniedrigen, so daß len = ceiling(q/intDsize) wird:
{ var uintC qD = ceiling(q,intDsize); // ceiling(q/intDsize)
// wegen q<=l ist qD = ceiling(q/intDsize) <= ceiling((l+1)/intDsize) = len, also
// Integers in general.
// Type tests.
-inline cl_boolean integerp (const cl_I& x)
- { unused x; return cl_true; }
-inline cl_boolean fixnump (const cl_I& x)
- { return (cl_boolean) !x.pointer_p(); }
-inline cl_boolean bignump (const cl_I& x)
+inline bool integerp (const cl_I& x)
+ { unused x; return true; }
+inline bool fixnump (const cl_I& x)
+ { return !x.pointer_p(); }
+inline bool bignump (const cl_I& x)
{ return x.pointer_p(); }
// Sign test:
// (MINUSP x) == (< x 0)
-inline cl_boolean minusp (const cl_I& x)
+inline bool minusp (const cl_I& x)
{
if (fixnump(x))
// This assumes cl_value_shift + cl_value_len == cl_pointer_size.
- return (cl_boolean)((cl_sint) x.word < 0);
+ return (cl_sint) x.word < 0;
else
- return (cl_boolean)((sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0);
+ return (sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0;
}
// (ZEROP x) == (= x 0)
-inline cl_boolean zerop (const cl_I& x)
+inline bool zerop (const cl_I& x)
{
- return (cl_boolean)(x.word == cl_combine(cl_FN_tag,0));
+ return x.word == cl_combine(cl_FN_tag,0);
}
// (EQ x y) == (= x y), assuming y a fixnum
-inline cl_boolean eq (const cl_I& x, sint32 y)
+inline bool eq (const cl_I& x, sint32 y)
{
- return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
+ return x.word == cl_combine(cl_FN_tag,y);
}
var uintD CONCAT(FN_store_,__LINE__) [FN_maxlength]; \
{ var const cl_I& obj_from_I_to_NDS = (obj); \
if (fixnump(obj_from_I_to_NDS)) \
- { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, cl_true,); } \
+ { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, true,); } \
else \
{ BN_to_NDS(obj_from_I_to_NDS,MSDptr_zuweisung,len_zuweisung, LSDptr_zuweisung); } \
}
var uintD CONCAT(FN_store_,__LINE__) [1+FN_maxlength]; \
{ var const cl_I& obj_from_I_to_NDS = (obj); \
if (fixnump(obj_from_I_to_NDS)) \
- { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),1+FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, cl_true,); } \
+ { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),1+FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, true,); } \
else \
{ BN_to_NDS_1(obj_from_I_to_NDS,MSDptr_zuweisung,len_zuweisung, LSDptr_zuweisung); } \
}
// > n: ein Integer >0
// > Annahme: x > 1 und n < (integer-length x).
// < w: Integer (expt x (/ n)) falls x eine n-te Potenz
-// < ergebnis: cl_true ........................, cl_false sonst
- extern cl_boolean cl_rootp_aux (cl_I x, uintL n, cl_I* w);
+// < ergebnis: true ........................, false sonst
+ extern bool cl_rootp_aux (cl_I x, uintL n, cl_I* w);
// Hilfsfunktion zur Eingabe von Integers
class cl_FN : public cl_I {
public:
// Optimization of method pointer_p().
- cl_boolean pointer_p() const
- { return cl_false; }
+ bool pointer_p() const
+ { return false; }
};
-inline cl_boolean fixnump (const cl_FN& x)
- { unused x; return cl_true; }
-inline cl_boolean bignump (const cl_FN& x)
- { unused x; return cl_false; }
+inline bool fixnump (const cl_FN& x)
+ { unused x; return true; }
+inline bool bignump (const cl_FN& x)
+ { unused x; return false; }
-inline cl_boolean minusp (const cl_FN& x)
+inline bool minusp (const cl_FN& x)
{
// This assumes cl_value_shift + cl_value_len == cl_pointer_size.
- return (cl_boolean)((cl_sint) x.word < 0);
+ return (cl_sint) x.word < 0;
}
class cl_BN : public cl_I {
public:
// Optimization of method pointer_p().
- cl_boolean pointer_p() const
- { return cl_true; }
+ bool pointer_p() const
+ { return true; }
};
-inline cl_boolean fixnump (const cl_BN& x)
- { unused x; return cl_false; }
-inline cl_boolean bignump (const cl_BN& x)
- { unused x; return cl_true; }
+inline bool fixnump (const cl_BN& x)
+ { unused x; return false; }
+inline bool bignump (const cl_BN& x)
+ { unused x; return true; }
-inline cl_boolean minusp (const cl_BN& x)
+inline bool minusp (const cl_BN& x)
{
- return (cl_boolean)((sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0);
+ return (sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0;
}
-inline cl_boolean zerop (const cl_BN& x)
- { unused x; return cl_false; }
+inline bool zerop (const cl_BN& x)
+ { unused x; return false; }
} // namespace cln
var const uintD* MSDptr;
var uintC len;
var const uintD* LSDptr;
- I_to_NDS_nocopy(X, MSDptr=,len=,LSDptr=,cl_false,);
+ I_to_NDS_nocopy(X, MSDptr=,len=,LSDptr=,false,);
var int b = (base==2 ? 1 : base==4 ? 2 : base==8 ? 3 : base==16 ? 4 : /*base==32*/ 5);
var uintD carry = 0;
var int carrybits = 0;
// x in NDS umwandeln, als UDS auffassen:
BN_to_NDS_nocopy(x, x_MSDptr=,x_len=,x_LSDptr=);
// y in NDS umwandeln, als UDS auffassen:
- I_to_NDS_nocopy(y, y_MSDptr=,y_len=,y_LSDptr=,/*cl_true*/cl_false,);
+ I_to_NDS_nocopy(y, y_MSDptr=,y_len=,y_LSDptr=,/*true*/false,);
// dividieren:
{var DS q;
var DS r;
namespace cln {
-cl_boolean equal (const cl_I& x, const cl_I& y)
+bool equal (const cl_I& x, const cl_I& y)
{
// Methode:
// x und y haben gleiches Vorzeichen ->
if (fixnump(y))
// x Fixnum, y Fixnum
{ // This assumes cl_value_shift + cl_value_len == cl_pointer_size.
- return (cl_boolean) ((cl_sint)x.word == (cl_sint)y.word);
+ return (cl_sint)x.word == (cl_sint)y.word;
}
else
// x Fixnum, y Bignum
- return cl_false;
+ return false;
else
// x Bignum
if (fixnump(y))
// x Bignum, y Fixnum
- return cl_false;
+ return false;
else
// x Bignum, y Bignum
if (x.pointer == y.pointer)
- return cl_true; // gleiche Pointer -> selbe Zahl
+ return true; // gleiche Pointer -> selbe Zahl
else
{ var uintC xlen = TheBignum(x)->length;
var uintC ylen = TheBignum(y)->length;
if (xlen==ylen)
// gleiche Länge -> digitweise vergleichen
- return (cl_boolean) (compare_loop_msp(BN_MSDptr(x),BN_MSDptr(y),xlen) == 0);
+ return compare_loop_msp(BN_MSDptr(x),BN_MSDptr(y),xlen) == 0;
else
- return cl_false;
+ return false;
}
}
namespace cln {
-cl_boolean minusp (const cl_I& x)
+bool minusp (const cl_I& x)
{
return inline_minusp(x);
}
var const uintD* yLSDptr;
var uintD* ergMSDptr;
var uintC erglen;
- I_to_NDS_nocopy(x, xMSDptr = , xlen = , xLSDptr = , cl_false,);
- I_to_NDS_nocopy(y, yMSDptr = , ylen = , yLSDptr = , cl_false,);
+ I_to_NDS_nocopy(x, xMSDptr = , xlen = , xLSDptr = , false,);
+ I_to_NDS_nocopy(y, yMSDptr = , ylen = , yLSDptr = , false,);
DS_DS_mul_DS(xMSDptr,xlen,xLSDptr,yMSDptr,ylen,yLSDptr, ergMSDptr=,erglen=,);
return DS_to_I(ergMSDptr,erglen);
}
namespace cln {
-cl_boolean plusp (const cl_I& x)
+bool plusp (const cl_I& x)
{
if (inline_minusp(x))
- return cl_false; // x<0 -> nein
+ return false; // x<0 -> nein
elif (inline_zerop(x))
- return cl_false; // x=0 -> nein
+ return false; // x=0 -> nein
else
- return cl_true; // sonst ist x>0.
+ return true; // sonst ist x>0.
}
} // namespace cln
var const uintD* xMSDptr;
var uintC xlen;
var const uintD* xLSDptr;
- I_to_NDS_nocopy(x, xMSDptr = , xlen = , xLSDptr = , cl_false,);
+ I_to_NDS_nocopy(x, xMSDptr = , xlen = , xLSDptr = , false,);
var uintD* ergMSDptr;
var uintC erglen = 2*xlen;
var uintD* ergLSDptr;
namespace cln {
-cl_boolean zerop (const cl_I& x)
+bool zerop (const cl_I& x)
{
return inline_zerop(x);
}
// b normalisieren:
while (mspref(b_MSDptr,0)==0) { msshrink(b_MSDptr); b_len--; }
} }
- if (cl_false)
+ if (false)
{ subtract: // Ersetze (a,b) := (a-b,b).
if (!( subfrom_loop_lsp(b_LSDptr,a_LSDptr,b_len) ==0))
// Übertrag nach b_len Stellen, muß also a_len=b_len+1 sein.
// a normalisieren:
while (mspref(a_MSDptr,0)==0) { msshrink(a_MSDptr); a_len--; }
}
- if (cl_false)
+ if (false)
{ divide: // Ersetze (a,b) := (b , a mod b).
{var uintD* old_a_LSDptr = a_LSDptr;
var DS q;
// b normalisieren:
while (mspref(b_MSDptr,0)==0) { msshrink(b_MSDptr); b_len--; }
} }
- if (cl_false)
+ if (false)
{ subtract: // Ersetze (a,b) := (a-b,b).
NUDS_likobi0_NUDS(&uAa,&uAb); // uAa := uAa + uAb
NUDS_likobi0_NUDS(&uBa,&uBb); // uBa := uBa + uBb
// a normalisieren:
while (mspref(a_MSDptr,0)==0) { msshrink(a_MSDptr); a_len--; }
}
- if (cl_false)
+ if (false)
{ divide: // Ersetze (a,b) := (b , a mod b).
{var uintD* old_a_LSDptr = a_LSDptr;
var DS q;
// These are not inline, because they tend to duplicate a lot of template code.
-cl_wht_from_integer_to_rcpointer::cl_wht_from_integer_to_rcpointer (cl_boolean (*maygc_htentry) (const cl_htentry_from_integer_to_rcpointer&))
+cl_wht_from_integer_to_rcpointer::cl_wht_from_integer_to_rcpointer (bool (*maygc_htentry) (const cl_htentry_from_integer_to_rcpointer&))
{
var cl_heap_weak_hashtable_from_integer_to_rcpointer* ht = new cl_heap_weak_hashtable_from_integer_to_rcpointer (maygc_htentry);
ht->refcount = 1;
struct cl_wht_from_integer_to_rcpointer : public cl_gcpointer {
// Constructors.
- cl_wht_from_integer_to_rcpointer (cl_boolean (*maygc_htentry) (const cl_htentry_from_integer_to_rcpointer&));
+ cl_wht_from_integer_to_rcpointer (bool (*maygc_htentry) (const cl_htentry_from_integer_to_rcpointer&));
cl_wht_from_integer_to_rcpointer (const cl_wht_from_integer_to_rcpointer&);
// Assignment operators.
cl_wht_from_integer_to_rcpointer& operator= (const cl_wht_from_integer_to_rcpointer&);
syntax_integer,
lsyntax_all,
10,
- { float_format_ffloat, float_format_lfloat_min, cl_true }
+ { float_format_ffloat, float_format_lfloat_min, true }
};
cl_I::cl_I (const char * string)
char* end_pointer (void) { return buffer+index; }
};
-static cl_boolean number_char_p (char c)
+static bool number_char_p (char c)
{
if ((c >= '0') && (c <= '9'))
- return cl_true;
+ return true;
if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
- return cl_true;
+ return true;
switch (c) {
case '+': case '-': case '.': case '_': case '/':
- return cl_true;
+ return true;
default:
- return cl_false;
+ return false;
}
}
// Cf. cl_I_p in cl_I_ring.cc.
// But here, for better inlining in g++, it is preferrable to finish every
-// alternative with either "return cl_true;" or "return cl_false;".
+// alternative with either "return true;" or "return false;".
-inline cl_boolean cl_I_p (const cl_number& x)
+inline bool cl_I_p (const cl_number& x)
{
if (!x.pointer_p())
switch (x.nonpointer_tag()) {
case cl_FN_tag:
- return cl_true;
+ return true;
}
else
if (x.pointer_type() == &cl_class_bignum)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_I& cl_I_As (const cl_number& x, const char * filename, int line)
namespace cln {
-cl_boolean oddp (const cl_I& x)
+bool oddp (const cl_I& x)
{
if (fixnump(x)) {
// Fixnum: Bit 0 abprüfen
if (x.word & bit(cl_value_shift))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
} else {
// Bignum: Bit 0 im letzten Digit abprüfen
if (lspref(BN_LSDptr(x),0) & bit(0))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}
}
char * print_integer_to_string (unsigned int base, const cl_I& z)
{
- var cl_boolean minus_p = cl_false;
+ var bool minus_p = false;
var cl_I abs_z;
if (minusp(z)) {
// z<0 -> später Vorzeichen ausgeben:
- minus_p = cl_true;
+ minus_p = true;
abs_z = -z;
} else
abs_z = z;
var const uintD* n_MSDptr;
var uintC n_len;
var const uintD* n_LSDptr;
- I_to_NDS_nocopy(n, n_MSDptr=,n_len=,n_LSDptr=,cl_false,); // Digit sequence >0 zu n
+ I_to_NDS_nocopy(n, n_MSDptr=,n_len=,n_LSDptr=,false,); // Digit sequence >0 zu n
var uintD* MSDptr;
var uintC len = n_len + ceiling(16,intDsize); // 16 Bits mehr
// neue UDS mit len Zufallsdigits bilden:
const cl_I testrandom_I (random_state& randomstate)
{
var uint32 ran = random32(randomstate);
- var cl_boolean negative = (cl_boolean)(ran & 1);
- var cl_boolean algo = (cl_boolean)((ran>>1) & 1);
+ var bool negative = (ran & 1);
+ var bool algo = ((ran>>1) & 1);
ran = ran >> 2;
ran = ran & ((1<<8)-1);
var uintC len =
fprint(stream,"0");
}
-static cl_boolean null_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
+static bool null_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
{
unused R;
unused x;
unused y;
- return cl_true;
+ return true;
}
#define null_zero null_op0
-static cl_boolean null_zerop (cl_heap_ring* R, const _cl_ring_element& x)
+static bool null_zerop (cl_heap_ring* R, const _cl_ring_element& x)
{
unused R;
unused x;
- return cl_true;
+ return true;
}
#define null_plus null_op2
#define null_minus null_op2
fprint(stream,The(cl_I)(x));
}
-static cl_boolean I_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
+static bool I_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
{
unused R;
return equal(The(cl_I)(x),The(cl_I)(y));
return _cl_ring_element(R, (cl_I)0);
}
-static cl_boolean I_zerop (cl_heap_ring* R, const _cl_ring_element& x)
+static bool I_zerop (cl_heap_ring* R, const _cl_ring_element& x)
{
unused R;
return zerop(The(cl_I)(x));
return _cl_ring_element(R, expt_pos(The(cl_I)(x),y));
}
-static cl_boolean cl_I_p (const cl_number& x)
+static bool cl_I_p (const cl_number& x)
{
- return (cl_boolean)
- (!x.pointer_p()
+ return (!x.pointer_p()
? x.nonpointer_tag() == cl_FN_tag
- : x.pointer_type() == &cl_class_bignum
- );
+ : x.pointer_type() == &cl_class_bignum);
}
static cl_ring_setops I_setops = {
}
-static cl_boolean modint_equal (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
+static bool modint_equal (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
{
unused R;
return equal(x.rep,y.rep);
// any more except from the hash table and the ring. Note that the ring contains
// exactly one reference to the modulus.
-static cl_boolean maygc_htentry (const cl_htentry_from_integer_to_rcpointer& entry)
+static bool maygc_htentry (const cl_htentry_from_integer_to_rcpointer& entry)
{
if (!entry.key.pointer_p() || (entry.key.heappointer->refcount == 2))
if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
static const cl_wht_from_integer_to_rcpointer modint_ring_table = cl_wht_from_integer_to_rcpointer(maygc_htentry);
return _cl_MI(R, 0);
}
-static cl_boolean int_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
+static bool int_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
{
unused R;
return zerop(x.rep);
CL_ALLOCA_STACK;
var uintC len;
var const uintD* M_LSDptr;
- I_to_NDS_nocopy(M, ,len=,M_LSDptr=,cl_false,);
+ I_to_NDS_nocopy(M, ,len=,M_LSDptr=,false,);
if (lspref(M_LSDptr,len-1)==0) { len--; } // normalize
// Compute U as 2-adic inverse of M.
var uintD* U_LSDptr;
var uintC i_min;
var uintC i_max;
var uintC i = floor(m,2);
- var cl_boolean negative;
+ var bool negative;
if (U_bit(i)) {
for (; --i > 0; )
if (!U_bit(i)) break;
for (; ++i < m; )
if (!U_bit(i)) break;
i_max = i;
- negative = cl_true;
+ negative = true;
} else {
for (; --i > 0; )
if (U_bit(i)) break;
for (; ++i < m; )
if (U_bit(i)) break;
i_max = i;
- negative = cl_false;
+ negative = false;
}
#undef U_bit
// OK, all the bits i_max-1..i_min of U are equal.
// mod(x,m) = mod(x0+x1+x2+...,m).
// If x<0, apply this to -1-x, and use mod(x,m) = m-1-mod(-1-x,m).
{ Mutable(cl_I,x);
- var cl_boolean sign = minusp(x);
+ var bool sign = minusp(x);
if (sign) { x = lognot(x); }
var const uintC m1 = R->m1;
if (x >= R->modulus) {
return _cl_MI(R, 0);
}
-static cl_boolean std_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
+static bool std_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
{
unused R;
return zerop(x.rep);
{
var const uintD* n_LSDptr;
var const uintD* n_MSDptr;
- I_to_NDS_nocopy(n, n_MSDptr=,,n_LSDptr=,cl_false,);
+ I_to_NDS_nocopy(n, n_MSDptr=,,n_LSDptr=,false,);
var const uintL k_mask = bit(k)-1;
var uintD carry = 0;
var unsigned int carrybits = 0;
// Returns true if n looks like a prime (with error probability < 4^-count).
// Returns false if n is definitely composite, and then sets factor = some
// nontrivial factor or 0.
-extern cl_boolean cl_miller_rabin_test (const cl_I& n, int count, cl_I* factor);
+extern bool cl_miller_rabin_test (const cl_I& n, int count, cl_I* factor);
} // namespace cln
namespace cln {
-cl_boolean cl_miller_rabin_test (const cl_I& n, int count, cl_I* factor)
+bool cl_miller_rabin_test (const cl_I& n, int count, cl_I* factor)
{
// [Cohen], section 8.2, algorithm 8.2.2.
var cl_modint_ring R = find_modint_ring(n); // Z/nZ
// (b-1)*(b+1) == 0 mod n, hence n not prime.
if (factor)
*factor = gcd(R->retract(b)-1,n);
- return cl_false;
+ return false;
}
b = new_b;
}
else
*factor = 0;
}
- return cl_false;
+ return false;
passed:
;
}
- return cl_true;
+ return true;
}
} // namespace cln
CL_ALLOCA_STACK;
var const uintD* n_MSDptr;
var uintC n_len;
- I_to_NDS_nocopy(n, n_MSDptr=,n_len=,,cl_false,);
+ I_to_NDS_nocopy(n, n_MSDptr=,n_len=,,false,);
if (mspref(n_MSDptr,0)==0) { msshrink(n_MSDptr); n_len--; }
// Make room for a quotient.
var uintD* q_MSDptr;
namespace cln {
-cl_boolean isprobprime (const cl_I& n)
+bool isprobprime (const cl_I& n)
{
if (!(n > 0)) {
std::ostringstream buf;
if (i < cl_small_prime_table_size
&& ((unsigned int) cl_small_prime_table[i] == nn
|| nn == 2))
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}
if ((nn % 2) == 0 || cl_trialdivision(nn,1,trialdivide_limit))
- return cl_false;
+ return false;
// For small n, only few Miller-Rabin tests are needed.
if (nn < 2000U) count = 1; // {2}
else if (nn < 1300000U) count = 2; // {2,3}
var uint32 nhi = cl_I_to_UL(ldb(n,cl_byte(32,32)));
var uint32 nlo = cl_I_to_UL(ldb(n,cl_byte(32,0)));
if ((nlo % 2) == 0 || cl_trialdivision(nhi,nlo,1,trialdivide_limit))
- return cl_false;
+ return false;
} else {
if (evenp(n) || cl_trialdivision(n,1,trialdivide_limit))
- return cl_false;
+ return false;
}
// Step 2: Miller-Rabin test.
return cl_miller_rabin_test(n,count,NULL);
uintD data[1];
};
-static cl_boolean gf2_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
+static bool gf2_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
{{
DeclarePoly(cl_GV_MI,x);
DeclarePoly(cl_GV_MI,y);
var uintL xlen = xv->v.length();
var uintL ylen = yv->v.length();
if (!(xlen == ylen))
- return cl_false;
+ return false;
// We can compare full words since unused bits in the last word are 0.
var uintL count = ceiling(xlen,intDsize);
if (compare_loop_up(xv->data,yv->data,count) != 0)
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}}
static const _cl_UP gf2_plus (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
}
}}
-static cl_boolean modint_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
+static bool modint_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
{{
DeclarePoly(cl_GV_MI,x);
DeclarePoly(cl_GV_MI,y);
var sintL xlen = x.length();
var sintL ylen = y.length();
if (!(xlen == ylen))
- return cl_false;
+ return false;
for (var sintL i = xlen-1; i >= 0; i--)
if (!R->_equal(x[i],y[i]))
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}}
static const _cl_UP modint_zero (cl_heap_univpoly_ring* UPR)
return _cl_UP(UPR, cl_null_GV_I);
}
-static cl_boolean modint_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
+static bool modint_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
{
unused UPR;
{ DeclarePoly(cl_GV_MI,x);
var sintL xlen = x.length();
if (xlen == 0)
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}}
static const _cl_UP modint_plus (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
}
}}
-static cl_boolean gen_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
+static bool gen_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
{{
DeclarePoly(cl_SV_ringelt,x);
DeclarePoly(cl_SV_ringelt,y);
var sintL xlen = x.length();
var sintL ylen = y.length();
if (!(xlen == ylen))
- return cl_false;
+ return false;
for (var sintL i = xlen-1; i >= 0; i--)
if (!R->_equal(x[i],y[i]))
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}}
static const _cl_UP gen_zero (cl_heap_univpoly_ring* UPR)
return _cl_UP(UPR, cl_null_SV_ringelt);
}
-static cl_boolean gen_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
+static bool gen_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
{
unused UPR;
{ DeclarePoly(cl_SV_ringelt,x);
var sintL xlen = x.length();
if (xlen == 0)
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}}
static const _cl_UP gen_plus (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
// the ring contains exactly one reference to the base ring and exactly one
// reference to the name (on the property list).
-static cl_boolean maygc_htentry (const cl_htentry_from_rcpointer2_to_rcpointer& entry)
+static bool maygc_htentry (const cl_htentry_from_rcpointer2_to_rcpointer& entry)
{
if (!entry.key1.pointer_p() || (entry.key1.heappointer->refcount == 2))
if (!entry.key2.pointer_p() || (entry.key2.heappointer->refcount == 2))
if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
static const cl_wht_from_rcpointer2_to_rcpointer univpoly_ring_table = cl_wht_from_rcpointer2_to_rcpointer(maygc_htentry);
unused stream;
throw uninitialized_exception(x);
}
-static cl_boolean dummy_equal (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y)
+static bool dummy_equal (cl_heap_univpoly_ring* R, const _cl_UP& x, const _cl_UP& y)
{
unused R;
throw uninitialized_exception(x, y);
}
#define dummy_zero dummy_op0
-static cl_boolean dummy_zerop (cl_heap_univpoly_ring* R, const _cl_UP& x)
+static bool dummy_zerop (cl_heap_univpoly_ring* R, const _cl_UP& x)
{
unused R;
throw uninitialized_exception(x);
}
}}
-static cl_boolean num_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
+static bool num_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
{{
DeclarePoly(cl_SV_number,x);
DeclarePoly(cl_SV_number,y);
var sintL xlen = x.length();
var sintL ylen = y.length();
if (!(xlen == ylen))
- return cl_false;
+ return false;
for (var sintL i = xlen-1; i >= 0; i--)
if (!ops.equal(x[i],y[i]))
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}}
static const _cl_UP num_zero (cl_heap_univpoly_ring* UPR)
return _cl_UP(UPR, cl_null_SV_number);
}
-static cl_boolean num_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
+static bool num_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
{
unused UPR;
{ DeclarePoly(cl_SV_number,x);
var sintL xlen = x.length();
if (xlen == 0)
- return cl_true;
+ return true;
else
- return cl_false;
+ return false;
}}
static const _cl_UP num_plus (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
// any more except from the hash table and the ring. Note that the ring contains
// exactly one reference to the base ring.
-static cl_boolean maygc_htentry (const cl_htentry_from_rcpointer_to_rcpointer& entry)
+static bool maygc_htentry (const cl_htentry_from_rcpointer_to_rcpointer& entry)
{
if (!entry.key.pointer_p() || (entry.key.heappointer->refcount == 2))
if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
static const cl_wht_from_rcpointer_to_rcpointer univpoly_ring_table = cl_wht_from_rcpointer_to_rcpointer(maygc_htentry);
namespace cln {
-cl_boolean rootp (const cl_RA& x, uintL n, cl_RA* w)
+bool rootp (const cl_RA& x, uintL n, cl_RA* w)
{
// Methode:
// Bei Integers: klar.
var const cl_I& b = denominator(x);
var cl_I d;
if (!rootp(b,n,&d)) // Nenner auf n-te Potenz testen
- return cl_false;
+ return false;
var const cl_I& a = numerator(x);
var cl_I c;
if (!rootp(a,n,&c)) // Zähler auf n-te Potenz testen
- return cl_false;
+ return false;
// beides n-te Potenzen -> Quotient der Wurzeln bilden
- *w = I_I_to_RT(c,d); return cl_true;
+ *w = I_I_to_RT(c,d); return true;
}}
} // namespace cln
namespace cln {
-cl_boolean rootp (const cl_RA& x, const cl_I& n, cl_RA* w)
+bool rootp (const cl_RA& x, const cl_I& n, cl_RA* w)
{
// Methode:
// Bei Integers: klar.
var const cl_I& b = denominator(x);
var cl_I d;
if (!rootp(b,n,&d)) // Nenner auf n-te Potenz testen
- return cl_false;
+ return false;
var const cl_I& a = numerator(x);
var cl_I c;
if (!rootp(a,n,&c)) // Zähler auf n-te Potenz testen
- return cl_false;
+ return false;
// beides n-te Potenzen -> Quotient der Wurzeln bilden
- *w = I_I_to_RT(c,d); return cl_true;
+ *w = I_I_to_RT(c,d); return true;
}}
} // namespace cln
namespace cln {
-cl_boolean sqrtp (const cl_RA& x, cl_RA* w)
+bool sqrtp (const cl_RA& x, cl_RA* w)
{
// Methode:
// Bei Integers: klar.
var const cl_I& b = denominator(x);
var cl_I d;
if (!sqrtp(b,&d)) // Nenner auf Quadratzahl testen
- return cl_false;
+ return false;
var const cl_I& a = numerator(x);
var cl_I c;
if (!sqrtp(a,&c)) // Zähler auf Quadratzahl testen
- return cl_false;
+ return false;
// beides Quadratzahlen -> Quotient der Wurzeln bilden
- *w = I_I_to_RT(c,d); return cl_true;
+ *w = I_I_to_RT(c,d); return true;
}}
} // namespace cln
#endif
// Type tests.
-inline cl_boolean rationalp (const cl_RA& x)
- { unused x; return cl_true; }
-inline cl_boolean integerp (const cl_RA& x)
+inline bool rationalp (const cl_RA& x)
+ { unused x; return true; }
+inline bool integerp (const cl_RA& x)
{
if (!x.pointer_p())
- return cl_true;
+ return true;
else
if (x.pointer_type() == &cl_class_bignum)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
-inline cl_boolean ratiop (const cl_RA& x)
+inline bool ratiop (const cl_RA& x)
{
if (!x.pointer_p())
- return cl_false;
+ return false;
else
if (x.pointer_type() == &cl_class_bignum)
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}
public:
};
-inline cl_boolean integerp (const cl_RT& x)
- { unused x; return cl_false; }
-inline cl_boolean ratiop (const cl_RT& x)
- { unused x; return cl_true; }
+inline bool integerp (const cl_RT& x)
+ { unused x; return false; }
+inline bool ratiop (const cl_RT& x)
+ { unused x; return true; }
// Access numerator and denominator.
inline const cl_I& numerator (const cl_RT& x)
// Sign test:
// (MINUSP x) == (< x 0)
-inline cl_boolean minusp (const cl_RT& x)
+inline bool minusp (const cl_RT& x)
{ return minusp(numerator(x)); }
-inline cl_boolean minusp (const cl_RA& x)
+inline bool minusp (const cl_RA& x)
{
if (ratiop(x)) {
DeclareType(cl_RT,x);
}
// (ZEROP x) == (= x 0)
-inline cl_boolean zerop (const cl_RT& x)
- { unused x; return cl_false; }
-inline cl_boolean zerop (const cl_RA& x)
+inline bool zerop (const cl_RT& x)
+ { unused x; return false; }
+inline bool zerop (const cl_RA& x)
{
- return (cl_boolean)(x.word == cl_combine(cl_FN_tag,0));
+ return x.word == cl_combine(cl_FN_tag,0);
}
// (EQ x y) == (= x y), assuming y a fixnum
-inline cl_boolean eq (const cl_RA& x, sint32 y)
+inline bool eq (const cl_RA& x, sint32 y)
{
- return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
+ return x.word == cl_combine(cl_FN_tag,y);
}
// Liefert zu den Integers a und b mit b>1 und ggT(a,b)=1 den Bruch a/b.
namespace cln {
-cl_boolean equal (const cl_RA& r, const cl_RA& s)
+bool equal (const cl_RA& r, const cl_RA& s)
{
// Methode:
// r,s Integer -> klar
return equal(r,s);
} else
// r Integer, s Ratio
- return cl_false;
+ return false;
else
if (integerp(s))
// r Ratio, s Integer
- return cl_false;
+ return false;
else {
DeclareType(cl_RT,r);
DeclareType(cl_RT,s);
// r,s Ratios
if (!equal(numerator(r),numerator(s)))
- return cl_false;
+ return false;
if (!equal(denominator(r),denominator(s)))
- return cl_false;
- return cl_true;
+ return false;
+ return true;
}
}
namespace cln {
-cl_boolean minusp (const cl_RA& x)
+bool minusp (const cl_RA& x)
{
return inline_minusp(x);
}
namespace cln {
-cl_boolean plusp (const cl_RA& x)
+bool plusp (const cl_RA& x)
{
if (inline_minusp(x))
- return cl_false; // x<0 -> nein
+ return false; // x<0 -> nein
elif (inline_zerop(x))
- return cl_false; // x=0 -> nein
+ return false; // x=0 -> nein
else
- return cl_true; // sonst ist x>0.
+ return true; // sonst ist x>0.
}
} // namespace cln
namespace cln {
-cl_boolean zerop (const cl_RA& x)
+bool zerop (const cl_RA& x)
{
return inline_zerop(x);
}
syntax_rational,
lsyntax_all,
10,
- { float_format_ffloat, float_format_lfloat_min, cl_true }
+ { float_format_ffloat, float_format_lfloat_min, true }
};
cl_RA::cl_RA (const char * string)
char* end_pointer (void) { return buffer+index; }
};
-static cl_boolean number_char_p (char c)
+static bool number_char_p (char c)
{
if ((c >= '0') && (c <= '9'))
- return cl_true;
+ return true;
if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
- return cl_true;
+ return true;
switch (c) {
case '+': case '-': case '.': case '_': case '/':
- return cl_true;
+ return true;
default:
- return cl_false;
+ return false;
}
}
// Cf. cl_RA_p in cl_RA_ring.cc.
// But here, for better inlining in g++, it is preferrable to finish every
-// alternative with either "return cl_true;" or "return cl_false;".
+// alternative with either "return true;" or "return false;".
-inline cl_boolean cl_RA_p (const cl_number& x)
+inline bool cl_RA_p (const cl_number& x)
{
if (!x.pointer_p())
switch (x.nonpointer_tag()) {
case cl_FN_tag:
- return cl_true;
+ return true;
}
else
if (x.pointer_type()->flags & cl_class_flags_subclass_rational)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_RA& cl_RA_As (const cl_number& x, const char * filename, int line)
fprint(stream,The(cl_RA)(x));
}
-static cl_boolean RA_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
+static bool RA_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
{
unused R;
return equal(The(cl_RA)(x),The(cl_RA)(y));
return _cl_ring_element(R, (cl_RA)0);
}
-static cl_boolean RA_zerop (cl_heap_ring* R, const _cl_ring_element& x)
+static bool RA_zerop (cl_heap_ring* R, const _cl_ring_element& x)
{
unused R;
return zerop(The(cl_RA)(x));
return _cl_ring_element(R, expt_pos(The(cl_RA)(x),y));
}
-static cl_boolean cl_RA_p (const cl_number& x)
+static bool cl_RA_p (const cl_number& x)
{
- return (cl_boolean)
- (!x.pointer_p()
+ return (!x.pointer_p()
? x.nonpointer_tag() == cl_FN_tag
- : (x.pointer_type()->flags & cl_class_flags_subclass_rational) != 0
- );
+ : (x.pointer_type()->flags & cl_class_flags_subclass_rational) != 0);
}
static cl_ring_setops RA_setops = {
namespace cln {
-cl_boolean logp (const cl_I& a, const cl_I& b, cl_RA* l)
+bool logp (const cl_I& a, const cl_I& b, cl_RA* l)
{
// Methode:
// log(a,b) soll Bruch c/d mit teilerfremdem c>=0,d>0 ergeben.
if (a >= b) {
var cl_I_div_t div = cl_divide(a,b); // a durch b dividieren
if (!eq(div.remainder,0)) // Rest /=0 ?
- return cl_false; // -> fertig
+ return false; // -> fertig
a = div.quotient; // a := a/b
ud = uc + ud; vd = vc + vd;
} else {
}
}
// a=1 -> c=0,d=1 -> Ergebnis ud/vd
- *l = I_I_to_RA(UL_to_I(ud),UL_to_I(vd)); return cl_true;
+ *l = I_I_to_RA(UL_to_I(ud),UL_to_I(vd)); return true;
}}
} // namespace cln
namespace cln {
-cl_boolean logp (const cl_RA& a, const cl_RA& b, cl_RA* pl)
+bool logp (const cl_RA& a, const cl_RA& b, cl_RA* pl)
{
// Methode:
// a=1 -> Ergebnis 0
// -log(a2/a1,b1/b2) liefern
if (eq(a,1)) { // a=1 -> Ergebnis 0
- *pl = 0; return cl_true;
+ *pl = 0; return true;
}
if (integerp(b)) {
// b Integer
var const cl_I& a1 = numerator(a);
var const cl_I& a2 = denominator(a);
if (!eq(a1,1))
- return cl_false;
+ return false;
// a1=1
var cl_RA l;
if (logp(a2,b,&l)) {
- *pl = -l; return cl_true;
+ *pl = -l; return true;
} else
- return cl_false;
+ return false;
}
} else {
// a rational, b Ratio
if (logp(a2,b2,&l2)) {
if (eq(b1,1)) {
if (eq(a1,1))
- { *pl = l2; return cl_true; }
+ { *pl = l2; return true; }
else
- return cl_false;
+ return false;
} else {
var cl_RA l1;
// rationalen log(a1,b1) versuchen
if (logp(a1,b1,&l1))
if (l1 == l2)
- { *pl = l2; return cl_true; }
- return cl_false;
+ { *pl = l2; return true; }
+ return false;
}
}
}
if (logp(a1,b2,&l2)) {
if (eq(b1,1)) {
if (eq(a2,1))
- { *pl = -l2; return cl_true; }
+ { *pl = -l2; return true; }
else
- return cl_false;
+ return false;
} else {
var cl_RA l1;
// rationalen log(a2,b1) versuchen
if (logp(a2,b1,&l1))
if (l1 == l2)
- { *pl = -l2; return cl_true; }
+ { *pl = -l2; return true; }
}
}
}
- return cl_false;
+ return false;
}
}
extern cl_class cl_class_lfloat;
// Type tests.
-inline cl_boolean rationalp (const cl_R& x)
+inline bool rationalp (const cl_R& x)
{
if (!x.pointer_p()) {
if (x.nonpointer_tag() == cl_FN_tag)
- return cl_true;
+ return true;
} else {
if (x.pointer_type()->flags & cl_class_flags_subclass_rational)
- return cl_true;
+ return true;
}
- return cl_false;
+ return false;
}
-inline cl_boolean integerp (const cl_R& x)
+inline bool integerp (const cl_R& x)
{
if (!x.pointer_p()) {
if (x.nonpointer_tag() == cl_FN_tag)
- return cl_true;
+ return true;
} else {
if (x.pointer_type() == &cl_class_bignum)
- return cl_true;
+ return true;
}
- return cl_false;
+ return false;
}
-inline cl_boolean floatp (const cl_R& x)
+inline bool floatp (const cl_R& x)
{
if (!x.pointer_p()) {
switch (x.nonpointer_tag()) {
#if defined(CL_WIDE_POINTERS)
case cl_FF_tag:
#endif
- return cl_true;
+ return true;
}
} else {
if (x.pointer_type()->flags & cl_class_flags_subclass_float)
- return cl_true;
+ return true;
}
- return cl_false;
+ return false;
}
// Comparison with a fixnum.
-inline cl_boolean eq (const cl_R& x, sint32 y)
+inline bool eq (const cl_R& x, sint32 y)
{
- return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
+ return x.word == cl_combine(cl_FN_tag,y);
}
-inline cl_boolean exact_zerop (const cl_R& x)
+inline bool exact_zerop (const cl_R& x)
{
return eq(x,0);
}
namespace cln {
-inline cl_boolean equal (const cl_F& x, const cl_F& y)
+inline bool equal (const cl_F& x, const cl_F& y)
{
- return (cl_boolean) (compare(x,y) == 0);
+ return compare(x,y) == 0;
}
-cl_boolean equal (const cl_R& x, const cl_R& y)
+bool equal (const cl_R& x, const cl_R& y)
{
// Methode:
// Beide rational oder beide Floats -> klar.
return equal(x,y);
, // x rational, y Float -> x in Float umwandeln
if (!power2p(denominator(x)))
- return cl_false;
+ return false;
if (!equal(cl_float(x,y),y))
- return cl_false;
+ return false;
return equal(x,rational(y));
);
, realcase2(y
, // x Float, y rational -> y in Float umwandeln
if (!power2p(denominator(y)))
- return cl_false;
+ return false;
if (!equal(x,cl_float(y,x)))
- return cl_false;
+ return false;
return equal(rational(x),y);
, // beides Floats
return equal(x,y);
namespace cln {
-cl_boolean minusp (const cl_R& x)
+bool minusp (const cl_R& x)
#if 0
GEN_R_OP1_2(x, minusp, return)
#else // fully inlined, faster
namespace cln {
-cl_boolean plusp (const cl_R& x)
+bool plusp (const cl_R& x)
{
if (minusp(x))
- return cl_false; // x<0 -> nein
+ return false; // x<0 -> nein
elif (zerop(x))
- return cl_false; // x=0 -> nein
+ return false; // x=0 -> nein
else
- return cl_true; // sonst ist x>0.
+ return true; // sonst ist x>0.
}
} // namespace cln
namespace cln {
-cl_boolean zerop (const cl_R& x)
+bool zerop (const cl_R& x)
#if 0
GEN_R_OP1_2(x, zerop, return)
#else // fully inlined, faster
arg = thousands;
} while (arg > 0);
// Roll back the recursion.
- var cl_boolean first_piece = cl_true;
+ var bool first_piece = true;
do {
var uintL small = *--small_piece_ptr;
var const char * illion = *--illion_ptr;
fprint(stream,", ");
format_small_cardinal(stream,small);
fprint(stream,illion);
- first_piece = cl_false;
+ first_piece = false;
}
} until (illion_ptr == &illions[0]);
}
for (sintL i = 1; i <= places; i++) string[i] = '0';
string[1+places] = '\0';
return digits_with_dot(string, 1+places,
- cl_true, (cl_boolean)(places==0), 0
+ true, (places==0), 0
);
}
// significand : Integer >0
// = 1 + Stelle der 1. signifikanten Ziffer
// oder =0, falls k>=0
// Ausführung der Rundung:
- var cl_boolean letzte_stelle_p = cl_false; // d oder width angegeben?
+ var bool letzte_stelle_p = false; // d oder width angegeben?
var sintL letzte_stelle = 0; // falls d oder width angegeben waren:
// Stelle der letzten signifikanten Ziffer
- var cl_boolean halbzahlig = cl_false; // zeigt an, ob hinten genau ein 0.500000 wegfällt
+ var bool halbzahlig = false; // zeigt an, ob hinten genau ein 0.500000 wegfällt
do {
// Solange das Ergebnis auch nach Aufrundung >= 1 bliebe,
// eine Vorkommastelle mehr einplanen:
if (dmin > 0)
if (letzte_stelle > -dmin)
letzte_stelle = -dmin;
- letzte_stelle_p = cl_true;
+ letzte_stelle_p = true;
}
elif (width > 0) {
// Falls nicht d, nur width angegeben:
if (dmin > 0)
if (letzte_stelle > -dmin)
letzte_stelle = -dmin;
- letzte_stelle_p = cl_true;
+ letzte_stelle_p = true;
}
if (letzte_stelle_p) {
var sintL ziffernzahl = letzte_stelle - stelle;
aufrund_einh = dezimal_einh;
// Jetzt darf auch um eine (halbe) DEZIMAL-Einheit gerundet werden.
if (aufrund_einh == dezimal_einh)
- halbzahlig = cl_true;
+ halbzahlig = true;
}
} until (((numerator << 1) + aufrund_einh) < (denominator << 1));
// stelle = Position der ersten signifikanten Stelle + 1
digit_count++;
}
// letzte signifikante Ziffer ausgeben:
- if (letzte_stelle_p ? (cl_boolean)(stelle >= letzte_stelle) : cl_true) {
+ if (letzte_stelle_p ? (stelle >= letzte_stelle) : true) {
digit = (abrunden && !aufrunden ? digit :
aufrunden && !abrunden ? digit+1 :
(numerator<<1) <= denominator ? digit : digit+1);
digit_count++;
}
return digits_with_dot(digitstring.contents(), digit_count+1,
- (cl_boolean)(point_pos==0),
- (cl_boolean)(point_pos==digit_count),
+ point_pos==0,
+ point_pos==digit_count,
point_pos
);
}
void format_integer (std::ostream& stream, const cl_I& arg,
unsigned int base, sintL mincol, char padchar,
- char commachar, uintL commainterval, cl_boolean commaflag,
- cl_boolean positive_sign_flag)
+ char commachar, uintL commainterval, bool commaflag,
+ bool positive_sign_flag)
{
if ((mincol == 0) && !commaflag && !positive_sign_flag) {
// Normale Ausgabe tut's.
var uintL oldstring_length = ::strlen(oldstring);
var uintL number_of_digits = (minusp(arg) ? oldstring_length-1 : oldstring_length);
var uintL number_of_commas = (commaflag ? floor(number_of_digits-1,commainterval) : 0);
- var cl_boolean positive_sign = (cl_boolean) (positive_sign_flag && (arg > 0));
+ var bool positive_sign = positive_sign_flag && (arg > 0);
var uintL newstring_length = (positive_sign ? 1 : 0) + oldstring_length + number_of_commas;
var char* newstring = (char *) malloc_hook(newstring_length+1);
newstring[newstring_length] = '\0'; // newstring termination
}
}
#if 0
- format_padded_string(stream,mincol,1,0,padchar,cl_true,newstring);
+ format_padded_string(stream,mincol,1,0,padchar,true,newstring);
#else // expand this special case of format_padded_string inline:
if ((sintL)newstring_length < mincol)
format_padding(stream,mincol-newstring_length,padchar);
namespace cln {
-void format_padded_string (std::ostream& stream, sintL mincol, sintL colinc, sintL minpad, char padchar, cl_boolean padleftflag, const char * str)
+void format_padded_string (std::ostream& stream, sintL mincol, sintL colinc, sintL minpad, char padchar, bool padleftflag, const char * str)
{
var sintL need = ::strlen(str) + minpad; // so viele Zeichen mindestens
var uintL auxpad = (need < mincol
// werden mindestens minpad Zeichen eingefügt, eventuelle weitere dann in
// Blöcken à colinc Zeichen. Falls padleftflag, werden sie links eingefügt,
// sonst rechts vom String.
-extern void format_padded_string (std::ostream& stream, sintL mincol, sintL colinc, sintL minpad, char padchar, cl_boolean padleftflag, const char * str);
+extern void format_padded_string (std::ostream& stream, sintL mincol, sintL colinc, sintL minpad, char padchar, bool padleftflag, const char * str);
// gibt den Integer arg auf den Stream aus:
// in Zahlenbasis base, mit Vorzeichen (+ nur falls >0 und positive-sign-flag),
// bei commaflag alle drei Stellen unterbrochen durch ein Zeichen commachar.
// Das Ganze links aufgefüllt mit padchar's, so daß die Gesamtbreite mindestens
// mincol ist.
-extern void format_integer (std::ostream& stream, const cl_I& arg, unsigned int base, sintL mincol, char padchar, char commachar, uintL commainterval, cl_boolean commaflag, cl_boolean positive_sign_flag);
+extern void format_integer (std::ostream& stream, const cl_I& arg, unsigned int base, sintL mincol, char padchar, char commachar, uintL commainterval, bool commaflag, bool positive_sign_flag);
// format_scale_exponent(arg) liefert zur Floating-Point-Zahl arg
// drei Werte: mantissa und n, mit
struct digits_with_dot {
char * string; // Mit malloc_hook() alloziert, mit free_hook() freizugeben.
uintL length; // strlen(string)
- cl_boolean dot_comes_first; // string[0] == '.' ?
- cl_boolean dot_comes_last; // string[strlen(string)-1] == '.' ?
+ bool dot_comes_first; // string[0] == '.' ?
+ bool dot_comes_last; // string[strlen(string)-1] == '.' ?
uintL dot_position; // string[dot_position] is '.'
// Constructor.
- digits_with_dot (char* s, uintL l, cl_boolean df, cl_boolean dl, uintL dp)
+ digits_with_dot (char* s, uintL l, bool df, bool dl, uintL dp)
: string(s), length(l), dot_comes_first(df), dot_comes_last(dl), dot_position(dp) {}
};
extern const digits_with_dot format_float_to_string (const cl_F& arg, const sintL width, const sintL d, const sintL k, const sintL dmin);
syntax_real,
lsyntax_all,
10,
- { float_format_ffloat, float_format_lfloat_min, cl_true }
+ { float_format_ffloat, float_format_lfloat_min, true }
};
cl_R::cl_R (const char * string)
}
var const char * ptr_after_sign = ptr;
var const char * ptr_after_intpart = skip_digits(ptr_after_sign,string_limit,float_base);
- var cl_boolean have_dot = cl_false;
+ var bool have_dot = false;
var const char * ptr_before_fracpart = ptr_after_intpart;
var const char * ptr_after_fracpart = ptr_after_intpart;
ptr = ptr_after_intpart;
if (ptr != string_limit)
if (*ptr == '.') {
- have_dot = cl_true;
+ have_dot = true;
ptr_before_fracpart = ptr+1;
ptr_after_fracpart = skip_digits(ptr_before_fracpart,string_limit,float_base);
}
ptr = ptr_after_fracpart;
var char exponent_marker;
- var cl_boolean have_exponent;
+ var bool have_exponent;
var const char * ptr_in_exponent = ptr;
var const char * ptr_after_exponent = ptr;
if ((ptr == string_limit) || !(((*ptr >= '0') && (*ptr <= '9')) || ((*ptr >= 'A') && (*ptr <= 'Z') && (*ptr != 'I')) || ((*ptr >= 'a') && (*ptr <= 'z') && (*ptr != 'i')) || (*ptr == '.') || (*ptr == '/'))) {
// No exponent.
- have_exponent = cl_false;
+ have_exponent = false;
// Must have at least one fractional part digit.
if (ptr_after_fracpart == ptr_before_fracpart) goto not_float_syntax;
exponent_marker = 'E';
} else {
- have_exponent = cl_true;
+ have_exponent = true;
// Must have at least one digit.
if (ptr_after_sign == ptr_after_intpart)
if (ptr_after_fracpart == ptr_before_fracpart)
char* end_pointer (void) { return buffer+index; }
};
-static cl_boolean number_char_p (char c)
+static bool number_char_p (char c)
{
if ((c >= '0') && (c <= '9'))
- return cl_true;
+ return true;
if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
- return cl_true;
+ return true;
switch (c) {
case '+': case '-': case '.': case '_': case '/':
- return cl_true;
+ return true;
default:
- return cl_false;
+ return false;
}
}
// Cf. cl_R_p in cl_R_ring.cc.
// But here, for better inlining in g++, it is preferrable to finish every
-// alternative with either "return cl_true;" or "return cl_false;".
+// alternative with either "return true;" or "return false;".
-inline cl_boolean cl_R_p (const cl_number& x)
+inline bool cl_R_p (const cl_number& x)
{
if (!x.pointer_p())
switch (x.nonpointer_tag()) {
#if defined(CL_WIDE_POINTERS)
case cl_FF_tag:
#endif
- return cl_true;
+ return true;
}
else
if (x.pointer_type()->flags & cl_class_flags_subclass_real)
- return cl_true;
- return cl_false;
+ return true;
+ return false;
}
const cl_R& cl_R_As (const cl_number& x, const char * filename, int line)
const cl_R expt (const cl_R& x, const cl_I& y)
{
if (eq(y,0)) { return 1; } // y=0 -> Ergebnis 1
- var cl_boolean y_negative = minusp(y);
+ var bool y_negative = minusp(y);
var cl_I abs_y = (y_negative ? -y : y); // Betrag von y nehmen
var cl_R z = expt_pos(x,abs_y); // (expt x (abs y))
return (y_negative ? recip(z) : z); // evtl. noch Kehrwert nehmen
fprint(stream,The(cl_R)(x));
}
-static cl_boolean R_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
+static bool R_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
{
unused R;
return equal(The(cl_R)(x),The(cl_R)(y));
return _cl_ring_element(R, (cl_R)0);
}
-static cl_boolean R_zerop (cl_heap_ring* R, const _cl_ring_element& x)
+static bool R_zerop (cl_heap_ring* R, const _cl_ring_element& x)
{
unused R;
// Here we return true only if x is the *exact* zero. Because we
return _cl_ring_element(R, expt(The(cl_R)(x),y));
}
-static cl_boolean cl_R_p (const cl_number& x)
+static bool cl_R_p (const cl_number& x)
{
- return (cl_boolean)
- (!x.pointer_p()
- || (x.pointer_type()->flags & cl_class_flags_subclass_real) != 0
- );
+ return (!x.pointer_p()
+ || (x.pointer_type()->flags & cl_class_flags_subclass_real) != 0);
}
static cl_ring_setops R_setops = {
#if 0
cl_I a = "77371252437321868671713407";
cl_I w;
- cl_boolean squarep = isqrt(a,&w);
+ bool squarep = isqrt(a,&w);
DUMP(squarep);
DUMP(w);
DUMP(expt_pos(w,2) <= a);
cl_I a = testrandom_I();
if (a >= 0) {
cl_I w;
- cl_boolean squarep = isqrt(a,&w);
+ bool squarep = isqrt(a,&w);
ASSERT1(w >= 0 && expt_pos(w,2) <= a && a < expt_pos(w+1,2), a);
ASSERT1(squarep ? w*w==a : w*w<a, a);
}
cl_I a = testrandom_I();
if (a >= 0) {
cl_I w;
- cl_boolean squarep = sqrtp(a,&w);
+ bool squarep = sqrtp(a,&w);
cl_I correct_w;
- cl_boolean correct_squarep = isqrt(a,&correct_w);
+ bool correct_squarep = isqrt(a,&correct_w);
ASSERT1(squarep == correct_squarep, a);
if (squarep)
ASSERT1(w == correct_w, a);