Bill Press
05-27-2008, 09:51 AM
Davekw7x points out that the published version of nr3.h does not work properly with the ancient Visual Studio Version 6 (MSVC++ ver. 6) compiler. This is not really a bug, because that compiler was not ANSI/ISO compliant. There is no problem with Visual Studio 2003, Visual Studio 2005, g++ (3.4.6 or later), or any ANSI/ISO compliant compiler.
Nevertheless, with a couple of tweaks, we can fix the problems for users with the ancient MSVC++ ver. 6.
Change these lines:
template<class T>
inline const T &MAX(const T &a, const T &b)
{return b > a ? (b) : (a);}
inline float MAX(const double &a, const float &b)
{return b > a ? (b) : float(a);}
inline float MAX(const float &a, const double &b)
{return b > a ? float(b) : (a);}
template<class T>
inline const T &MIN(const T &a, const T &b)
{return b < a ? (b) : (a);}
inline float MIN(const double &a, const float &b)
{return b < a ? (b) : float(a);}
inline float MIN(const float &a, const double &b)
{return b < a ? float(b) : (a);}
to these
#if defined(_MSC_VER) && (_MSC_VER < 1300)
// special case of MSVC++ 6 and older compilers
double abs(double x) { return fabs(x); }
template<class T>
inline const T MAX(const T &a, const T &b)
{return b > a ? (b) : (a);}
template<class T>
inline const T MIN(const T &a, const T &b)
{return b < a ? (b) : (a);}
#else
// general case of ANSI/ISO compliant compilers
template<class T>
inline const T &MAX(const T &a, const T &b)
{return b > a ? (b) : (a);}
template<class T>
inline const T &MIN(const T &a, const T &b)
{return b < a ? (b) : (a);}
#endif /* _MSC_VER < 1300 */
We have made this change in the downloadable file at http://nr.com/codefile.php?nr3.
By the way, we're not sure whether these changes also need to be made for the old, but not ancient, MSVC++ ver. 7 = Visual Studio 2002, with _MSC_VER = 1300. If so, then the test should be for _MSC_VER < 1310 . Can someone check?
(For reference, Visual Studio 2003 has _MSC_VER = 1310; Visual Studio 2005 has _MSC_VER = 1400; Visual Studio 2008 has _MSC_VER = 1500.)
Nevertheless, with a couple of tweaks, we can fix the problems for users with the ancient MSVC++ ver. 6.
Change these lines:
template<class T>
inline const T &MAX(const T &a, const T &b)
{return b > a ? (b) : (a);}
inline float MAX(const double &a, const float &b)
{return b > a ? (b) : float(a);}
inline float MAX(const float &a, const double &b)
{return b > a ? float(b) : (a);}
template<class T>
inline const T &MIN(const T &a, const T &b)
{return b < a ? (b) : (a);}
inline float MIN(const double &a, const float &b)
{return b < a ? (b) : float(a);}
inline float MIN(const float &a, const double &b)
{return b < a ? float(b) : (a);}
to these
#if defined(_MSC_VER) && (_MSC_VER < 1300)
// special case of MSVC++ 6 and older compilers
double abs(double x) { return fabs(x); }
template<class T>
inline const T MAX(const T &a, const T &b)
{return b > a ? (b) : (a);}
template<class T>
inline const T MIN(const T &a, const T &b)
{return b < a ? (b) : (a);}
#else
// general case of ANSI/ISO compliant compilers
template<class T>
inline const T &MAX(const T &a, const T &b)
{return b > a ? (b) : (a);}
template<class T>
inline const T &MIN(const T &a, const T &b)
{return b < a ? (b) : (a);}
#endif /* _MSC_VER < 1300 */
We have made this change in the downloadable file at http://nr.com/codefile.php?nr3.
By the way, we're not sure whether these changes also need to be made for the old, but not ancient, MSVC++ ver. 7 = Visual Studio 2002, with _MSC_VER = 1300. If so, then the test should be for _MSC_VER < 1310 . Can someone check?
(For reference, Visual Studio 2003 has _MSC_VER = 1310; Visual Studio 2005 has _MSC_VER = 1400; Visual Studio 2008 has _MSC_VER = 1500.)