⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quaternion.hpp

📁 support vector clustering for vc++
💻 HPP
📖 第 1 页 / 共 5 页
字号:
                tr[3] = static_cast<type>(rhs.R_component_4());                                         \
                                                                                                        \
                type            mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)();  \
                                                                                                        \
                tr *= mixam;                                                                            \
                                                                                                        \
                valarray<type>    tt(4);                                                                \
                                                                                                        \
                tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3];                                               \
                tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2];                                               \
                tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1];                                               \
                tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0];                                               \
                                                                                                        \
                tr *= tr;                                                                               \
                                                                                                        \
                tt *= (mixam/tr.sum());                                                                 \
                                                                                                        \
                a = tt[0];                                                                              \
                b = tt[1];                                                                              \
                c = tt[2];                                                                              \
                d = tt[3];                                                                              \
                                                                                                        \
                return(*this);                                                                          \
            }
#elif    defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
    #define    BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type)                  \
            template<typename X>                                              \
            quaternion<type> &        operator /= (quaternion<X> const & rhs) \
            {                                                                 \
                using    ::std::valarray;                                     \
                using    ::std::abs;                                          \
                                                                              \
                valarray<type>    tr(4);                                      \
                                                                              \
                tr[0] = static_cast<type>(rhs.R_component_1());               \
                tr[1] = static_cast<type>(rhs.R_component_2());               \
                tr[2] = static_cast<type>(rhs.R_component_3());               \
                tr[3] = static_cast<type>(rhs.R_component_4());               \
                                                                              \
                type            mixam = static_cast<type>(1)/(abs(tr).max)(); \
                                                                              \
                tr *= mixam;                                                  \
                                                                              \
                valarray<type>    tt(4);                                      \
                                                                              \
                tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3];                     \
                tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2];                     \
                tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1];                     \
                tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0];                     \
                                                                              \
                tr *= tr;                                                     \
                                                                              \
                tt *= (mixam/tr.sum());                                       \
                                                                              \
                a = tt[0];                                                    \
                b = tt[1];                                                    \
                c = tt[2];                                                    \
                d = tt[3];                                                    \
                                                                              \
                return(*this);                                                \
            }
#else
    #define    BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type)                  \
            template<typename X>                                              \
            quaternion<type> &        operator /= (quaternion<X> const & rhs) \
            {                                                                 \
                using    ::std::valarray;                                     \
                                                                              \
                valarray<type>    tr(4);                                      \
                                                                              \
                tr[0] = static_cast<type>(rhs.R_component_1());               \
                tr[1] = static_cast<type>(rhs.R_component_2());               \
                tr[2] = static_cast<type>(rhs.R_component_3());               \
                tr[3] = static_cast<type>(rhs.R_component_4());               \
                                                                              \
                type            mixam = static_cast<type>(1)/(abs(tr).max)(); \
                                                                              \
                tr *= mixam;                                                  \
                                                                              \
                valarray<type>    tt(4);                                      \
                                                                              \
                tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3];                     \
                tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2];                     \
                tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1];                     \
                tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0];                     \
                                                                              \
                tr *= tr;                                                     \
                                                                              \
                tt *= (mixam/tr.sum());                                       \
                                                                              \
                a = tt[0];                                                    \
                b = tt[1];                                                    \
                c = tt[2];                                                    \
                d = tt[3];                                                    \
                                                                              \
                return(*this);                                                \
            }
#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
    
#define    BOOST_QUATERNION_MEMBER_ADD_GENERATOR(type)   \
        BOOST_QUATERNION_MEMBER_ADD_GENERATOR_1(type)    \
        BOOST_QUATERNION_MEMBER_ADD_GENERATOR_2(type)    \
        BOOST_QUATERNION_MEMBER_ADD_GENERATOR_3(type)
        
#define    BOOST_QUATERNION_MEMBER_SUB_GENERATOR(type)   \
        BOOST_QUATERNION_MEMBER_SUB_GENERATOR_1(type)    \
        BOOST_QUATERNION_MEMBER_SUB_GENERATOR_2(type)    \
        BOOST_QUATERNION_MEMBER_SUB_GENERATOR_3(type)
        
