test_scaled_norm.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Distributed under the Boost Software License, Version 1.0. (See
  2. // accompanying file LICENSE_1_0.txt or copy at
  3. // http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/numeric/ublas/vector.hpp>
  5. #include <boost/numeric/ublas/io.hpp>
  6. #include "utils.hpp"
  7. using namespace boost::numeric::ublas;
  8. static const double TOL(1.0e-5); ///< Used for comparing two real numbers.
  9. BOOST_UBLAS_TEST_DEF ( test_double_scaled_norm_2 ) {
  10. vector<double> v(2);
  11. v[0] = 0; v[1] = 1.0e155;
  12. const double expected = 1.0e155;
  13. BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) );
  14. BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL);
  15. }
  16. BOOST_UBLAS_TEST_DEF ( test_float_scaled_norm_2 ) {
  17. vector<float> v(2);
  18. v[0] = 0; v[1] = 1.0e20;
  19. const float expected = 1.0e20;
  20. BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) );
  21. BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL);
  22. }
  23. int main() {
  24. BOOST_UBLAS_TEST_BEGIN();
  25. BOOST_UBLAS_TEST_DO( test_double_scaled_norm_2 );
  26. BOOST_UBLAS_TEST_DO( test_float_scaled_norm_2 );
  27. BOOST_UBLAS_TEST_END();
  28. }