📄 octonion.hpp
字号:
// boost octonion.hpp header file
// (C) Copyright Hubert Holin 2001.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#ifndef BOOST_OCTONION_HPP
#define BOOST_OCTONION_HPP
#include <boost/math/quaternion.hpp>
namespace boost
{
namespace math
{
#if BOOST_WORKAROUND(__GNUC__, < 3)
// gcc 2.95.x uses expression templates for valarray calculations, but
// the result is not conforming. We need BOOST_GET_VALARRAY to get an
// actual valarray result when we need to call a member function
#define BOOST_GET_VALARRAY(T,x) ::std::valarray<T>(x)
// gcc 2.95.x has an "std::ios" class that is similar to
// "std::ios_base", so we just use a #define
#define BOOST_IOS_BASE ::std::ios
// gcc 2.x ignores function scope using declarations,
// put them in the scope of the enclosing namespace instead:
using ::std::valarray;
using ::std::sqrt;
using ::std::cos;
using ::std::sin;
using ::std::exp;
using ::std::cosh;
#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
#define BOOST_OCTONION_ACCESSOR_GENERATOR(type) \
type real() const \
{ \
return(a); \
} \
\
octonion<type> unreal() const \
{ \
return( octonion<type>(static_cast<type>(0),b,c,d,e,f,g,h)); \
} \
\
type R_component_1() const \
{ \
return(a); \
} \
\
type R_component_2() const \
{ \
return(b); \
} \
\
type R_component_3() const \
{ \
return(c); \
} \
\
type R_component_4() const \
{ \
return(d); \
} \
\
type R_component_5() const \
{ \
return(e); \
} \
\
type R_component_6() const \
{ \
return(f); \
} \
\
type R_component_7() const \
{ \
return(g); \
} \
\
type R_component_8() const \
{ \
return(h); \
} \
\
::std::complex<type> C_component_1() const \
{ \
return(::std::complex<type>(a,b)); \
} \
\
::std::complex<type> C_component_2() const \
{ \
return(::std::complex<type>(c,d)); \
} \
\
::std::complex<type> C_component_3() const \
{ \
return(::std::complex<type>(e,f)); \
} \
\
::std::complex<type> C_component_4() const \
{ \
return(::std::complex<type>(g,h)); \
} \
\
::boost::math::quaternion<type> H_component_1() const \
{ \
return(::boost::math::quaternion<type>(a,b,c,d)); \
} \
\
::boost::math::quaternion<type> H_component_2() const \
{ \
return(::boost::math::quaternion<type>(e,f,g,h)); \
}
#define BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(type) \
template<typename X> \
octonion<type> & operator = (octonion<X> const & a_affecter) \
{ \
a = static_cast<type>(a_affecter.R_component_1()); \
b = static_cast<type>(a_affecter.R_component_2()); \
c = static_cast<type>(a_affecter.R_component_3()); \
d = static_cast<type>(a_affecter.R_component_4()); \
e = static_cast<type>(a_affecter.R_component_5()); \
f = static_cast<type>(a_affecter.R_component_6()); \
g = static_cast<type>(a_affecter.R_component_7()); \
h = static_cast<type>(a_affecter.R_component_8()); \
\
return(*this); \
} \
\
octonion<type> & operator = (octonion<type> const & a_affecter) \
{ \
a = a_affecter.a; \
b = a_affecter.b; \
c = a_affecter.c; \
d = a_affecter.d; \
e = a_affecter.e; \
f = a_affecter.f; \
g = a_affecter.g; \
h = a_affecter.h; \
\
return(*this); \
} \
\
octonion<type> & operator = (type const & a_affecter) \
{ \
a = a_affecter; \
\
b = c = d = e = f= g = h = static_cast<type>(0); \
\
return(*this); \
} \
\
octonion<type> & operator = (::std::complex<type> const & a_affecter) \
{ \
a = a_affecter.real(); \
b = a_affecter.imag(); \
\
c = d = e = f = g = h = static_cast<type>(0); \
\
return(*this); \
} \
\
octonion<type> & operator = (::boost::math::quaternion<type> const & a_affecter) \
{ \
a = a_affecter.R_component_1(); \
b = a_affecter.R_component_2(); \
c = a_affecter.R_component_3(); \
d = a_affecter.R_component_4(); \
\
e = f = g = h = static_cast<type>(0); \
\
return(*this); \
}
#define BOOST_OCTONION_MEMBER_DATA_GENERATOR(type) \
type a; \
type b; \
type c; \
type d; \
type e; \
type f; \
type g; \
type h; \
template<typename T>
class octonion
{
public:
typedef T value_type;
// constructor for O seen as R^8
// (also default constructor)
explicit octonion( T const & requested_a = T(),
T const & requested_b = T(),
T const & requested_c = T(),
T const & requested_d = T(),
T const & requested_e = T(),
T const & requested_f = T(),
T const & requested_g = T(),
T const & requested_h = T())
: a(requested_a),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -