Login  Register

Re: Some trouble with qldefines.hpp

Posted by Luigi Ballabio-4 on Oct 31, 2001; 5:24am
URL: http://quantlib.414.s1.nabble.com/Some-trouble-with-qldefines-hpp-tp1787p1794.html

At 11:39 AM 10/31/01 +0100, Nicolas Di Césaré wrote:
>Hi all,
>
>I have some trouble with numeric_limits<>::max() under visual C++. It
>conflicts with macro max.

Oh, yes, of course. Visual C++ does not supply std::max, but defines a max
macro instead. Absolute genius. Not.

>I am not able to provide a simple example where it occurs but
>it seems to work with the following changes (the whole file is in
>attachement):
>
>#if defined HAVE_LIMITS
>     #include <limits>
>     #define QL_MIN_INT      (int)(std::numeric_limits<int>::min)()
>     #define QL_MAX_INT      (int)(std::numeric_limits<int>::max)()
>     #define QL_MIN_DOUBLE  -(double)(std::numeric_limits<double>::max)()
>     #define QL_MAX_DOUBLE   (double)(std::numeric_limits<double>::max)()
>     #define QL_EPSILON      (double)(std::numeric_limits<double>::epsilon)()
>     #define
> QL_MIN_POSITIVE_DOUBLE  (double)(std::numeric_limits<double>::min)()
>...

I have used your file with Borland C++ as well without any problem, and I
checked the modifications into CVS.

I'm curious, though: why are the (int) and (double) casts required? Maybe
in order to shield the function pointer from precedence problems between ()
and some operator before the macro? Would
#define QL_MIN_INT      ((std::numeric_limits<int>::min)())
#define QL_MAX_INT     ((std::numeric_limits<int>::max)())
#define QL_MIN_DOUBLE  -((std::numeric_limits<double>::max)())
...
work for you instead?

Bye,
         Luigi