help-gplusplus
[Top][All Lists]
Advanced

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

Puzzling behaviour of `isnan' with -ffast-math


From: Lionel B
Subject: Puzzling behaviour of `isnan' with -ffast-math
Date: Thu, 3 Jul 2008 11:52:39 +0000 (UTC)
User-agent: Pan/0.132 (Waxed in Black)

Is this just because all bets are off with -ffast-math (i.e. undefined 
behaviour) or is there a problem here?

$ g++ -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: <basedir>/src/gcc-4.3.0/configure --disable-multilib
--prefix=<basedir>/gcc-4.3.0 --enable-version-specific-runtime-libs
--enable-__cxa_atexit --enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.3.0 (GCC) 

//-------------------------------------------------------------------------

#include <limits>
#include <cmath>
#include <iostream>

int main()
{
  double x = std::numeric_limits<double>::quiet_NaN();
  std::cout << "x = " << x << '\n';
  std::cout << "   ::nan() " << (   ::isnan(x) ? "nan" : "not nan") << '\n';
  std::cout << "std::nan() " << (std::isnan(x) ? "nan" : "not nan") << '\n';
}

//-------------------------------------------------------------------------

1) compiled with g++ -std=c++98 -ffast-math

Output:
-------
x = nan
   ::nan() nan
std::nan() not nan

2) compiled with g++ -ffast-math

Output:
-------
x = nan
   ::nan() not nan
std::nan() not nan

3) compiled with g++ -std=c++98 or just g++

Output:
-------
x = nan
   ::nan() nan
std::nan() nan

-- 
Lionel B


reply via email to

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