3 * This file contains the interface to the underlying bignum package.
4 * Its most important design principle is to completely hide the inner
5 * working of that other package from the user of GiNaC. It must either
6 * provide implementation of arithmetic operators and numerical evaluation
7 * of special functions or implement the interface to the bignum package. */
10 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #if defined(HAVE_SSTREAM)
35 #elif defined(HAVE_STRSTREAM)
38 #error Need either sstream or strstream
47 // CLN should not pollute the global namespace, hence we include it here
48 // instead of in some header file where it would propagate to other parts.
49 // Also, we only need a subset of CLN, so we don't include the complete cln.h:
51 #include <cln/cl_integer_io.h>
52 #include <cln/cl_integer_ring.h>
53 #include <cln/cl_rational_io.h>
54 #include <cln/cl_rational_ring.h>
55 #include <cln/cl_lfloat_class.h>
56 #include <cln/cl_lfloat_io.h>
57 #include <cln/cl_real_io.h>
58 #include <cln/cl_real_ring.h>
59 #include <cln/cl_complex_io.h>
60 #include <cln/cl_complex_ring.h>
61 #include <cln/cl_numtheory.h>
62 #else // def HAVE_CLN_CLN_H
63 #include <cl_integer_io.h>
64 #include <cl_integer_ring.h>
65 #include <cl_rational_io.h>
66 #include <cl_rational_ring.h>
67 #include <cl_lfloat_class.h>
68 #include <cl_lfloat_io.h>
69 #include <cl_real_io.h>
70 #include <cl_real_ring.h>
71 #include <cl_complex_io.h>
72 #include <cl_complex_ring.h>
73 #include <cl_numtheory.h>
74 #endif // def HAVE_CLN_CLN_H
76 #ifndef NO_NAMESPACE_GINAC
78 #endif // ndef NO_NAMESPACE_GINAC
80 // linker has no problems finding text symbols for numerator or denominator
83 GINAC_IMPLEMENT_REGISTERED_CLASS(numeric, basic)
86 // default constructor, destructor, copy constructor assignment
87 // operator and helpers
92 /** default ctor. Numerically it initializes to an integer zero. */
93 numeric::numeric() : basic(TINFO_numeric)
95 debugmsg("numeric default constructor", LOGLEVEL_CONSTRUCT);
99 setflag(status_flags::evaluated|
100 status_flags::hash_calculated);
105 debugmsg("numeric destructor" ,LOGLEVEL_DESTRUCT);
109 numeric::numeric(const numeric & other)
111 debugmsg("numeric copy constructor", LOGLEVEL_CONSTRUCT);
115 const numeric & numeric::operator=(const numeric & other)
117 debugmsg("numeric operator=", LOGLEVEL_ASSIGNMENT);
118 if (this != &other) {
127 void numeric::copy(const numeric & other)
130 value = new cl_N(*other.value);
133 void numeric::destroy(bool call_parent)
136 if (call_parent) basic::destroy(call_parent);
140 // other constructors
145 numeric::numeric(int i) : basic(TINFO_numeric)
147 debugmsg("numeric constructor from int",LOGLEVEL_CONSTRUCT);
148 // Not the whole int-range is available if we don't cast to long
149 // first. This is due to the behaviour of the cl_I-ctor, which
150 // emphasizes efficiency:
151 value = new cl_I((long) i);
153 setflag(status_flags::evaluated|
154 status_flags::hash_calculated);
158 numeric::numeric(unsigned int i) : basic(TINFO_numeric)
160 debugmsg("numeric constructor from uint",LOGLEVEL_CONSTRUCT);
161 // Not the whole uint-range is available if we don't cast to ulong
162 // first. This is due to the behaviour of the cl_I-ctor, which
163 // emphasizes efficiency:
164 value = new cl_I((unsigned long)i);
166 setflag(status_flags::evaluated|
167 status_flags::hash_calculated);
171 numeric::numeric(long i) : basic(TINFO_numeric)
173 debugmsg("numeric constructor from long",LOGLEVEL_CONSTRUCT);
176 setflag(status_flags::evaluated|
177 status_flags::hash_calculated);
181 numeric::numeric(unsigned long i) : basic(TINFO_numeric)
183 debugmsg("numeric constructor from ulong",LOGLEVEL_CONSTRUCT);
186 setflag(status_flags::evaluated|
187 status_flags::hash_calculated);
190 /** Ctor for rational numerics a/b.
192 * @exception overflow_error (division by zero) */
193 numeric::numeric(long numer, long denom) : basic(TINFO_numeric)
195 debugmsg("numeric constructor from long/long",LOGLEVEL_CONSTRUCT);
197 throw (std::overflow_error("division by zero"));
198 value = new cl_I(numer);
199 *value = *value / cl_I(denom);
201 setflag(status_flags::evaluated|
202 status_flags::hash_calculated);
206 numeric::numeric(double d) : basic(TINFO_numeric)
208 debugmsg("numeric constructor from double",LOGLEVEL_CONSTRUCT);
209 // We really want to explicitly use the type cl_LF instead of the
210 // more general cl_F, since that would give us a cl_DF only which
211 // will not be promoted to cl_LF if overflow occurs:
213 *value = cl_float(d, cl_default_float_format);
215 setflag(status_flags::evaluated|
216 status_flags::hash_calculated);
220 numeric::numeric(const char *s) : basic(TINFO_numeric)
221 { // MISSING: treatment of complex and ints and rationals.
222 debugmsg("numeric constructor from string",LOGLEVEL_CONSTRUCT);
224 value = new cl_LF(s);
228 setflag(status_flags::evaluated|
229 status_flags::hash_calculated);
232 /** Ctor from CLN types. This is for the initiated user or internal use
234 numeric::numeric(const cl_N & z) : basic(TINFO_numeric)
236 debugmsg("numeric constructor from cl_N", LOGLEVEL_CONSTRUCT);
239 setflag(status_flags::evaluated|
240 status_flags::hash_calculated);
247 /** Construct object from archive_node. */
248 numeric::numeric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
250 debugmsg("numeric constructor from archive_node", LOGLEVEL_CONSTRUCT);
253 // Read number as string
255 if (n.find_string("number", str)) {
256 istringstream s(str);
257 cl_idecoded_float re, im;
261 case 'N': // Ordinary number
262 case 'R': // Integer-decoded real number
263 s >> re.sign >> re.mantissa >> re.exponent;
264 *value = re.sign * re.mantissa * ::expt(cl_float(2.0, cl_default_float_format), re.exponent);
266 case 'C': // Integer-decoded complex number
267 s >> re.sign >> re.mantissa >> re.exponent;
268 s >> im.sign >> im.mantissa >> im.exponent;
269 *value = ::complex(re.sign * re.mantissa * ::expt(cl_float(2.0, cl_default_float_format), re.exponent),
270 im.sign * im.mantissa * ::expt(cl_float(2.0, cl_default_float_format), im.exponent));
272 default: // Ordinary number
279 // Read number as string
281 if (n.find_string("number", str)) {
282 istrstream f(str.c_str(), str.size() + 1);
283 cl_idecoded_float re, im;
287 case 'R': // Integer-decoded real number
288 f >> re.sign >> re.mantissa >> re.exponent;
289 *value = re.sign * re.mantissa * ::expt(cl_float(2.0, cl_default_float_format), re.exponent);
291 case 'C': // Integer-decoded complex number
292 f >> re.sign >> re.mantissa >> re.exponent;
293 f >> im.sign >> im.mantissa >> im.exponent;
294 *value = ::complex(re.sign * re.mantissa * ::expt(cl_float(2.0, cl_default_float_format), re.exponent),
295 im.sign * im.mantissa * ::expt(cl_float(2.0, cl_default_float_format), im.exponent));
297 default: // Ordinary number
305 setflag(status_flags::evaluated|
306 status_flags::hash_calculated);
309 /** Unarchive the object. */
310 ex numeric::unarchive(const archive_node &n, const lst &sym_lst)
312 return (new numeric(n, sym_lst))->setflag(status_flags::dynallocated);
315 /** Archive the object. */
316 void numeric::archive(archive_node &n) const
318 inherited::archive(n);
320 // Write number as string
322 if (this->is_crational())
325 // Non-rational numbers are written in an integer-decoded format
326 // to preserve the precision
327 if (this->is_real()) {
328 cl_idecoded_float re = integer_decode_float(The(cl_F)(*value));
330 s << re.sign << " " << re.mantissa << " " << re.exponent;
332 cl_idecoded_float re = integer_decode_float(The(cl_F)(::realpart(*value)));
333 cl_idecoded_float im = integer_decode_float(The(cl_F)(::imagpart(*value)));
335 s << re.sign << " " << re.mantissa << " " << re.exponent << " ";
336 s << im.sign << " " << im.mantissa << " " << im.exponent;
339 n.add_string("number", s.str());
341 // Write number as string
343 ostrstream f(buf, 1024);
344 if (this->is_crational())
347 // Non-rational numbers are written in an integer-decoded format
348 // to preserve the precision
349 if (this->is_real()) {
350 cl_idecoded_float re = integer_decode_float(The(cl_F)(*value));
352 f << re.sign << " " << re.mantissa << " " << re.exponent << ends;
354 cl_idecoded_float re = integer_decode_float(The(cl_F)(::realpart(*value)));
355 cl_idecoded_float im = integer_decode_float(The(cl_F)(::imagpart(*value)));
357 f << re.sign << " " << re.mantissa << " " << re.exponent << " ";
358 f << im.sign << " " << im.mantissa << " " << im.exponent << ends;
362 n.add_string("number", str);
367 // functions overriding virtual functions from bases classes
372 basic * numeric::duplicate() const
374 debugmsg("numeric duplicate", LOGLEVEL_DUPLICATE);
375 return new numeric(*this);
378 void numeric::print(ostream & os, unsigned upper_precedence) const
380 // The method print adds to the output so it blends more consistently
381 // together with the other routines and produces something compatible to
383 debugmsg("numeric print", LOGLEVEL_PRINT);
384 if (this->is_real()) {
385 // case 1, real: x or -x
386 if ((precedence<=upper_precedence) && (!this->is_pos_integer())) {
387 os << "(" << *value << ")";
392 // case 2, imaginary: y*I or -y*I
393 if (::realpart(*value) == 0) {
394 if ((precedence<=upper_precedence) && (::imagpart(*value) < 0)) {
395 if (::imagpart(*value) == -1) {
398 os << "(" << ::imagpart(*value) << "*I)";
401 if (::imagpart(*value) == 1) {
404 if (::imagpart (*value) == -1) {
407 os << ::imagpart(*value) << "*I";
412 // case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I
413 if (precedence <= upper_precedence) os << "(";
414 os << ::realpart(*value);
415 if (::imagpart(*value) < 0) {
416 if (::imagpart(*value) == -1) {
419 os << ::imagpart(*value) << "*I";
422 if (::imagpart(*value) == 1) {
425 os << "+" << ::imagpart(*value) << "*I";
428 if (precedence <= upper_precedence) os << ")";
434 void numeric::printraw(ostream & os) const
436 // The method printraw doesn't do much, it simply uses CLN's operator<<()
437 // for output, which is ugly but reliable. e.g: 2+2i
438 debugmsg("numeric printraw", LOGLEVEL_PRINT);
439 os << "numeric(" << *value << ")";
443 void numeric::printtree(ostream & os, unsigned indent) const
445 debugmsg("numeric printtree", LOGLEVEL_PRINT);
446 os << string(indent,' ') << *value
448 << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
449 << ", flags=" << flags << endl;
453 void numeric::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
455 debugmsg("numeric print csrc", LOGLEVEL_PRINT);
456 ios::fmtflags oldflags = os.flags();
457 os.setf(ios::scientific);
458 if (this->is_rational() && !this->is_integer()) {
459 if (compare(_num0()) > 0) {
461 if (type == csrc_types::ctype_cl_N)
462 os << "cl_F(\"" << numer().evalf() << "\")";
464 os << numer().to_double();
467 if (type == csrc_types::ctype_cl_N)
468 os << "cl_F(\"" << -numer().evalf() << "\")";
470 os << -numer().to_double();
473 if (type == csrc_types::ctype_cl_N)
474 os << "cl_F(\"" << denom().evalf() << "\")";
476 os << denom().to_double();
479 if (type == csrc_types::ctype_cl_N)
480 os << "cl_F(\"" << evalf() << "\")";
488 bool numeric::info(unsigned inf) const
491 case info_flags::numeric:
492 case info_flags::polynomial:
493 case info_flags::rational_function:
495 case info_flags::real:
497 case info_flags::rational:
498 case info_flags::rational_polynomial:
499 return is_rational();
500 case info_flags::crational:
501 case info_flags::crational_polynomial:
502 return is_crational();
503 case info_flags::integer:
504 case info_flags::integer_polynomial:
506 case info_flags::cinteger:
507 case info_flags::cinteger_polynomial:
508 return is_cinteger();
509 case info_flags::positive:
510 return is_positive();
511 case info_flags::negative:
512 return is_negative();
513 case info_flags::nonnegative:
514 return compare(_num0())>=0;
515 case info_flags::posint:
516 return is_pos_integer();
517 case info_flags::negint:
518 return is_integer() && (compare(_num0())<0);
519 case info_flags::nonnegint:
520 return is_nonneg_integer();
521 case info_flags::even:
523 case info_flags::odd:
525 case info_flags::prime:
531 /** Disassemble real part and imaginary part to scan for the occurrence of a
532 * single number. Also handles the imaginary unit. It ignores the sign on
533 * both this and the argument, which may lead to what might appear as funny
534 * results: (2+I).has(-2) -> true. But this is consistent, since we also
535 * would like to have (-2+I).has(2) -> true and we want to think about the
536 * sign as a multiplicative factor. */
537 bool numeric::has(const ex & other) const
539 if (!is_exactly_of_type(*other.bp, numeric))
541 const numeric & o = static_cast<numeric &>(const_cast<basic &>(*other.bp));
542 if (this->is_equal(o) || this->is_equal(-o))
544 if (o.imag().is_zero()) // e.g. scan for 3 in -3*I
545 return (this->real().is_equal(o) || this->imag().is_equal(o) ||
546 this->real().is_equal(-o) || this->imag().is_equal(-o));
548 if (o.is_equal(I)) // e.g scan for I in 42*I
549 return !this->is_real();
550 if (o.real().is_zero()) // e.g. scan for 2*I in 2*I+1
551 return (this->real().has(o*I) || this->imag().has(o*I) ||
552 this->real().has(-o*I) || this->imag().has(-o*I));
558 /** Evaluation of numbers doesn't do anything at all. */
559 ex numeric::eval(int level) const
561 // Warning: if this is ever gonna do something, the ex ctors from all kinds
562 // of numbers should be checking for status_flags::evaluated.
567 /** Cast numeric into a floating-point object. For example exact numeric(1) is
568 * returned as a 1.0000000000000000000000 and so on according to how Digits is
571 * @param level ignored, but needed for overriding basic::evalf.
572 * @return an ex-handle to a numeric. */
573 ex numeric::evalf(int level) const
575 // level can safely be discarded for numeric objects.
576 return numeric(::cl_float(1.0, ::cl_default_float_format) * (*value)); // -> CLN
581 /** Implementation of ex::diff() for a numeric. It always returns 0.
584 ex numeric::derivative(const symbol & s) const
590 int numeric::compare_same_type(const basic & other) const
592 GINAC_ASSERT(is_exactly_of_type(other, numeric));
593 const numeric & o = static_cast<numeric &>(const_cast<basic &>(other));
595 if (*value == *o.value) {
603 bool numeric::is_equal_same_type(const basic & other) const
605 GINAC_ASSERT(is_exactly_of_type(other,numeric));
606 const numeric *o = static_cast<const numeric *>(&other);
608 return this->is_equal(*o);
611 unsigned numeric::calchash(void) const
613 return (hashvalue=cl_equal_hashcode(*value) | 0x80000000U);
615 cout << *value << "->" << hashvalue << endl;
616 hashvalue=HASHVALUE_NUMERIC+1000U;
617 return HASHVALUE_NUMERIC+1000U;
622 unsigned numeric::calchash(void) const
624 double d=to_double();
630 return 0x88000000U+s*unsigned(d/0x07FF0000);
636 // new virtual functions which can be overridden by derived classes
642 // non-virtual functions in this class
647 /** Numerical addition method. Adds argument to *this and returns result as
648 * a new numeric object. */
649 numeric numeric::add(const numeric & other) const
651 return numeric((*value)+(*other.value));
654 /** Numerical subtraction method. Subtracts argument from *this and returns
655 * result as a new numeric object. */
656 numeric numeric::sub(const numeric & other) const
658 return numeric((*value)-(*other.value));
661 /** Numerical multiplication method. Multiplies *this and argument and returns
662 * result as a new numeric object. */
663 numeric numeric::mul(const numeric & other) const
665 static const numeric * _num1p=&_num1();
668 } else if (&other==_num1p) {
671 return numeric((*value)*(*other.value));
674 /** Numerical division method. Divides *this by argument and returns result as
675 * a new numeric object.
677 * @exception overflow_error (division by zero) */
678 numeric numeric::div(const numeric & other) const
680 if (::zerop(*other.value))
681 throw (std::overflow_error("division by zero"));
682 return numeric((*value)/(*other.value));
685 numeric numeric::power(const numeric & other) const
687 static const numeric * _num1p=&_num1();
690 if (::zerop(*value)) {
691 if (::zerop(*other.value))
692 throw (std::domain_error("numeric::eval(): pow(0,0) is undefined"));
693 else if (other.is_real() && !::plusp(::realpart(*other.value)))
694 throw (std::overflow_error("numeric::eval(): division by zero"));
698 return numeric(::expt(*value,*other.value));
701 /** Inverse of a number. */
702 numeric numeric::inverse(void) const
704 return numeric(::recip(*value)); // -> CLN
707 const numeric & numeric::add_dyn(const numeric & other) const
709 return static_cast<const numeric &>((new numeric((*value)+(*other.value)))->
710 setflag(status_flags::dynallocated));
713 const numeric & numeric::sub_dyn(const numeric & other) const
715 return static_cast<const numeric &>((new numeric((*value)-(*other.value)))->
716 setflag(status_flags::dynallocated));
719 const numeric & numeric::mul_dyn(const numeric & other) const
721 static const numeric * _num1p=&_num1();
724 } else if (&other==_num1p) {
727 return static_cast<const numeric &>((new numeric((*value)*(*other.value)))->
728 setflag(status_flags::dynallocated));
731 const numeric & numeric::div_dyn(const numeric & other) const
733 if (::zerop(*other.value))
734 throw (std::overflow_error("division by zero"));
735 return static_cast<const numeric &>((new numeric((*value)/(*other.value)))->
736 setflag(status_flags::dynallocated));
739 const numeric & numeric::power_dyn(const numeric & other) const
741 static const numeric * _num1p=&_num1();
744 if (::zerop(*value)) {
745 if (::zerop(*other.value))
746 throw (std::domain_error("numeric::eval(): pow(0,0) is undefined"));
747 else if (other.is_real() && !::plusp(::realpart(*other.value)))
748 throw (std::overflow_error("numeric::eval(): division by zero"));
752 return static_cast<const numeric &>((new numeric(::expt(*value,*other.value)))->
753 setflag(status_flags::dynallocated));
756 const numeric & numeric::operator=(int i)
758 return operator=(numeric(i));
761 const numeric & numeric::operator=(unsigned int i)
763 return operator=(numeric(i));
766 const numeric & numeric::operator=(long i)
768 return operator=(numeric(i));
771 const numeric & numeric::operator=(unsigned long i)
773 return operator=(numeric(i));
776 const numeric & numeric::operator=(double d)
778 return operator=(numeric(d));
781 const numeric & numeric::operator=(const char * s)
783 return operator=(numeric(s));
786 /** Return the complex half-plane (left or right) in which the number lies.
787 * csgn(x)==0 for x==0, csgn(x)==1 for Re(x)>0 or Re(x)=0 and Im(x)>0,
788 * csgn(x)==-1 for Re(x)<0 or Re(x)=0 and Im(x)<0.
790 * @see numeric::compare(const numeric & other) */
791 int numeric::csgn(void) const
795 if (!::zerop(::realpart(*value))) {
796 if (::plusp(::realpart(*value)))
801 if (::plusp(::imagpart(*value)))
808 /** This method establishes a canonical order on all numbers. For complex
809 * numbers this is not possible in a mathematically consistent way but we need
810 * to establish some order and it ought to be fast. So we simply define it
811 * to be compatible with our method csgn.
813 * @return csgn(*this-other)
814 * @see numeric::csgn(void) */
815 int numeric::compare(const numeric & other) const
817 // Comparing two real numbers?
818 if (this->is_real() && other.is_real())
819 // Yes, just compare them
820 return ::cl_compare(The(cl_R)(*value), The(cl_R)(*other.value));
822 // No, first compare real parts
823 cl_signean real_cmp = ::cl_compare(::realpart(*value), ::realpart(*other.value));
827 return ::cl_compare(::imagpart(*value), ::imagpart(*other.value));
831 bool numeric::is_equal(const numeric & other) const
833 return (*value == *other.value);
836 /** True if object is zero. */
837 bool numeric::is_zero(void) const
839 return ::zerop(*value); // -> CLN
842 /** True if object is not complex and greater than zero. */
843 bool numeric::is_positive(void) const
846 return ::plusp(The(cl_R)(*value)); // -> CLN
850 /** True if object is not complex and less than zero. */
851 bool numeric::is_negative(void) const
854 return ::minusp(The(cl_R)(*value)); // -> CLN
858 /** True if object is a non-complex integer. */
859 bool numeric::is_integer(void) const
861 return ::instanceof(*value, cl_I_ring); // -> CLN
864 /** True if object is an exact integer greater than zero. */
865 bool numeric::is_pos_integer(void) const
867 return (this->is_integer() && ::plusp(The(cl_I)(*value))); // -> CLN
870 /** True if object is an exact integer greater or equal zero. */
871 bool numeric::is_nonneg_integer(void) const
873 return (this->is_integer() && !::minusp(The(cl_I)(*value))); // -> CLN
876 /** True if object is an exact even integer. */
877 bool numeric::is_even(void) const
879 return (this->is_integer() && ::evenp(The(cl_I)(*value))); // -> CLN
882 /** True if object is an exact odd integer. */
883 bool numeric::is_odd(void) const
885 return (this->is_integer() && ::oddp(The(cl_I)(*value))); // -> CLN
888 /** Probabilistic primality test.
890 * @return true if object is exact integer and prime. */
891 bool numeric::is_prime(void) const
893 return (this->is_integer() && ::isprobprime(The(cl_I)(*value))); // -> CLN
896 /** True if object is an exact rational number, may even be complex
897 * (denominator may be unity). */
898 bool numeric::is_rational(void) const
900 return ::instanceof(*value, cl_RA_ring); // -> CLN
903 /** True if object is a real integer, rational or float (but not complex). */
904 bool numeric::is_real(void) const
906 return ::instanceof(*value, cl_R_ring); // -> CLN
909 bool numeric::operator==(const numeric & other) const
911 return (*value == *other.value); // -> CLN
914 bool numeric::operator!=(const numeric & other) const
916 return (*value != *other.value); // -> CLN
919 /** True if object is element of the domain of integers extended by I, i.e. is
920 * of the form a+b*I, where a and b are integers. */
921 bool numeric::is_cinteger(void) const
923 if (::instanceof(*value, cl_I_ring))
925 else if (!this->is_real()) { // complex case, handle n+m*I
926 if (::instanceof(::realpart(*value), cl_I_ring) &&
927 ::instanceof(::imagpart(*value), cl_I_ring))
933 /** True if object is an exact rational number, may even be complex
934 * (denominator may be unity). */
935 bool numeric::is_crational(void) const
937 if (::instanceof(*value, cl_RA_ring))
939 else if (!this->is_real()) { // complex case, handle Q(i):
940 if (::instanceof(::realpart(*value), cl_RA_ring) &&
941 ::instanceof(::imagpart(*value), cl_RA_ring))
947 /** Numerical comparison: less.
949 * @exception invalid_argument (complex inequality) */
950 bool numeric::operator<(const numeric & other) const
952 if (this->is_real() && other.is_real())
953 return (The(cl_R)(*value) < The(cl_R)(*other.value)); // -> CLN
954 throw (std::invalid_argument("numeric::operator<(): complex inequality"));
955 return false; // make compiler shut up
958 /** Numerical comparison: less or equal.
960 * @exception invalid_argument (complex inequality) */
961 bool numeric::operator<=(const numeric & other) const
963 if (this->is_real() && other.is_real())
964 return (The(cl_R)(*value) <= The(cl_R)(*other.value)); // -> CLN
965 throw (std::invalid_argument("numeric::operator<=(): complex inequality"));
966 return false; // make compiler shut up
969 /** Numerical comparison: greater.
971 * @exception invalid_argument (complex inequality) */
972 bool numeric::operator>(const numeric & other) const
974 if (this->is_real() && other.is_real())
975 return (The(cl_R)(*value) > The(cl_R)(*other.value)); // -> CLN
976 throw (std::invalid_argument("numeric::operator>(): complex inequality"));
977 return false; // make compiler shut up
980 /** Numerical comparison: greater or equal.
982 * @exception invalid_argument (complex inequality) */
983 bool numeric::operator>=(const numeric & other) const
985 if (this->is_real() && other.is_real())
986 return (The(cl_R)(*value) >= The(cl_R)(*other.value)); // -> CLN
987 throw (std::invalid_argument("numeric::operator>=(): complex inequality"));
988 return false; // make compiler shut up
991 /** Converts numeric types to machine's int. You should check with
992 * is_integer() if the number is really an integer before calling this method.
993 * You may also consider checking the range first. */
994 int numeric::to_int(void) const
996 GINAC_ASSERT(this->is_integer());
997 return ::cl_I_to_int(The(cl_I)(*value)); // -> CLN
1000 /** Converts numeric types to machine's long. You should check with
1001 * is_integer() if the number is really an integer before calling this method.
1002 * You may also consider checking the range first. */
1003 long numeric::to_long(void) const
1005 GINAC_ASSERT(this->is_integer());
1006 return ::cl_I_to_long(The(cl_I)(*value)); // -> CLN
1009 /** Converts numeric types to machine's double. You should check with is_real()
1010 * if the number is really not complex before calling this method. */
1011 double numeric::to_double(void) const
1013 GINAC_ASSERT(this->is_real());
1014 return ::cl_double_approx(::realpart(*value)); // -> CLN
1017 /** Real part of a number. */
1018 numeric numeric::real(void) const
1020 return numeric(::realpart(*value)); // -> CLN
1023 /** Imaginary part of a number. */
1024 numeric numeric::imag(void) const
1026 return numeric(::imagpart(*value)); // -> CLN
1030 // Unfortunately, CLN did not provide an official way to access the numerator
1031 // or denominator of a rational number (cl_RA). Doing some excavations in CLN
1032 // one finds how it works internally in src/rational/cl_RA.h:
1033 struct cl_heap_ratio : cl_heap {
1038 inline cl_heap_ratio* TheRatio (const cl_N& obj)
1039 { return (cl_heap_ratio*)(obj.pointer); }
1040 #endif // ndef SANE_LINKER
1042 /** Numerator. Computes the numerator of rational numbers, rationalized
1043 * numerator of complex if real and imaginary part are both rational numbers
1044 * (i.e numer(4/3+5/6*I) == 8+5*I), the number carrying the sign in all other
1046 numeric numeric::numer(void) const
1048 if (this->is_integer()) {
1049 return numeric(*this);
1052 else if (::instanceof(*value, cl_RA_ring)) {
1053 return numeric(::numerator(The(cl_RA)(*value)));
1055 else if (!this->is_real()) { // complex case, handle Q(i):
1056 cl_R r = ::realpart(*value);
1057 cl_R i = ::imagpart(*value);
1058 if (::instanceof(r, cl_I_ring) && ::instanceof(i, cl_I_ring))
1059 return numeric(*this);
1060 if (::instanceof(r, cl_I_ring) && ::instanceof(i, cl_RA_ring))
1061 return numeric(::complex(r*::denominator(The(cl_RA)(i)), ::numerator(The(cl_RA)(i))));
1062 if (::instanceof(r, cl_RA_ring) && ::instanceof(i, cl_I_ring))
1063 return numeric(::complex(::numerator(The(cl_RA)(r)), i*::denominator(The(cl_RA)(r))));
1064 if (::instanceof(r, cl_RA_ring) && ::instanceof(i, cl_RA_ring)) {
1065 cl_I s = ::lcm(::denominator(The(cl_RA)(r)), ::denominator(The(cl_RA)(i)));
1066 return numeric(::complex(::numerator(The(cl_RA)(r))*(exquo(s,::denominator(The(cl_RA)(r)))),
1067 ::numerator(The(cl_RA)(i))*(exquo(s,::denominator(The(cl_RA)(i))))));
1071 else if (instanceof(*value, cl_RA_ring)) {
1072 return numeric(TheRatio(*value)->numerator);
1074 else if (!this->is_real()) { // complex case, handle Q(i):
1075 cl_R r = ::realpart(*value);
1076 cl_R i = ::imagpart(*value);
1077 if (instanceof(r, cl_I_ring) && instanceof(i, cl_I_ring))
1078 return numeric(*this);
1079 if (instanceof(r, cl_I_ring) && instanceof(i, cl_RA_ring))
1080 return numeric(::complex(r*TheRatio(i)->denominator, TheRatio(i)->numerator));
1081 if (instanceof(r, cl_RA_ring) && instanceof(i, cl_I_ring))
1082 return numeric(::complex(TheRatio(r)->numerator, i*TheRatio(r)->denominator));
1083 if (instanceof(r, cl_RA_ring) && instanceof(i, cl_RA_ring)) {
1084 cl_I s = ::lcm(TheRatio(r)->denominator, TheRatio(i)->denominator);
1085 return numeric(::complex(TheRatio(r)->numerator*(exquo(s,TheRatio(r)->denominator)),
1086 TheRatio(i)->numerator*(exquo(s,TheRatio(i)->denominator))));
1089 #endif // def SANE_LINKER
1090 // at least one float encountered
1091 return numeric(*this);
1094 /** Denominator. Computes the denominator of rational numbers, common integer
1095 * denominator of complex if real and imaginary part are both rational numbers
1096 * (i.e denom(4/3+5/6*I) == 6), one in all other cases. */
1097 numeric numeric::denom(void) const
1099 if (this->is_integer()) {
1103 if (instanceof(*value, cl_RA_ring)) {
1104 return numeric(::denominator(The(cl_RA)(*value)));
1106 if (!this->is_real()) { // complex case, handle Q(i):
1107 cl_R r = ::realpart(*value);
1108 cl_R i = ::imagpart(*value);
1109 if (::instanceof(r, cl_I_ring) && ::instanceof(i, cl_I_ring))
1111 if (::instanceof(r, cl_I_ring) && ::instanceof(i, cl_RA_ring))
1112 return numeric(::denominator(The(cl_RA)(i)));
1113 if (::instanceof(r, cl_RA_ring) && ::instanceof(i, cl_I_ring))
1114 return numeric(::denominator(The(cl_RA)(r)));
1115 if (::instanceof(r, cl_RA_ring) && ::instanceof(i, cl_RA_ring))
1116 return numeric(::lcm(::denominator(The(cl_RA)(r)), ::denominator(The(cl_RA)(i))));
1119 if (instanceof(*value, cl_RA_ring)) {
1120 return numeric(TheRatio(*value)->denominator);
1122 if (!this->is_real()) { // complex case, handle Q(i):
1123 cl_R r = ::realpart(*value);
1124 cl_R i = ::imagpart(*value);
1125 if (instanceof(r, cl_I_ring) && instanceof(i, cl_I_ring))
1127 if (instanceof(r, cl_I_ring) && instanceof(i, cl_RA_ring))
1128 return numeric(TheRatio(i)->denominator);
1129 if (instanceof(r, cl_RA_ring) && instanceof(i, cl_I_ring))
1130 return numeric(TheRatio(r)->denominator);
1131 if (instanceof(r, cl_RA_ring) && instanceof(i, cl_RA_ring))
1132 return numeric(::lcm(TheRatio(r)->denominator, TheRatio(i)->denominator));
1134 #endif // def SANE_LINKER
1135 // at least one float encountered
1139 /** Size in binary notation. For integers, this is the smallest n >= 0 such
1140 * that -2^n <= x < 2^n. If x > 0, this is the unique n > 0 such that
1141 * 2^(n-1) <= x < 2^n.
1143 * @return number of bits (excluding sign) needed to represent that number
1144 * in two's complement if it is an integer, 0 otherwise. */
1145 int numeric::int_length(void) const
1147 if (this->is_integer())
1148 return ::integer_length(The(cl_I)(*value)); // -> CLN
1155 // static member variables
1160 unsigned numeric::precedence = 30;
1166 const numeric some_numeric;
1167 const type_info & typeid_numeric=typeid(some_numeric);
1168 /** Imaginary unit. This is not a constant but a numeric since we are
1169 * natively handing complex numbers anyways. */
1170 const numeric I = numeric(::complex(cl_I(0),cl_I(1)));
1173 /** Exponential function.
1175 * @return arbitrary precision numerical exp(x). */
1176 const numeric exp(const numeric & x)
1178 return ::exp(*x.value); // -> CLN
1182 /** Natural logarithm.
1184 * @param z complex number
1185 * @return arbitrary precision numerical log(x).
1186 * @exception overflow_error (logarithmic singularity) */
1187 const numeric log(const numeric & z)
1190 throw (std::overflow_error("log(): logarithmic singularity"));
1191 return ::log(*z.value); // -> CLN
1195 /** Numeric sine (trigonometric function).
1197 * @return arbitrary precision numerical sin(x). */
1198 const numeric sin(const numeric & x)
1200 return ::sin(*x.value); // -> CLN
1204 /** Numeric cosine (trigonometric function).
1206 * @return arbitrary precision numerical cos(x). */
1207 const numeric cos(const numeric & x)
1209 return ::cos(*x.value); // -> CLN
1213 /** Numeric tangent (trigonometric function).
1215 * @return arbitrary precision numerical tan(x). */
1216 const numeric tan(const numeric & x)
1218 return ::tan(*x.value); // -> CLN
1222 /** Numeric inverse sine (trigonometric function).
1224 * @return arbitrary precision numerical asin(x). */
1225 const numeric asin(const numeric & x)
1227 return ::asin(*x.value); // -> CLN
1231 /** Numeric inverse cosine (trigonometric function).
1233 * @return arbitrary precision numerical acos(x). */
1234 const numeric acos(const numeric & x)
1236 return ::acos(*x.value); // -> CLN
1242 * @param z complex number
1244 * @exception overflow_error (logarithmic singularity) */
1245 const numeric atan(const numeric & x)
1248 x.real().is_zero() &&
1249 !abs(x.imag()).is_equal(_num1()))
1250 throw (std::overflow_error("atan(): logarithmic singularity"));
1251 return ::atan(*x.value); // -> CLN
1257 * @param x real number
1258 * @param y real number
1259 * @return atan(y/x) */
1260 const numeric atan(const numeric & y, const numeric & x)
1262 if (x.is_real() && y.is_real())
1263 return ::atan(::realpart(*x.value), ::realpart(*y.value)); // -> CLN
1265 throw (std::invalid_argument("numeric::atan(): complex argument"));
1269 /** Numeric hyperbolic sine (trigonometric function).
1271 * @return arbitrary precision numerical sinh(x). */
1272 const numeric sinh(const numeric & x)
1274 return ::sinh(*x.value); // -> CLN
1278 /** Numeric hyperbolic cosine (trigonometric function).
1280 * @return arbitrary precision numerical cosh(x). */
1281 const numeric cosh(const numeric & x)
1283 return ::cosh(*x.value); // -> CLN
1287 /** Numeric hyperbolic tangent (trigonometric function).
1289 * @return arbitrary precision numerical tanh(x). */
1290 const numeric tanh(const numeric & x)
1292 return ::tanh(*x.value); // -> CLN
1296 /** Numeric inverse hyperbolic sine (trigonometric function).
1298 * @return arbitrary precision numerical asinh(x). */
1299 const numeric asinh(const numeric & x)
1301 return ::asinh(*x.value); // -> CLN
1305 /** Numeric inverse hyperbolic cosine (trigonometric function).
1307 * @return arbitrary precision numerical acosh(x). */
1308 const numeric acosh(const numeric & x)
1310 return ::acosh(*x.value); // -> CLN
1314 /** Numeric inverse hyperbolic tangent (trigonometric function).
1316 * @return arbitrary precision numerical atanh(x). */
1317 const numeric atanh(const numeric & x)
1319 return ::atanh(*x.value); // -> CLN
1323 /** Numeric evaluation of Riemann's Zeta function. Currently works only for
1324 * integer arguments. */
1325 const numeric zeta(const numeric & x)
1327 // A dirty hack to allow for things like zeta(3.0), since CLN currently
1328 // only knows about integer arguments and zeta(3).evalf() automatically
1329 // cascades down to zeta(3.0).evalf(). The trick is to rely on 3.0-3
1330 // being an exact zero for CLN, which can be tested and then we can just
1331 // pass the number casted to an int:
1333 int aux = (int)(::cl_double_approx(::realpart(*x.value)));
1334 if (zerop(*x.value-aux))
1335 return ::cl_zeta(aux); // -> CLN
1337 clog << "zeta(" << x
1338 << "): Does anybody know good way to calculate this numerically?"
1344 /** The gamma function.
1345 * This is only a stub! */
1346 const numeric gamma(const numeric & x)
1348 clog << "gamma(" << x
1349 << "): Does anybody know good way to calculate this numerically?"
1355 /** The psi function (aka polygamma function).
1356 * This is only a stub! */
1357 const numeric psi(const numeric & x)
1360 << "): Does anybody know good way to calculate this numerically?"
1366 /** The psi functions (aka polygamma functions).
1367 * This is only a stub! */
1368 const numeric psi(const numeric & n, const numeric & x)
1370 clog << "psi(" << n << "," << x
1371 << "): Does anybody know good way to calculate this numerically?"
1377 /** Factorial combinatorial function.
1379 * @param n integer argument >= 0
1380 * @exception range_error (argument must be integer >= 0) */
1381 const numeric factorial(const numeric & n)
1383 if (!n.is_nonneg_integer())
1384 throw (std::range_error("numeric::factorial(): argument must be integer >= 0"));
1385 return numeric(::factorial(n.to_int())); // -> CLN
1389 /** The double factorial combinatorial function. (Scarcely used, but still
1390 * useful in cases, like for exact results of Gamma(n+1/2) for instance.)
1392 * @param n integer argument >= -1
1393 * @return n!! == n * (n-2) * (n-4) * ... * ({1|2}) with 0!! == (-1)!! == 1
1394 * @exception range_error (argument must be integer >= -1) */
1395 const numeric doublefactorial(const numeric & n)
1397 if (n == numeric(-1)) {
1400 if (!n.is_nonneg_integer()) {
1401 throw (std::range_error("numeric::doublefactorial(): argument must be integer >= -1"));
1403 return numeric(::doublefactorial(n.to_int())); // -> CLN
1407 /** The Binomial coefficients. It computes the binomial coefficients. For
1408 * integer n and k and positive n this is the number of ways of choosing k
1409 * objects from n distinct objects. If n is negative, the formula
1410 * binomial(n,k) == (-1)^k*binomial(k-n-1,k) is used to compute the result. */
1411 const numeric binomial(const numeric & n, const numeric & k)
1413 if (n.is_integer() && k.is_integer()) {
1414 if (n.is_nonneg_integer()) {
1415 if (k.compare(n)!=1 && k.compare(_num0())!=-1)
1416 return numeric(::binomial(n.to_int(),k.to_int())); // -> CLN
1420 return _num_1().power(k)*binomial(k-n-_num1(),k);
1424 // should really be gamma(n+1)/(gamma(r+1)/gamma(n-r+1) or a suitable limit
1425 throw (std::range_error("numeric::binomial(): don´t know how to evaluate that."));
1429 /** Bernoulli number. The nth Bernoulli number is the coefficient of x^n/n!
1430 * in the expansion of the function x/(e^x-1).
1432 * @return the nth Bernoulli number (a rational number).
1433 * @exception range_error (argument must be integer >= 0) */
1434 const numeric bernoulli(const numeric & nn)
1436 if (!nn.is_integer() || nn.is_negative())
1437 throw (std::range_error("numeric::bernoulli(): argument must be integer >= 0"));
1440 if (!nn.compare(_num1()))
1441 return numeric(-1,2);
1444 // Until somebody has the Blues and comes up with a much better idea and
1445 // codes it (preferably in CLN) we make this a remembering function which
1446 // computes its results using the formula
1447 // B(nn) == - 1/(nn+1) * sum_{k=0}^{nn-1}(binomial(nn+1,k)*B(k))
1449 static vector<numeric> results;
1450 static int highest_result = -1;
1451 int n = nn.sub(_num2()).div(_num2()).to_int();
1452 if (n <= highest_result)
1454 if (results.capacity() < (unsigned)(n+1))
1455 results.reserve(n+1);
1457 numeric tmp; // used to store the sum
1458 for (int i=highest_result+1; i<=n; ++i) {
1459 // the first two elements:
1460 tmp = numeric(-2*i-1,2);
1461 // accumulate the remaining elements:
1462 for (int j=0; j<i; ++j)
1463 tmp += binomial(numeric(2*i+3),numeric(j*2+2))*results[j];
1464 // divide by -(nn+1) and store result:
1465 results.push_back(-tmp/numeric(2*i+3));
1472 /** Fibonacci number. The nth Fibonacci number F(n) is defined by the
1473 * recurrence formula F(n)==F(n-1)+F(n-2) with F(0)==0 and F(1)==1.
1475 * @param n an integer
1476 * @return the nth Fibonacci number F(n) (an integer number)
1477 * @exception range_error (argument must be an integer) */
1478 const numeric fibonacci(const numeric & n)
1480 if (!n.is_integer()) {
1481 throw (std::range_error("numeric::fibonacci(): argument must be integer"));
1483 // For positive arguments compute the nearest integer to
1484 // ((1+sqrt(5))/2)^n/sqrt(5). For negative arguments, apply an additional
1485 // sign. Note that we are falling back to longs, but this should suffice
1488 const long nn = ::abs(n.to_double());
1489 if (n.is_negative() && n.is_even())
1492 // Need a precision of ((1+sqrt(5))/2)^-n.
1493 cl_float_format_t prec = ::cl_float_format((int)(0.208987641*nn+5));
1494 cl_R sqrt5 = ::sqrt(::cl_float(5,prec));
1495 cl_R phi = (1+sqrt5)/2;
1496 return numeric(::round1(::expt(phi,nn)/sqrt5)*sig);
1500 /** Absolute value. */
1501 numeric abs(const numeric & x)
1503 return ::abs(*x.value); // -> CLN
1507 /** Modulus (in positive representation).
1508 * In general, mod(a,b) has the sign of b or is zero, and rem(a,b) has the
1509 * sign of a or is zero. This is different from Maple's modp, where the sign
1510 * of b is ignored. It is in agreement with Mathematica's Mod.
1512 * @return a mod b in the range [0,abs(b)-1] with sign of b if both are
1513 * integer, 0 otherwise. */
1514 numeric mod(const numeric & a, const numeric & b)
1516 if (a.is_integer() && b.is_integer())
1517 return ::mod(The(cl_I)(*a.value), The(cl_I)(*b.value)); // -> CLN
1519 return _num0(); // Throw?
1523 /** Modulus (in symmetric representation).
1524 * Equivalent to Maple's mods.
1526 * @return a mod b in the range [-iquo(abs(m)-1,2), iquo(abs(m),2)]. */
1527 numeric smod(const numeric & a, const numeric & b)
1529 if (a.is_integer() && b.is_integer()) {
1530 cl_I b2 = The(cl_I)(ceiling1(The(cl_I)(*b.value) / 2)) - 1;
1531 return ::mod(The(cl_I)(*a.value) + b2, The(cl_I)(*b.value)) - b2;
1533 return _num0(); // Throw?
1537 /** Numeric integer remainder.
1538 * Equivalent to Maple's irem(a,b) as far as sign conventions are concerned.
1539 * In general, mod(a,b) has the sign of b or is zero, and irem(a,b) has the
1540 * sign of a or is zero.
1542 * @return remainder of a/b if both are integer, 0 otherwise. */
1543 numeric irem(const numeric & a, const numeric & b)
1545 if (a.is_integer() && b.is_integer())
1546 return ::rem(The(cl_I)(*a.value), The(cl_I)(*b.value)); // -> CLN
1548 return _num0(); // Throw?
1552 /** Numeric integer remainder.
1553 * Equivalent to Maple's irem(a,b,'q') it obeyes the relation
1554 * irem(a,b,q) == a - q*b. In general, mod(a,b) has the sign of b or is zero,
1555 * and irem(a,b) has the sign of a or is zero.
1557 * @return remainder of a/b and quotient stored in q if both are integer,
1559 numeric irem(const numeric & a, const numeric & b, numeric & q)
1561 if (a.is_integer() && b.is_integer()) { // -> CLN
1562 cl_I_div_t rem_quo = truncate2(The(cl_I)(*a.value), The(cl_I)(*b.value));
1563 q = rem_quo.quotient;
1564 return rem_quo.remainder;
1568 return _num0(); // Throw?
1573 /** Numeric integer quotient.
1574 * Equivalent to Maple's iquo as far as sign conventions are concerned.
1576 * @return truncated quotient of a/b if both are integer, 0 otherwise. */
1577 numeric iquo(const numeric & a, const numeric & b)
1579 if (a.is_integer() && b.is_integer())
1580 return truncate1(The(cl_I)(*a.value), The(cl_I)(*b.value)); // -> CLN
1582 return _num0(); // Throw?
1586 /** Numeric integer quotient.
1587 * Equivalent to Maple's iquo(a,b,'r') it obeyes the relation
1588 * r == a - iquo(a,b,r)*b.
1590 * @return truncated quotient of a/b and remainder stored in r if both are
1591 * integer, 0 otherwise. */
1592 numeric iquo(const numeric & a, const numeric & b, numeric & r)
1594 if (a.is_integer() && b.is_integer()) { // -> CLN
1595 cl_I_div_t rem_quo = truncate2(The(cl_I)(*a.value), The(cl_I)(*b.value));
1596 r = rem_quo.remainder;
1597 return rem_quo.quotient;
1600 return _num0(); // Throw?
1605 /** Numeric square root.
1606 * If possible, sqrt(z) should respect squares of exact numbers, i.e. sqrt(4)
1607 * should return integer 2.
1609 * @param z numeric argument
1610 * @return square root of z. Branch cut along negative real axis, the negative
1611 * real axis itself where imag(z)==0 and real(z)<0 belongs to the upper part
1612 * where imag(z)>0. */
1613 numeric sqrt(const numeric & z)
1615 return ::sqrt(*z.value); // -> CLN
1619 /** Integer numeric square root. */
1620 numeric isqrt(const numeric & x)
1622 if (x.is_integer()) {
1624 ::isqrt(The(cl_I)(*x.value), &root); // -> CLN
1627 return _num0(); // Throw?
1631 /** Greatest Common Divisor.
1633 * @return The GCD of two numbers if both are integer, a numerical 1
1634 * if they are not. */
1635 numeric gcd(const numeric & a, const numeric & b)
1637 if (a.is_integer() && b.is_integer())
1638 return ::gcd(The(cl_I)(*a.value), The(cl_I)(*b.value)); // -> CLN
1644 /** Least Common Multiple.
1646 * @return The LCM of two numbers if both are integer, the product of those
1647 * two numbers if they are not. */
1648 numeric lcm(const numeric & a, const numeric & b)
1650 if (a.is_integer() && b.is_integer())
1651 return ::lcm(The(cl_I)(*a.value), The(cl_I)(*b.value)); // -> CLN
1653 return *a.value * *b.value;
1657 /** Floating point evaluation of Archimedes' constant Pi. */
1660 return numeric(::cl_pi(cl_default_float_format)); // -> CLN
1664 /** Floating point evaluation of Euler's constant Gamma. */
1665 ex EulerGammaEvalf(void)
1667 return numeric(::cl_eulerconst(cl_default_float_format)); // -> CLN
1671 /** Floating point evaluation of Catalan's constant. */
1672 ex CatalanEvalf(void)
1674 return numeric(::cl_catalanconst(cl_default_float_format)); // -> CLN
1678 // It initializes to 17 digits, because in CLN cl_float_format(17) turns out to
1679 // be 61 (<64) while cl_float_format(18)=65. We want to have a cl_LF instead
1680 // of cl_SF, cl_FF or cl_DF but everything else is basically arbitrary.
1681 _numeric_digits::_numeric_digits()
1686 cl_default_float_format = ::cl_float_format(17);
1690 _numeric_digits& _numeric_digits::operator=(long prec)
1693 cl_default_float_format = ::cl_float_format(prec);
1698 _numeric_digits::operator long()
1700 return (long)digits;
1704 void _numeric_digits::print(ostream & os) const
1706 debugmsg("_numeric_digits print", LOGLEVEL_PRINT);
1711 ostream& operator<<(ostream& os, const _numeric_digits & e)
1718 // static member variables
1723 bool _numeric_digits::too_late = false;
1726 /** Accuracy in decimal digits. Only object of this type! Can be set using
1727 * assignment from C++ unsigned ints and evaluated like any built-in type. */
1728 _numeric_digits Digits;
1730 #ifndef NO_NAMESPACE_GINAC
1731 } // namespace GiNaC
1732 #endif // ndef NO_NAMESPACE_GINAC