barry@ADS.COM (05/18/89)
g++-1.35.0 from Labrea
libg++-1.35.0 also from Labrea
When compiling the files in the tests directory I run into one problem.
tRational.cc gets the following error:
(cd src; make GXX="g++" CC="gcc")
(cd tests; make GXX="g++" LIBDIR="/usr/local/gnu/lib")
g++ -g -O -fchar-charconst -I../g++-include -I. -fstrength-reduce -c tRational
.cc
In function void etest (long int):
tRational.cc:168: call of overloaded `log' is ambiguous
tRational.cc:169: call of overloaded `log' is ambiguous
*** Error code 1
The code in question:
void etest(long n)
{
cout << "approximating e as pow(1+1/n),n) for n =" << n << "\n";
Rational approxe = estimate_e(n);
assert(approxe.OK());
cout << "double(approxe) = " << double(approxe) << "\n";
cout << "log(approxe) = " << log(approxe) << "\n";
assert(log(approxe) <= 1.0);
cout << "approxe = " << approxe << "\n";
}
barry
dl@ROCKY.OSWEGO.EDU (Doug Lea) (05/20/89)
This was a problem in using `extern "C"' conventions in math-68881.h. Sorry. Andy Fyfe contributed this fix, which solves overloading problems, and also adds a few additional capabilities to math-68881.h -Doug --- math.h ----------------------------------------------------------- // This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) This file is part of GNU CC. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the GNU CC General Public License for full details. Everyone is granted permission to copy, modify and redistribute GNU CC, but only under the conditions described in the GNU CC General Public License. A copy of this license is supposed to have been given to you along with GNU CC so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ #ifndef _math_h #pragma once #define _math_h 1 overload acos; overload acosh; overload asin; overload asinh; overload atan2; overload atanh; overload ceil; overload cos; overload cosh; overload exp; overload floor; overload gamma; overload hypot; overload log; overload log10; overload pow; overload sin; overload sinh; overload sqrt; overload tan; overload tanh; #ifdef __HAVE_68881__ /* MC68881/2 Floating-Point Coprocessor */ #include <math-68881.h> extern "C" { /* fill in what we've left out */ double acosh(double); double asinh(double); double cbrt(double); double copysign(double,double); double erf(double); double erfc(double); double finite(double); double gamma(double); double hypot(double,double); double infnan(int); int isinf(double); int isnan(double); double j0(double); double j1(double); double jn(int, double); double lgamma(double); double y0(double); double y1(double); double yn(int, double); } /* Please add inline asm code for other machines here! */ #else extern "C" { double acos(double); double acosh(double); double asin(double); double asinh(double); double atan(double); double atan2(double, double); double atanh(double); double cbrt(double); double ceil(double); double copysign(double,double); double cos(double); double cosh(double); double drem(double,double); double erf(double); double erfc(double); double exp(double); double expm1(double); double fabs(double); double finite(double); double floor(double); double frexp(double, int*); double gamma(double); double hypot(double,double); double infnan(int); int isinf(double); int isnan(double); double j0(double); double j1(double); double jn(int, double); double ldexp(double, int); double lgamma(double); double log(double); double log10(double); double log1p(double); double logb(double); double modf(double, double*); double pow(double, double); double rint(double); double scalb(double, int); double sin(double); double sinh(double); double sqrt(double); double tan(double); double tanh(double); double y0(double); double y1(double); double yn(int, double); } #endif /* libg++ doesn't use this since it is not available on some systems */ /* the following ifdef is just for compiling OOPS */ #ifndef DONT_DECLARE_EXCEPTION struct exception { int type; char* name; double arg1, arg2, retval; }; #define DOMAIN 1 #define SING 2 #define OVERFLOW 3 #define UNDERFLOW 4 #define TLOSS 5 #define PLOSS 6 extern "C" int matherr(exception*); #endif #include <values.h> /* On some systems, HUGE ought to be MAXFLOAT or IEEE infinity */ #ifndef HUGE #define HUGE MAXDOUBLE #endif /* These seem to be sun & sysV names of these constants */ #ifndef M_E #define M_E 2.7182818284590452354 #endif #ifndef M_LOG2E #define M_LOG2E 1.4426950408889634074 #endif #ifndef M_LOG10E #define M_LOG10E 0.43429448190325182765 #endif #ifndef M_LN2 #define M_LN2 0.69314718055994530942 #endif #ifndef M_LN10 #define M_LN10 2.30258509299404568402 #endif #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef M_PI_2 #define M_PI_2 1.57079632679489661923 #endif #ifndef M_1_PI #define M_1_PI 0.31830988618379067154 #endif #ifndef M_PI_4 #define M_PI_4 0.78539816339744830962 #endif #ifndef M_2_PI #define M_2_PI 0.63661977236758134308 #endif #ifndef M_2_SQRTPI #define M_2_SQRTPI 1.12837916709551257390 #endif #ifndef M_SQRT2 #define M_SQRT2 1.41421356237309504880 #endif #ifndef M_SQRT1_2 #define M_SQRT1_2 0.70710678118654752440 #endif #ifndef PI // as in stroustrup #define PI M_PI #endif #ifndef PI2 #define PI2 M_PI_2 #endif #endif --- math-68881.h ----------------------------------------------------- /******************************************************************\ * * * <math-68881.h> last modified: 18 May 1989. * * * * Copyright (C) 1989 by Matthew Self. * * You may freely distribute verbatim copies of this software * * provided that this copyright notice is retained in all copies. * * You may distribute modifications to this software under the * * conditions above if you also clearly note such modifications * * with their author and date. * * * * Note: errno is not set to EDOM when domain errors occur for * * most of these functions. Rather, it is assumed that the * * 68881's OPERR exception will be enabled and handled * * appropriately by the operating system. Similarly, overflow * * and underflow do not set errno to ERANGE. * * * * Send bugs to Matthew Self (self@bayes.arc.nasa.gov). * * * \******************************************************************/ #include <errno.h> #ifndef HUGE_VAL #define HUGE_VAL \ ({ \ double huge_val; \ \ __asm ("fmove%.d #0x7ff0000000000000,%0" /* Infinity */ \ : "=f" (huge_val) \ : /* no inputs */); \ huge_val; \ }) #endif __inline static const double sin (double x) { double value; __asm ("fsin%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double cos (double x) { double value; __asm ("fcos%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double tan (double x) { double value; __asm ("ftan%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double asin (double x) { double value; __asm ("fasin%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double acos (double x) { double value; __asm ("facos%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double atan (double x) { double value; __asm ("fatan%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double atan2 (double y, double x) { double pi, pi_over_2; __asm ("fmovecr%.x %#0,%0" /* extended precision pi */ : "=f" (pi) : /* no inputs */ ); __asm ("fscale%.b %#-1,%0" /* no loss of accuracy */ : "=f" (pi_over_2) : "0" (pi)); if (x > 0) { if (y > 0) { if (x > y) return atan (y / x); else return pi_over_2 - atan (x / y); } else { if (x > -y) return atan (y / x); else return - pi_over_2 - atan (x / y); } } else { if (y > 0) { if (-x > y) return pi + atan (y / x); else return pi_over_2 - atan (x / y); } else { if (-x > -y) return - pi + atan (y / x); else if (y < 0) return - pi_over_2 - atan (x / y); else { double value; errno = EDOM; __asm ("fmove%.d %#0rnan,%0" /* quiet NaN */ : "=f" (value) : /* no inputs */); return value; } } } } __inline static const double sinh (double x) { double value; __asm ("fsinh%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double cosh (double x) { double value; __asm ("fcosh%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double tanh (double x) { double value; __asm ("ftanh%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double atanh (double x) { double value; __asm ("fatanh%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double exp (double x) { double value; __asm ("fetox%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double expm1 (double x) { double value; __asm ("fetoxm1%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double log (double x) { double value; __asm ("flogn%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double log1p (double x) { double value; __asm ("flognp1%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double log10 (double x) { double value; __asm ("flog10%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double sqrt (double x) { double value; __asm ("fsqrt%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double pow (const double x, const double y) { if (x > 0) return exp (y * log (x)); else if (x == 0) { if (y > 0) return 0.0; else { double value; errno = EDOM; __asm ("fmove%.d %#0rnan,%0" /* quiet NaN */ : "=f" (value) : /* no inputs */); return value; } } else { double temp; __asm ("fintrz%.x %1,%0" : "=f" (temp) /* integer-valued float */ : "f" (y)); if (y == temp) { int i = (int) y; if (i & 1 == 0) /* even */ return exp (y * log (x)); else return - exp (y * log (x)); } else { double value; errno = EDOM; __asm ("fmove%.d %#0rnan,%0" /* quiet NaN */ : "=f" (value) : /* no inputs */); return value; } } } __inline static const double fabs (double x) { double value; __asm ("fabs%.x %1,%0" : "=f" (value) : "f" (x)); return value; } __inline static const double ceil (double x) { int rounding_mode, round_up; double value; __asm volatile ("fmove%.l fpcr,%0" : "=dm" (rounding_mode) : /* no inputs */ ); round_up = rounding_mode | 0x30; __asm volatile ("fmove%.l %0,fpcr" : /* no outputs */ : "dmi" (round_up)); __asm volatile ("fint%.x %1,%0" : "=f" (value) : "f" (x)); __asm volatile ("fmove%.l %0,fpcr" : /* no outputs */ : "dmi" (rounding_mode)); return value; } __inline static const double floor (double x) { int rounding_mode, round_down; double value; __asm volatile ("fmove%.l fpcr,%0" : "=dm" (rounding_mode) : /* no inputs */ ); round_down = (rounding_mode & ~0x10) | 0x20; __asm volatile ("fmove%.l %0,fpcr" : /* no outputs */ : "dmi" (round_down)); __asm volatile ("fint%.x %1,%0" : "=f" (value) : "f" (x)); __asm volatile ("fmove%.l %0,fpcr" : /* no outputs */ : "dmi" (rounding_mode)); return value; } __inline static const double rint (double x) { int rounding_mode, round_nearest; double value; __asm volatile ("fmove%.l fpcr,%0" : "=dm" (rounding_mode) : /* no inputs */ ); round_nearest = rounding_mode & ~0x30; __asm volatile ("fmove%.l %0,fpcr" : /* no outputs */ : "dmi" (round_nearest)); __asm volatile ("fint%.x %1,%0" : "=f" (value) : "f" (x)); __asm volatile ("fmove%.l %0,fpcr" : /* no outputs */ : "dmi" (rounding_mode)); return value; } __inline static const double fmod (double x, double y) { double value; __asm ("fmod%.x %2,%0" : "=f" (value) : "0" (x), "f" (y)); return value; } __inline static const double drem (double x, double y) { double value; __asm ("frem%.x %2,%0" : "=f" (value) : "0" (x), "f" (y)); return value; } __inline static const double scalb (double x, int n) { double value; __asm ("fscale%.l %2,%0" : "=f" (value) : "0" (x), "dmi" (n)); return value; } __inline static double logb (double x) { double exponent; __asm ("fgetexp%.x %1,%0" : "=f" (exponent) : "f" (x)); return exponent; } __inline static const double ldexp (double x, int n) { double value; __asm ("fscale%.l %2,%0" : "=f" (value) : "0" (x), "dmi" (n)); return value; } __inline static double frexp (double x, int *exp) { double float_exponent; int int_exponent; double mantissa; __asm ("fgetexp%.x %1,%0" : "=f" (float_exponent) /* integer-valued float */ : "f" (x)); int_exponent = (int) float_exponent; __asm ("fgetman%.x %1,%0" : "=f" (mantissa) /* 1.0 <= mantissa < 2.0 */ : "f" (x)); if (mantissa != 0) { __asm ("fscale%.b %#-1,%0" : "=f" (mantissa) /* mantissa /= 2.0 */ : "0" (mantissa)); int_exponent += 1; } *exp = int_exponent; return mantissa; } __inline static double modf (double x, double *ip) { double temp; __asm ("fintrz%.x %1,%0" : "=f" (temp) /* integer-valued float */ : "f" (x)); *ip = temp; return x - temp; }