std::isinf(-inf) strange results

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

 



Is this the expected behaviour when std::isinf(-inf) yields 0 or -1
instead of 1?
Consider the source:

#include <iostream>
#include <limits>
#include <cmath>
int main() {
    std::cout << "   ::isinf, long d = " <<
::isinf(-std::numeric_limits<long double>::infinity()) << std::endl
              << "   ::isinf, double = " <<
::isinf(-std::numeric_limits<     double>::infinity()) << std::endl
              << "   ::isinf, float  = " <<
::isinf(-std::numeric_limits<     float >::infinity()) << std::endl
              << "std::isinf, long d = " <<
std::isinf(-std::numeric_limits<long double>::infinity()) << std::endl
              << "std::isinf, double = " <<
std::isinf(-std::numeric_limits<     double>::infinity()) << std::endl
              << "std::isinf, float  = " <<
std::isinf(-std::numeric_limits<     float >::infinity()) <<
std::endl;
    return 0;
}

$ # this is expected, everything`s all right
$ g++ test.cpp
$ ./a.out
   ::isinf, long d = 1
   ::isinf, double = 1
   ::isinf, float  = 1
std::isinf, long d = 1
std::isinf, double = 1
std::isinf, float  = 1

$ # now let`s force -lm ... things begin to get weird
$ g++ -fno-builtin-isinf -lm test.cpp
$ ./a.out
   ::isinf, long d = -1
   ::isinf, double = -1
   ::isinf, float  = -1
std::isinf, long d = 1
std::isinf, double = -1
std::isinf, float  = 1

$ # and now to insanity and beyond:
$ g++ -Ofast test.cpp
$ ./a.out
   ::isinf, long d = -1
   ::isinf, double = -1
   ::isinf, float  = -1
std::isinf, long d = 0
std::isinf, double = -1
std::isinf, float  = 0

Granted, -Ofast is allowed to disregard some standards in favor of
performance... but is it allowed to produce code that is plain wrong?
Furthermore, std::isinf sometimes takes the output of isinf from the
math library without casting it to bool, which, as far as I know,
doesn`t comply to the standard.
The question is whether I should report any of this as a GCC bug.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux