inline
void
arma_ostream::print_elem(std::ostream& o, const std::complex<T>& x, const bool modify)
  {
  if( (x.real() != T(0)) || (x.imag() != T(0)) || (modify == false) )
    {
    std::ostringstream ss;
    ss.flags(o.flags());
    //ss.imbue(o.getloc());
    ss.precision(o.precision());
    
    ss << '(';
    
    const T a = x.real();
    
    if(arma_isfinite(a))
      {
      ss << a;
      }
    else
      {
      ss << ( arma_isinf(a) ? ((a <= T(0)) ? "-inf" : "+inf") : "nan" );
      }
    
    ss << ',';
    
    const T b = x.imag();
    
    if(arma_isfinite(b))
      {
      ss << b;
      }
    else
      {
      ss << ( arma_isinf(b) ? ((b <= T(0)) ? "-inf" : "+inf") : "nan" );
      }
    
    ss << ')';
    
    o << ss.str();
    }
  else
    {
    o << "(0,0)";
    }
  }
arma_hot
inline
bool
arrayops::has_inf(const eT* src, const uword n_elem)
  {
  uword j;
  
  for(j=1; j<n_elem; j+=2)
    {
    const eT val_i = (*src);  src++;
    const eT val_j = (*src);  src++;
    
    if( arma_isinf(val_i) || arma_isinf(val_j) )  { return true; }
    }
  
  if((j-1) < n_elem)
    {
    if(arma_isinf(*src))  { return true; }
    }
  
  return false;
  }
arma_inline
void
arma_ostream::print_elem(std::ostream& o, const eT& x, const bool modify)
  {
  if(is_signed<eT>::value)
    {
    typedef typename promote_type<eT, s16>::result promoted_eT;
    
    if(x != eT(0))
      {
      if(arma_isfinite(x))
        {
        o << promoted_eT(x);
        }
      else
        {
        o << ( arma_isinf(x) ? ((x <= eT(0)) ? "-inf" : "inf") : "nan" );
        }
      }
    else
      {
      arma_ostream::print_elem_zero<promoted_eT>(o, modify);
      }
    }
  else
    {
    typedef typename promote_type<eT, u16>::result promoted_eT;
    
    if(x != eT(0))
      {
      o << promoted_eT(x);
      }
    else
      {
      arma_ostream::print_elem_zero<promoted_eT>(o, modify);
      }
    }
  }
arma_inline
bool
arma_isinf(const std::complex<T>& x)
  {
  return ( arma_isinf(x.real()) || arma_isinf(x.imag()) );
  }