octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MSVC compilation problem: std::abs<int64_t> does not exist


From: Abdelrazak Younes
Subject: Re: MSVC compilation problem: std::abs<int64_t> does not exist
Date: Thu, 30 Oct 2008 18:35:08 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b1pre) Gecko/20081006 Shredder/3.0a3

On 30/10/2008 18:21, John W. Eaton wrote:
On 30-Oct-2008, Abdelrazak Younes wrote:

| On 30/10/2008 16:04, Michael Goffioul wrote:
|>  As the subject says, there's no specialization of abs for int64_t type
|>  in MSVC. Any idea on how to fix this?
|>  (Problem occurs in oct-inttypes.h, line 697).
|
| template<typename T>  T abs(T t) { return t>  0 ? t : -t; }

That's buggy on my system.

For example, try the following program:

   #include<iostream>
   #include<climits>

   template<typename T>
   T
   abs (T t)
   {
     return t>  0 ? t : -t;
   }

   int
   main (void)
   {
     std::cout<<  LLONG_MAX<<  std::endl;
     std::cout<<  LLONG_MIN<<  ", "<<  abs (LLONG_MIN)<<  std::endl;
     std::cout<<  LLONG_MIN+1<<  ", "<<  abs (LLONG_MIN+1)<<  std::endl;

I indeed get this with MSVC2008 on Windows vista:

9223372036854775807
-9223372036854775808, -9223372036854775808
-9223372036854775807, 9223372036854775807

But looking at the definition of those macro, this is not too surprising:

#define LONG_MIN    (-2147483647L - 1) /* minimum (signed) long value */
#define LONG_MAX      2147483647L   /* maximum (signed) long value */

I guess LONG_MIN is meant for comparison not really for being used as a value. But I am far from an expert...

Abdel.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]