comparison liboctave/CMatrix.cc @ 15212:4bbd3bbb8912

reduce code duplication in too_large_for_float array functions * lo-utils.h (any_all_test): New function. * lo-utils.h, lo-utils.cc (xtoo_large_for_float (const Complex&)): New function. * Array.h (Array<T>::test): Call any_all_test. * Sparse.h (Sparse<T>::test, Sparse<T>::test_any, Sparse<T>::test_all, Sparse<T>::test_any, Sparse<T>::test_any, Sparse<T>::test_all, Sparse<T>::test_all): New functions. * CMatrix.cc (ComplexMatrix::too_large_for_float): Simplify with test_any and xtoo_large_for_float. * CNDArray.cc (ComplexNDArray::too_large_for_float): Likewise. * CSparse.cc (SparseComplexMatrix::too_large_for_float): Likewise. * dSparse.cc (SparseMatrix::too_large_for_float): Likewise. * dMatrix.cc (Matrix::too_large_for_float): Use test_any, not test_all. * dNDArray.cc (NDArray::too_large_for_float): Likewise. * fCMatrix.cc (FloatComplexMatrix::too_large_for_float): Unconditionlly return false. * fCNDArray.cc (FloatComplexNDArray::too_large_for_float): Likewise.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Aug 2012 16:16:31 -0400
parents 3d8ace26c5b4
children 61822c866ba1
comparison
equal deleted inserted replaced
15211:efd2024c7d56 15212:4bbd3bbb8912
3160 } 3160 }
3161 3161
3162 bool 3162 bool
3163 ComplexMatrix::too_large_for_float (void) const 3163 ComplexMatrix::too_large_for_float (void) const
3164 { 3164 {
3165 octave_idx_type nr = rows (); 3165 return test_any (xtoo_large_for_float);
3166 octave_idx_type nc = cols ();
3167
3168 for (octave_idx_type j = 0; j < nc; j++)
3169 for (octave_idx_type i = 0; i < nr; i++)
3170 {
3171 Complex val = elem (i, j);
3172
3173 double r_val = std::real (val);
3174 double i_val = std::imag (val);
3175
3176 if ((! (xisnan (r_val) || xisinf (r_val))
3177 && fabs (r_val) > FLT_MAX)
3178 || (! (xisnan (i_val) || xisinf (i_val))
3179 && fabs (i_val) > FLT_MAX))
3180 return true;
3181 }
3182
3183 return false;
3184 } 3166 }
3185 3167
3186 // FIXME Do these really belong here? Maybe they should be 3168 // FIXME Do these really belong here? Maybe they should be
3187 // in a base class? 3169 // in a base class?
3188 3170