| Home | Libraries | People | FAQ | More

### Octonion Non-Member Operators

##### Unary Plus and Minus Operators

    template<typename T> octonion<T> operator + (octonion<T> const & o);

This unary operator simply returns o.

    template<typename T> octonion<T> operator - (octonion<T> const & o);

This unary operator returns the opposite of o.

##### Binary Addition Operators

    template<typename T> octonion<T> operator + (T const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator + (octonion<T> const & lhs, T const & rhs);
    template<typename T> octonion<T> operator + (::std::complex<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator + (octonion<T> const & lhs, ::std::complex<T> const & rhs);
    template<typename T> octonion<T> operator + (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator + (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs);
    template<typename T> octonion<T> operator + (octonion<T> const & lhs, octonion<T> const & rhs);

These operators return `octonion<T>(lhs) += rhs`.

##### Binary Subtraction Operators

    template<typename T> octonion<T> operator - (T const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator - (octonion<T> const & lhs, T const & rhs);
    template<typename T> octonion<T> operator - (::std::complex<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator - (octonion<T> const & lhs, ::std::complex<T> const & rhs);
    template<typename T> octonion<T> operator - (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator - (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs);
    template<typename T> octonion<T> operator - (octonion<T> const & lhs, octonion<T> const & rhs);

These operators return `octonion<T>(lhs) -= rhs`.

##### Binary Multiplication Operators

    template<typename T> octonion<T> operator * (T const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator * (octonion<T> const & lhs, T const & rhs);
    template<typename T> octonion<T> operator * (::std::complex<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator * (octonion<T> const & lhs, ::std::complex<T> const & rhs);
    template<typename T> octonion<T> operator * (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator * (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs);
    template<typename T> octonion<T> operator * (octonion<T> const & lhs, octonion<T> const & rhs);

These operators return `octonion<T>(lhs) *= rhs`.

##### Binary Division Operators

    template<typename T> octonion<T> operator / (T const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator / (octonion<T> const & lhs, T const & rhs);
    template<typename T> octonion<T> operator / (::std::complex<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator / (octonion<T> const & lhs, ::std::complex<T> const & rhs);
    template<typename T> octonion<T> operator / (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs);
    template<typename T> octonion<T> operator / (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs);
    template<typename T> octonion<T> operator / (octonion<T> const & lhs, octonion<T> const & rhs);

These operators return `octonion<T>(lhs) /= rhs`. It is of course still an error to divide by zero...

##### Binary Equality Operators

    template<typename T> bool operator == (T const & lhs, octonion<T> const & rhs);
    template<typename T> bool operator == (octonion<T> const & lhs, T const & rhs);
    template<typename T> bool operator == (::std::complex<T> const & lhs, octonion<T> const & rhs);
    template<typename T> bool operator == (octonion<T> const & lhs, ::std::complex<T> const & rhs);
    template<typename T> bool operator == (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs);
    template<typename T> bool operator == (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs);
    template<typename T> bool operator == (octonion<T> const & lhs, octonion<T> const & rhs);

These return true if and only if the four components of `octonion<T>(lhs)` are equal to their counterparts in `octonion<T>(rhs)`. As with any floating-type entity, this is essentially meaningless.

##### Binary Inequality Operators

    template<typename T> bool operator != (T const & lhs, octonion<T> const & rhs);
    template<typename T> bool operator != (octonion<T> const & lhs, T const & rhs);
    template<typename T> bool operator != (::std::complex<T> const & lhs, octonion<T> const & rhs);
    template<typename T> bool operator != (octonion<T> const & lhs, ::std::complex<T> const & rhs);
    template<typename T> bool operator != (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs);
    template<typename T> bool operator != (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs);
    template<typename T> bool operator != (octonion<T> const & lhs, octonion<T> const & rhs);

These return true if and only if `octonion<T>(lhs) == octonion<T>(rhs)` is false. As with any floating-type entity, this is essentially meaningless.

##### Stream Extractor

    template<typename T, typename charT, class traits>
    ::std::basic_istream<charT,traits> & operator >> (::std::basic_istream<charT,traits> & is, octonion<T> & o);

Extracts an octonion `o`. We accept any format which seems reasonable. However, since this leads to a great many ambiguities, decisions were made to lift these. In case of doubt, stick to lists of reals.

The input values must be convertible to T. If bad input is encountered, calls `is.setstate(ios::failbit)` (which may throw `ios::failure` (27.4.5.3)).

Returns `is`.

##### Stream Inserter

    template<typename T, typename charT, class traits>
    ::std::basic_ostream<charT,traits> & operator << (::std::basic_ostream<charT,traits> & os, octonion<T> const & o);

Inserts the octonion `o` onto the stream `os` as if it were implemented as follows:

    template<typename T, typename charT, class traits>
    ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os,
    octonion<T> const & o)
    {
       ::std::basic_ostringstream<charT,traits> s;

       s.flags(os.flags());
       s.imbue(os.getloc());
       s.precision(os.precision());

       s << '(' << o.R_component_1() << ','
          << o.R_component_2() << ','
          << o.R_component_3() << ','
          << o.R_component_4() << ','
          << o.R_component_5() << ','
          << o.R_component_6() << ','
          << o.R_component_7() << ','
          << o.R_component_8() << ')';

       return os << s.str();
    }