c++ - sqrt() error
- Jim Jennings (14/14) Mar 18 2003 todouble() converts two ints, a numerator and a denominator, into a doub...
- Nic Tiger (22/36) Mar 18 2003 Some of math functions, and sqrt among them, are #define'd in math.h.
- Jim Jennings (6/24) Mar 18 2003 Thank you, Nic.
todouble() converts two ints, a numerator and a denominator, into a double and returns it. When I try to take the square root of the double, I get the errors below. As hard as it is to believe STLport will only take the square root of a float and a long double. (See _cmath.h, which is included in cmath.) When I cast the return of todouble() to long double it worked. std::cout << "Fraction x is " << x << "\tsqrt x is "<< std::sqrt(x.todouble()) << std::endl; ^ ftest6.cpp(40) : Error: ambiguous reference to symbol Had: std::_inline_sqrt(float ) and: std::_inline_sqrt(long double ) frac6WR.cpp: ftest6.cpp: --- errorlevel 1
Mar 18 2003
Some of math functions, and sqrt among them, are #define'd in math.h. Defines serve to promote sqrt/sin/cos an other calls to intrinsic calls. But this surely prevents normal usage of STL. When ported Blitz to DMC++, I used the code below to suppress this errors: ----------- #include <math.h> #undef sin #undef cos #undef fabs #undef sqrt inline double cos (double x) { return _inline_cos(x);} inline double sin (double x) { return _inline_sin(x);} inline double fabs (double x) { return _inline_fabs(x);} inline double sqrt (double x) { return _inline_sqrt(x);} ------------ You should insert it before you make calls to std::sqrt. Or even simpler solution, write sqrt instead of std::sqrt. Nic Tiger. "Jim Jennings" <jwjenn mindspring.com> сообщил/сообщила в новостях следующее: news:b57s60$16lp$1 digitaldaemon.com...todouble() converts two ints, a numerator and a denominator, into a double and returns it. When I try to take the square root of the double, I gettheerrors below. As hard as it is to believe STLport will only take thesquareroot of a float and a long double. (See _cmath.h, which is included in cmath.) When I cast the return of todouble() to long double it worked. std::cout << "Fraction x is " << x << "\tsqrt x is "<< std::sqrt(x.todouble()) << std::endl; ^ ftest6.cpp(40) : Error: ambiguous reference to symbol Had: std::_inline_sqrt(float ) and: std::_inline_sqrt(long double ) frac6WR.cpp: ftest6.cpp: --- errorlevel 1
Mar 18 2003
Thank you, Nic. This works. I have filed this away, and will use it in the future. JIm "Nic Tiger" <nictiger progtech.ru> wrote in message news:b588j0$1gpb$1 digitaldaemon.com...Some of math functions, and sqrt among them, are #define'd in math.h. Defines serve to promote sqrt/sin/cos an other calls to intrinsic calls.Butthis surely prevents normal usage of STL. When ported Blitz to DMC++, I used the code below to suppress this errors: ----------- #include <math.h> #undef sin #undef cos #undef fabs #undef sqrt inline double cos (double x) { return _inline_cos(x);} inline double sin (double x) { return _inline_sin(x);} inline double fabs (double x) { return _inline_fabs(x);} inline double sqrt (double x) { return _inline_sqrt(x);} ------------ You should insert it before you make calls to std::sqrt. Or even simpler solution, write sqrt instead of std::sqrt. Nic Tiger.
Mar 18 2003