📄 octonion_test.cpp
字号:
f0 != o0; // using != (const octonion<T> &, const T &) o0 != f0; // using != (const ::std::complex<T> &, const octonion<T> &) c0 != o2; // using != (const octonion<T> &, const ::std::complex<T> &) o2 != c0; // using != (const ::boost::math::quaternion<T> &, const octonion<T> &) q0 != o3; // using != (const octonion<T> &, const ::boost::math::quaternion<T> &) o3 != q0; // using != (const octonion<T> &,const octonion<T> &) o0 != o4; BOOST_MESSAGE("Please input an octonion..."); #ifdef BOOST_INTERACTIVE_TEST_INPUT_ITERATOR ::std::cin >> o0; if (::std::cin.fail()) { BOOST_MESSAGE("You have entered nonsense!"); } else { BOOST_MESSAGE("You have entered the octonion " << o0 << " ."); }#else ::std::istringstream bogus("(1,2,3,4,5,6,7,8)"); bogus >> o0; BOOST_MESSAGE("You have entered the octonion " << o0 << " .");#endif BOOST_MESSAGE("For this octonion:"); BOOST_MESSAGE( "the value of the real part is " << real(o0)); BOOST_MESSAGE( "the value of the unreal part is " << unreal(o0)); BOOST_MESSAGE( "the value of the sup norm is " << sup(o0)); BOOST_MESSAGE( "the value of the l1 norm is " << l1(o0)); BOOST_MESSAGE( "the value of the magnitude (euclidian norm) is " << abs(o0)); BOOST_MESSAGE( "the value of the (Cayley) norm is " << norm(o0)); BOOST_MESSAGE( "the value of the conjugate is " << conj(o0)); BOOST_MESSAGE( "the value of the exponential is " << exp(o0)); BOOST_MESSAGE( "the value of the cube is " << pow(o0,3)); BOOST_MESSAGE( "the value of the cosinus is " << cos(o0)); BOOST_MESSAGE( "the value of the sinus is " << sin(o0)); BOOST_MESSAGE( "the value of the tangent is " << tan(o0)); BOOST_MESSAGE( "the value of the hyperbolic cosinus is " << cosh(o0)); BOOST_MESSAGE( "the value of the hyperbolic sinus is " << sinh(o0)); BOOST_MESSAGE( "the value of the hyperbolic tangent is " << tanh(o0)); #ifdef BOOST_NO_TEMPLATE_TEMPLATES BOOST_MESSAGE( "no template templates, can't compute cardinal functions");#else /* BOOST_NO_TEMPLATE_TEMPLATES */ BOOST_MESSAGE( "the value of the Sinus Cardinal (of index pi) is " << sinc_pi(o0)); BOOST_MESSAGE( "the value of " << "the Hyperbolic Sinus Cardinal (of index pi) is " << sinhc_pi(o0));#endif /* BOOST_NO_TEMPLATE_TEMPLATES */ BOOST_MESSAGE(" "); float rho = ::std::sqrt(4096.0f); float theta = ::std::atan(1.0f); float phi1 = ::std::atan(1.0f); float phi2 = ::std::atan(1.0f); float phi3 = ::std::atan(1.0f); float phi4 = ::std::atan(1.0f); float phi5 = ::std::atan(1.0f); float phi6 = ::std::atan(1.0f); BOOST_MESSAGE( "The value of the octonion represented " << "in spherical form by " << "rho = " << rho << " , theta = " << theta << " , phi1 = " << phi1 << " , phi2 = " << phi2 << " , phi3 = " << phi3 << " , phi4 = " << phi4 << " , phi5 = " << phi5 << " , phi6 = " << phi6 << " is " << ::boost::math::spherical(rho, theta, phi1, phi2, phi3, phi4, phi5, phi6)); float rho1 = 1; float rho2 = 2; float rho3 = ::std::sqrt(2.0f); float rho4 = ::std::sqrt(8.0f); float theta1 = 0; float theta2 = ::std::atan(1.0f)*2; float theta3 = ::std::atan(1.0f); float theta4 = ::std::atan(::std::sqrt(3.0f)); BOOST_MESSAGE( "The value of the octonion represented " << "in multipolar form by " << "rho1 = " << rho1 << " , theta1 = " << theta1 << " , rho2 = " << rho2 << " , theta2 = " << theta2 << "rho3 = " << rho3 << " , theta3 = " << theta3 << " , rho4 = " << rho4 << " , theta4 = " << theta4 << " is " << ::boost::math::multipolar(rho1, theta1, rho2, theta2, rho3, theta3, rho4, theta4)); float r = ::std::sqrt(2.0f); float angle = ::std::atan(1.0f); float h1 = 3; float h2 = 4; float h3 = 5; float h4 = 6; float h5 = 7; float h6 = 8; BOOST_MESSAGE( "The value of the octonion represented " << "in cylindrical form by " << "r = " << r << " , angle = " << angle << " , h1 = " << h1 << " , h2 = " << h2 << " , h3 = " << h3 << " , h4 = " << h4 << " , h5 = " << h5 << " , h6 = " << h6 << " is " << ::boost::math::cylindrical(r, angle, h1, h2, h3, h4, h5, h6)); double real_1(1); ::std::complex<double> complex_1(1); ::std::complex<double> complex_i(0,1); ::boost::math::quaternion<double> quaternion_1(1); ::boost::math::quaternion<double> quaternion_i(0,1); ::boost::math::quaternion<double> quaternion_j(0,0,1); ::boost::math::quaternion<double> quaternion_k(0,0,0,1); ::boost::math::octonion<double> octonion_1(1); ::boost::math::octonion<double> octonion_i(0,1); ::boost::math::octonion<double> octonion_j(0,0,1); ::boost::math::octonion<double> octonion_k(0,0,0,1); ::boost::math::octonion<double> octonion_e_prime(0,0,0,0,1); ::boost::math::octonion<double> octonion_i_prime(0,0,0,0,0,1); ::boost::math::octonion<double> octonion_j_prime(0,0,0,0,0,0,1); ::boost::math::octonion<double> octonion_k_prime(0,0,0,0,0,0,0,1); BOOST_MESSAGE(" "); BOOST_MESSAGE( "Real 1: " << real_1 << " ; Complex 1: " << complex_1 << " ; Quaternion 1: " << quaternion_1 << " ; Octonion 1: " << octonion_1 << " ."); BOOST_MESSAGE( "Complex i: " << complex_i << " ; Quaternion i: " << quaternion_i << " ; Octonion i : " << octonion_i << " ."); BOOST_MESSAGE( "Quaternion j: " << quaternion_j << " ; Octonion j: " << octonion_j << " ."); BOOST_MESSAGE( "Quaternion k: " << quaternion_k << " ; Octonion k: " << octonion_k << " ."); BOOST_MESSAGE( "Quaternion e\': " << octonion_e_prime << " ."); BOOST_MESSAGE( "Quaternion i\': " << octonion_i_prime << " ."); BOOST_MESSAGE( "Quaternion j\': " << octonion_j_prime << " ."); BOOST_MESSAGE( "Quaternion k\': " << octonion_k_prime << " ."); BOOST_MESSAGE(" "); BOOST_MESSAGE( octonion_1*octonion_1 << " ; " << octonion_1*octonion_i << " ; " << octonion_1*octonion_j << " ; " << octonion_1*octonion_k << " ; " << octonion_1*octonion_e_prime << " ; " << octonion_1*octonion_i_prime << " ; " << octonion_1*octonion_j_prime << " ; " << octonion_1*octonion_k_prime << " ; "); BOOST_MESSAGE( octonion_i*octonion_1 << " ; " << octonion_i*octonion_i << " ; " << octonion_i*octonion_j << " ; " << octonion_i*octonion_k << " ; " << octonion_i*octonion_e_prime << " ; " << octonion_i*octonion_i_prime << " ; " << octonion_i*octonion_j_prime << " ; " << octonion_i*octonion_k_prime << " ; "); BOOST_MESSAGE( octonion_j*octonion_1 << " ; " << octonion_j*octonion_i << " ; " << octonion_j*octonion_j << " ; " << octonion_j*octonion_k << " ; " << octonion_j*octonion_e_prime << " ; " << octonion_j*octonion_i_prime << " ; " << octonion_j*octonion_j_prime << " ; " << octonion_j*octonion_k_prime << " ; "); BOOST_MESSAGE( octonion_k*octonion_1 << " ; " << octonion_k*octonion_i << " ; " << octonion_k*octonion_j << " ; " << octonion_k*octonion_k << " ; " << octonion_k*octonion_e_prime << " ; " << octonion_k*octonion_i_prime << " ; " << octonion_k*octonion_j_prime << " ; " << octonion_k*octonion_k_prime << " ; "); BOOST_MESSAGE( octonion_e_prime*octonion_1 << " ; " << octonion_e_prime*octonion_i << " ; " << octonion_e_prime*octonion_j << " ; " << octonion_e_prime*octonion_k << " ; " << octonion_e_prime*octonion_e_prime << " ; " << octonion_e_prime*octonion_i_prime << " ; " << octonion_e_prime*octonion_j_prime << " ; " << octonion_e_prime*octonion_k_prime << " ; "); BOOST_MESSAGE( octonion_i_prime*octonion_1 << " ; " << octonion_i_prime*octonion_i << " ; " << octonion_i_prime*octonion_j << " ; " << octonion_i_prime*octonion_k << " ; " << octonion_i_prime*octonion_e_prime << " ; " << octonion_i_prime*octonion_i_prime << " ; " << octonion_i_prime*octonion_j_prime << " ; " << octonion_i_prime*octonion_k_prime << " ; "); BOOST_MESSAGE( octonion_j_prime*octonion_1 << " ; " << octonion_j_prime*octonion_i << " ; " << octonion_j_prime*octonion_j << " ; " << octonion_j_prime*octonion_k << " ; " << octonion_j_prime*octonion_e_prime << " ; " << octonion_j_prime*octonion_i_prime << " ; " << octonion_j_prime*octonion_j_prime << " ; " << octonion_j_prime*octonion_k_prime << " ; "); BOOST_MESSAGE( octonion_k_prime*octonion_1 << " ; " << octonion_k_prime*octonion_i << " ; " << octonion_k_prime*octonion_j << " ; " << octonion_k_prime*octonion_k << " ; " << octonion_k_prime*octonion_e_prime << " ; " << octonion_k_prime*octonion_i_prime << " ; " << octonion_k_prime*octonion_j_prime << " ; " << octonion_k_prime*octonion_k_prime << " ; "); BOOST_MESSAGE(" "); BOOST_MESSAGE("i\'*(e\'*j) : " << octonion_i_prime*(octonion_e_prime*octonion_j) << " ;"); BOOST_MESSAGE("(i\'*e\')*j : " << (octonion_i_prime*octonion_e_prime)*octonion_j << " ;"); BOOST_MESSAGE(" ");}BOOST_TEST_CASE_TEMPLATE_FUNCTION(multiplication_test, T){#if BOOST_WORKAROUND(__GNUC__, < 3)#else /* BOOST_WORKAROUND(__GNUC__, < 3) */ using ::std::numeric_limits; using ::boost::math::abs;#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ BOOST_MESSAGE("Testing multiplication for " << string_type_name<T>::_() << "."); BOOST_REQUIRE_PREDICATE(::std::less_equal<T>(), (abs(::boost::math::octonion<T>(1,0,0,0,0,0,0,0)* ::boost::math::octonion<T>(1,0,0,0,0,0,0,0)- static_cast<T>(1))) (numeric_limits<T>::epsilon())); for (int idx = 1; idx < 8; ++idx) { ::boost::math::octonion<T> toto = index_i_element<T>(idx); BOOST_REQUIRE_PREDICATE(::std::less_equal<T>(), (abs(toto*toto+static_cast<T>(1))) (numeric_limits<T>::epsilon())); }}BOOST_TEST_CASE_TEMPLATE_FUNCTION(exp_test, T){#if BOOST_WORKAROUND(__GNUC__, < 3)#else /* BOOST_WORKAROUND(__GNUC__, < 3) */ using ::std::numeric_limits; using ::std::atan; using ::boost::math::abs;#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ BOOST_MESSAGE("Testing exp for " << string_type_name<T>::_() << "."); for (int idx = 1; idx < 8; ++idx) { ::boost::math::octonion<T> toto = static_cast<T>(4)*atan(static_cast<T>(1))*index_i_element<T>(idx); BOOST_CHECK_PREDICATE(::std::less_equal<T>(), (abs(exp(toto)+static_cast<T>(1))) (2*numeric_limits<T>::epsilon())); }}boost::unit_test_framework::test_suite * init_unit_test_suite(int, char *[]){ ::boost::unit_test::unit_test_log. set_threshold_level(::boost::unit_test::log_messages); boost::unit_test_framework::test_suite * test = BOOST_TEST_SUITE("octonion_test"); BOOST_MESSAGE("Results of octonion test."); BOOST_MESSAGE(" "); BOOST_MESSAGE("(C) Copyright Hubert Holin 2003-2005."); BOOST_MESSAGE("Distributed under the Boost Software License, Version 1.0."); BOOST_MESSAGE("(See accompanying file LICENSE_1_0.txt or copy at"); BOOST_MESSAGE("http://www.boost.org/LICENSE_1_0.txt)"); BOOST_MESSAGE(" "); #define BOOST_OCTONION_COMMON_GENERATOR(fct) \ test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, test_types)); #define BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(fct) \ test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, near_eps_test_types)); #define BOOST_OCTONION_TEST \ BOOST_OCTONION_COMMON_GENERATOR(multiplication) \ BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(exp) BOOST_OCTONION_TEST #undef BOOST_OCTONION_TEST #undef BOOST_OCTONION_COMMON_GENERATOR#undef BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS #ifdef BOOST_OCTONION_TEST_VERBOSE test->add(BOOST_TEST_CASE(octonion_manual_test)); #endif /* BOOST_OCTONION_TEST_VERBOSE */ return test;}#undef DEFINE_TYPE_NAME
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -