Home Libraries People FAQ More

### Quaternion 非成員運算符

##### 一元 取正 運算符
```template<typename T>
quaternion<T> operator + (quaternion<T> const & q);
```

##### 一元 取負 運算符
```template<typename T>
quaternion<T> operator - (quaternion<T> const & q);
```

##### 二元加法運算符
```template<typename T>	quaternion<T>	operator + (T const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator + (quaternion<T> const & lhs, T const & rhs);
template<typename T>	quaternion<T>	operator + (::std::complex<T> const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator + (quaternion<T> const & lhs, ::std::complex<T> const & rhs);
template<typename T>	quaternion<T>	operator + (quaternion<T> const & lhs, quaternion<T> const & rhs);
```

##### 二元減法運算符
```template<typename T>	quaternion<T>	operator - (T const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator - (quaternion<T> const & lhs, T const & rhs);
template<typename T>	quaternion<T>	operator - (::std::complex<T> const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator - (quaternion<T> const & lhs, ::std::complex<T> const & rhs);
template<typename T>	quaternion<T>	operator - (quaternion<T> const & lhs, quaternion<T> const & rhs);
```

##### 二元乘法運算符
```template<typename T>	quaternion<T>	operator * (T const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator * (quaternion<T> const & lhs, T const & rhs);
template<typename T>	quaternion<T>	operator * (::std::complex<T> const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator * (quaternion<T> const & lhs, ::std::complex<T> const & rhs);
template<typename T>	quaternion<T>	operator * (quaternion<T> const & lhs, quaternion<T> const & rhs);
```

##### 二元除法運算符
```template<typename T>	quaternion<T>	operator / (T const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator / (quaternion<T> const & lhs, T const & rhs);
template<typename T>	quaternion<T>	operator / (::std::complex<T> const & lhs, quaternion<T> const & rhs);
template<typename T>	quaternion<T>	operator / (quaternion<T> const & lhs, ::std::complex<T> const & rhs);
template<typename T>	quaternion<T>	operator / (quaternion<T> const & lhs, quaternion<T> const & rhs);
```

##### 相等(==)運算符
```template<typename T>	bool	operator == (T const & lhs, quaternion<T> const & rhs);
template<typename T>	bool	operator == (quaternion<T> const & lhs, T const & rhs);
template<typename T>	bool	operator == (::std::complex<T> const & lhs, quaternion<T> const & rhs);
template<typename T>	bool	operator == (quaternion<T> const & lhs, ::std::complex<T> const & rhs);
template<typename T>	bool	operator == (quaternion<T> const & lhs, quaternion<T> const & rhs);
```

``` 不相等(!=)運算符 template<typename T> bool operator != (T const & lhs, quaternion<T> const & rhs); template<typename T> bool operator != (quaternion<T> const & lhs, T const & rhs); template<typename T> bool operator != (::std::complex<T> const & lhs, quaternion<T> const & rhs); template<typename T> bool operator != (quaternion<T> const & lhs, ::std::complex<T> const & rhs); template<typename T> bool operator != (quaternion<T> const & lhs, quaternion<T> const & rhs); 這些函數返回真，當且僅當quaternion<T>(lhs) == quaternion<T>(rhs) 為假. 與任何的浮點數一樣, 這本質上是沒有意義的. 流抽取運算符 template<typename T, typename charT, class traits> ::std::basic_istream<charT,traits>& operator >> (::std::basic_istream<charT,traits> & is, quaternion<T> & q); 從下面的任意一種形式中抽取一個四元數 q ( a, b, c 和 d 的類型為 T): a (a), (a,b), (a,b,c), (a,b,c,d) (a,(c)), (a,(c,d)), ((a)), ((a),c), ((a),(c)), ((a),(c,d)), ((a,b)), ((a,b),c), ((a,b),(c)), ((a,b),(c,d)) 輸入值必須能夠轉換為T類型的值. 如果遇到了不合法的輸入, 將會調用函數 is.setstate(ios::failbit) (該函數將會拋出異常 ios::failure (27.4.5.3)). 返回: is. 這一串可以接受的輸入格式的原理在於 或者我們有一個由4個實數組成的實數串 或者 我們有兩個複數, 並且在那種情況下可以被格式化為合適的複數, 那麼這種輸入形式應當被接受. 這樣，潛在的二義性就被消除了 (例如 (a,b) 表示 (a,b,0,0) 而不是(a,0,b,0), 也就是說. 這種形式被解析為兩個實數組成的串 而不是兩個虛部為0的複數組成的串 ). 流插入運算符 template<typename T, typename charT, class traits> ::std::basic_ostream<charT,traits>& operator << (::std::basic_ostream<charT,traits> & os, quaternion<T> const & q); 將四元數 q 插入到流 os中 就像它被實現為下面這樣: template<typename T, typename charT, class traits> ::std::basic_ostream<charT,traits>& operator << ( ::std::basic_ostream<charT,traits> & os, quaternion<T> const & q) { ::std::basic_ostringstream<charT,traits> s; s.flags(os.flags()); s.imbue(os.getloc()); s.precision(os.precision()); s << '(' << q.R_component_1() << ',' << q.R_component_2() << ',' << q.R_component_3() << ',' << q.R_component_4() << ')'; return os << s.str(); } ```
``` Copyright ?2001 -2003 Hubert Holin 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) ```