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: Jaroslav Hajek
Subject: Re: MSVC compilation problem: std::abs<int64_t> does not exist
Date: Thu, 30 Oct 2008 18:37:10 +0100

On Thu, Oct 30, 2008 at 6:21 PM, John W. Eaton <address@hidden> 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;
>
>    return 0;
>  }
>

No, it's no more buggy than std::abs itself. The standard simply says
that the result is undefined if it is not representable, which is the
case of INT_MIN, LONG_MIN etc, given the most common two's complement
integers.

One option is to define our own abs and use that, other is to include
a configure check and define the missing overload (that's, for
instance, what Boost does).
In any case, I'd want to mark this as FIXME because I hope Microsofot
will add the missing overload eventually (it is not required by C++98,
if int64_t is longer than long, but it will probably be in C++0x).

Btw. Is it just my impression that MSVC exhibits a strange tendency to
complicate things with missing trivial "consistency extensions",
while, of course, providing a lot of shiny features?



> jwe
>



-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

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