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 5 #include <boost/numeric/ublas/vector.hpp> 6 #include <boost/numeric/ublas/io.hpp> 7 8 #include "utils.hpp" 9 10 using namespace boost::numeric::ublas; 11 12 static const double TOL(1.0e-5); ///< Used for comparing two real numbers. 13 BOOST_UBLAS_TEST_DEF(test_double_scaled_norm_2)14BOOST_UBLAS_TEST_DEF ( test_double_scaled_norm_2 ) { 15 vector<double> v(2); 16 v[0] = 0; v[1] = 1.0e155; 17 18 const double expected = 1.0e155; 19 20 BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) ); 21 BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL); 22 } 23 BOOST_UBLAS_TEST_DEF(test_float_scaled_norm_2)24BOOST_UBLAS_TEST_DEF ( test_float_scaled_norm_2 ) { 25 vector<float> v(2); 26 v[0] = 0; v[1] = 1.0e20; 27 28 const float expected = 1.0e20; 29 30 BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) ); 31 BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL); 32 } 33 main()34int main() { 35 BOOST_UBLAS_TEST_BEGIN(); 36 37 BOOST_UBLAS_TEST_DO( test_double_scaled_norm_2 ); 38 BOOST_UBLAS_TEST_DO( test_float_scaled_norm_2 ); 39 40 BOOST_UBLAS_TEST_END(); 41 } 42