#define    BOOST_QUATERNION_MEMBER_MUL_GENERATOR(type)   \
        BOOST_QUATERNION_MEMBER_MUL_GENERATOR_1(type)    \
        BOOST_QUATERNION_MEMBER_MUL_GENERATOR_2(type)    \
        BOOST_QUATERNION_MEMBER_MUL_GENERATOR_3(type)
        
#define    BOOST_QUATERNION_MEMBER_DIV_GENERATOR(type)   \
        BOOST_QUATERNION_MEMBER_DIV_GENERATOR_1(type)    \
        BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type)    \
        BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type)
        
#define    BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(type)   \
        BOOST_QUATERNION_MEMBER_ADD_GENERATOR(type)            \
        BOOST_QUATERNION_MEMBER_SUB_GENERATOR(type)            \
        BOOST_QUATERNION_MEMBER_MUL_GENERATOR(type)            \
        BOOST_QUATERNION_MEMBER_DIV_GENERATOR(type)
        
        
        template<>
        class quaternion<float>
        {
        public:
            
            typedef float value_type;
            
            BOOST_QUATERNION_CONSTRUCTOR_GENERATOR(float)
            
            // UNtemplated copy constructor
            // (this is taken care of by the compiler itself)
            
            // explicit copy constructors (precision-loosing converters)
            
            explicit            quaternion(quaternion<double> const & a_recopier)
            {
                *this = detail::quaternion_type_converter<float, double>(a_recopier);
            }
            
            explicit            quaternion(quaternion<long double> const & a_recopier)
            {
                *this = detail::quaternion_type_converter<float, long double>(a_recopier);
            }
            
            // destructor
            // (this is taken care of by the compiler itself)
            
            // accessors
            //
            // Note:    Like complex number, quaternions do have a meaningful notion of "real part",
            //            but unlike them there is no meaningful notion of "imaginary part".
            //            Instead there is an "unreal part" which itself is a quaternion, and usually
            //            nothing simpler (as opposed to the complex number case).
            //            However, for practicallity, there are accessors for the other components
            //            (these are necessary for the templated copy constructor, for instance).
            
            BOOST_QUATERNION_ACCESSOR_GENERATOR(float)
            
            // assignment operators
            
            BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(float)
            
            // other assignment-related operators
            //
            // NOTE:    Quaternion multiplication is *NOT* commutative;
            //            symbolically, "q *= rhs;" means "q = q * rhs;"
            //            and "q /= rhs;" means "q = q * inverse_of(rhs);"
            
            BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(float)
            
            
        protected:
            
            BOOST_QUATERNION_MEMBER_DATA_GENERATOR(float)
            
            
        private:
            
        };
        
        
        template<>
        class quaternion<double>
        {
        public:
            
            typedef double value_type;
            
            BOOST_QUATERNION_CONSTRUCTOR_GENERATOR(double)
            
            // UNtemplated copy constructor
            // (this is taken care of by the compiler itself)
            
            // converting copy constructor
            
            explicit                quaternion(quaternion<float> const & a_recopier)
            {
                *this = detail::quaternion_type_converter<double, float>(a_recopier);
            }
            
            // explicit copy constructors (precision-loosing converters)
            
            explicit                quaternion(quaternion<long double> const & a_recopier)
            {
                *this = detail::quaternion_type_converter<double, long double>(a_recopier);
            }
            
            // destructor
            // (this is taken care of by the compiler itself)
            
            // accessors
            //
            // Note:    Like complex number, quaternions do have a meaningful notion of "real part",
            //            but unlike them there is no meaningful notion of "imaginary part".
            //            Instead there is an "unreal part" which itself is a quaternion, and usually
            //            nothing simpler (as opposed to the complex number case).
            //            However, for practicallity, there are accessors for the other components
            //            (these are necessary for the templated copy constructor, for instance).
            
            BOOST_QUATERNION_ACCESSOR_GENERATOR(double)
            
            // assignment operators
            
            BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(double)
            
            // other assignment-related operators
            //
            // NOTE:    Quaternion multiplication is *NOT* commutative;
            //            symbolically, "q *= rhs;" means "q = q * rhs;"
            //            and "q /= rhs;" means "q = q * inverse_of(rhs);"
            
            BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(double)
            

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -