diff --git a/src/TNL/Math.h b/src/TNL/Math.h
index 67e9f5e082af0b238e1d045bc516bf578efe82a0..2d81bea6678a41508ea8a1bdfa19d93b0c831c01 100644
--- a/src/TNL/Math.h
+++ b/src/TNL/Math.h
@@ -168,6 +168,24 @@ T sign( const T& a )
    return ( T ) 1;
 }
 
+template< class T >
+__cuda_callable__
+bool isNan( const T& v )
+{
+#if defined HAVE_CUDA
+   #if defined(__CUDA_ARCH__)
+      return isnan( v );
+   #else
+      #if defined (__GNUC__) && ( __GNUC__  < 5 )
+         return false;
+      #else
+         return std::isnan( v );
+      #endif
+   #endif
+#else
+   return std::isnan( v );
+#endif
+}
 template< typename Real >
 __cuda_callable__
 bool isSmall( const Real& v,
diff --git a/src/TNL/Solvers/IterativeSolver_impl.h b/src/TNL/Solvers/IterativeSolver_impl.h
index 333c38cd44a54478d01b439dbc27780711b44ac1..e65b3cdd412c899b6803b2129f193c9846c05766 100644
--- a/src/TNL/Solvers/IterativeSolver_impl.h
+++ b/src/TNL/Solvers/IterativeSolver_impl.h
@@ -107,7 +107,7 @@ bool IterativeSolver< Real, Index> :: checkNextIteration()
 {
    this->refreshSolverMonitor();
 
-   if( std::isnan( this->getResidue() ) ||
+   if( isNan( this->getResidue() ) ||
        this->getIterations() > this->getMaxIterations()  ||
        ( this->getResidue() > this->getDivergenceResidue() && this->getIterations() >= this->getMinIterations() ) ||
        ( this->getResidue() < this->getConvergenceResidue() && this->getIterations() >= this->getMinIterations() ) )
@@ -120,7 +120,7 @@ bool
 IterativeSolver< Real, Index>::
 checkConvergence()
 {
-   if( std::isnan( this->getResidue() ) )
+   if( isNan( this->getResidue() ) )
    {
       std::cerr << std::endl << "The residue is NaN." << std::endl;
       return false;
diff --git a/src/TNL/Solvers/Linear/BICGStabL_impl.h b/src/TNL/Solvers/Linear/BICGStabL_impl.h
index 6606bddd561fa8a8d5b3ce5e8855b6e41541b546..467f1a91a04c018377863b27ac85985759eb988d 100644
--- a/src/TNL/Solvers/Linear/BICGStabL_impl.h
+++ b/src/TNL/Solvers/Linear/BICGStabL_impl.h
@@ -87,7 +87,7 @@ BICGStabL< Matrix >::solve( ConstVectorViewType b, VectorViewType x )
    }
 
    sigma[ 0 ] = r_0.lpNorm( 2.0 );
-   if( std::isnan( sigma[ 0 ] ) )
+   if( isNan( sigma[ 0 ] ) )
       throw std::runtime_error( "BiCGstab(ell): initial residue is NAN" );
 
    r_ast = r_0;