/****************************************** * C++ Octonions * Version: 1.0.9 * Author: Douglas Wilhelm Harder * Date: 2008/03/03 * * Copyright (c) 2006-2008 by Douglas Wilhelm Harder. * All rights reserved. ******************************************/ #ifndef CA_UWATERLOO_ALUMNI_DWHARDER_OCTONION #define CA_UWATERLOO_ALUMNI_DWHARDER_OCTONION #include #include #include template class Octonion; template std::ostream & operator << ( std::ostream &, const Octonion & ); template Octonion operator + ( T, const Octonion & ); template Octonion operator + ( long, const Octonion & ); template Octonion operator - ( T, const Octonion & ); template Octonion operator - ( long, const Octonion & ); template Octonion operator * ( T, const Octonion & ); template Octonion operator * ( long, const Octonion & ); template Octonion operator / ( T, const Octonion & ); template Octonion operator / ( long, const Octonion & ); template bool operator == ( T, const Octonion & ); template bool operator == ( long, const Octonion & ); template bool operator != ( T, const Octonion & ); template bool operator != ( long, const Octonion & ); template T real( const Octonion & ); template T imag_i( const Octonion & ); template T imag_j( const Octonion & ); template T imag_k( const Octonion & ); template T imag_u1( const Octonion & ); template T imag_i1( const Octonion & ); template T imag_j1( const Octonion & ); template T imag_k1( const Octonion & ); template T csgn( const Octonion & ); template T abs( const Octonion & ); template T norm( const Octonion & ); template T abs_imag( const Octonion & ); template T norm_imag( const Octonion & ); template T arg( const Octonion & ); template Octonion imag( const Octonion & ); template Octonion conj( const Octonion & ); template Octonion signum( const Octonion & ); template Octonion sqr( const Octonion & ); template Octonion sqrt( const Octonion & ); template Octonion rotate( const Octonion &, const Octonion & ); template Octonion exp( const Octonion & ); template Octonion log( const Octonion & ); template Octonion log10( const Octonion & ); template Octonion pow( const Octonion &, const Octonion & ); template Octonion pow( const Octonion &, T ); template Octonion inverse( const Octonion & ); template Octonion sin( const Octonion & ); template Octonion cos( const Octonion & ); template Octonion tan( const Octonion & ); template Octonion sec( const Octonion & ); template Octonion csc( const Octonion & ); template Octonion cot( const Octonion & ); template Octonion sinh( const Octonion & ); template Octonion cosh( const Octonion & ); template Octonion tanh( const Octonion & ); template Octonion sech( const Octonion & ); template Octonion csch( const Octonion & ); template Octonion coth( const Octonion & ); template Octonion asin( const Octonion &, const Octonion & = Octonion::I ); template Octonion acos( const Octonion &, const Octonion & = Octonion::I ); template Octonion atan( const Octonion & ); template Octonion asec( const Octonion &, const Octonion & = Octonion::I ); template Octonion acsc( const Octonion &, const Octonion & = Octonion::I ); template Octonion acot( const Octonion & ); template Octonion asinh( const Octonion & ); template Octonion acosh( const Octonion &, const Octonion & = Octonion::I ); template Octonion atanh( const Octonion &, const Octonion & = Octonion::I ); template Octonion asech( const Octonion &, const Octonion & = Octonion::I ); template Octonion acsch( const Octonion & ); template Octonion acoth( const Octonion &, const Octonion & = Octonion::I ); template Octonion bessel_J( int, const Octonion & ); template Octonion floor( const Octonion & ); template Octonion ceil( const Octonion & ); template Octonion horner( const Octonion &, T *, unsigned int ); template Octonion horner( const Octonion &, T *, T *, unsigned int ); template class Octonion { private: T r, i, j, k, u1, i1, j1, k1; inline static Octonion multiplier( T, T, const Octonion & ); inline static Octonion make_inf( T, T ); inline static Octonion make_i( T, T ); public: const static Octonion ZERO; const static Octonion ONE; const static Octonion I; const static Octonion J; const static Octonion K; const static Octonion U1; const static Octonion I1; const static Octonion J1; const static Octonion K1; const static Octonion UNITS[8]; /****************************************** * Constructor and Copy Constructor ******************************************/ Octonion( T, T, T, T, T, T, T, T ); Octonion( T = 0.0 ); /****************************************** * Assignment Operator ******************************************/ const Octonion & operator = ( const T & ); /****************************************** * Mutating Arithmetic Operators ******************************************/ Octonion & operator += ( const Octonion & ); Octonion & operator -= ( const Octonion & ); Octonion & operator *= ( const Octonion & ); Octonion & operator /= ( const Octonion & ); Octonion & operator += ( T ); Octonion & operator -= ( T ); Octonion & operator *= ( T ); Octonion & operator /= ( T ); Octonion & operator ++(); Octonion operator ++( int ); Octonion & operator --(); Octonion operator --( int ); /****************************************** * Real-valued Functions ******************************************/ T real() const; T operator []( int ) const; T& operator []( int ); T imag_i() const; T imag_j() const; T imag_k() const; T imag_u1() const; T imag_i1() const; T imag_j1() const; T imag_k1() const; T csgn() const; T abs() const; T norm() const; T abs_imag() const; T norm_imag() const; T arg() const; /****************************************** * Octonion-valued Functions ******************************************/ Octonion imag() const; Octonion conj() const; Octonion operator * () const; Octonion signum() const; Octonion sqr() const; Octonion sqrt() const; Octonion rotate( const Octonion & ) const; /****************************************** * Boolean-valued Functions ******************************************/ bool is_imaginary() const; bool is_inf() const; bool is_nan() const; bool is_neg_inf() const; bool is_pos_inf() const; bool is_real() const; bool is_real_inf() const; bool is_zero() const; /****************************************** * Exponential and Logarithmic Functions ******************************************/ Octonion exp() const; Octonion log() const; Octonion log10() const; Octonion pow( const Octonion & ) const; Octonion pow( T ) const; Octonion inverse() const; /****************************************** * Trigonometric and Hyperbolic Functions ******************************************/ Octonion sin() const; Octonion cos() const; Octonion tan() const; Octonion sec() const; Octonion csc() const; Octonion cot() const; Octonion sinh() const; Octonion cosh() const; Octonion tanh() const; Octonion sech() const; Octonion csch() const; Octonion coth() const; Octonion asin( const Octonion & = I ) const; Octonion acos( const Octonion & = I ) const; Octonion atan() const; Octonion asec( const Octonion & = I ) const; Octonion acsc( const Octonion & = I ) const; Octonion acot() const; Octonion asinh() const; Octonion acosh( const Octonion & = I ) const; Octonion atanh( const Octonion & = I ) const; Octonion asech( const Octonion & = I ) const; Octonion acsch() const; Octonion acoth( const Octonion & = I ) const; Octonion bessel_J( int ) const; /****************************************** * Integer Functions ******************************************/ Octonion ceil() const; Octonion floor() const; /****************************************** * Horner's Rule ******************************************/ Octonion horner( T *, T *, unsigned int ) const; Octonion horner( T *, unsigned int ) const; /****************************************** * Random Factories ******************************************/ static Octonion random(); static Octonion random_imag(); static Octonion random_real(); /****************************************** * Binary Arithmetic Operators ******************************************/ Octonion operator + ( const Octonion & ) const; Octonion operator + ( T ) const; Octonion operator - ( const Octonion & ) const; Octonion operator - ( T ) const; Octonion operator * ( const Octonion & ) const; Octonion operator * ( T ) const; Octonion operator / ( const Octonion & ) const; Octonion operator / ( T ) const; /****************************************** * Unary Arithmetic Operators ******************************************/ Octonion operator - () const; /****************************************** * Binary Boolean Operators ******************************************/ bool operator == ( const Octonion & ) const; bool operator == ( T ) const; bool operator != ( const Octonion & ) const; bool operator != ( T ) const; }; #endif