Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Numerical Recipes Official Announcements > Official Bug Reports (NR3, the Third Edition)

Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2008, 09:51 AM
Bill Press Bill Press is offline
Numerical Recipes Author
 
Join Date: Dec 2001
Posts: 227
nr3.h: fixes for compatiblity with older (non-ANSI/ISO) compilers

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:
Code:
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

Code:
#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.)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:10 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.