octonion.hpp 217 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251
  1. // boost octonion.hpp header file
  2. // (C) Copyright Hubert Holin 2001.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org for updates, documentation, and revision history.
  7. #ifndef BOOST_OCTONION_HPP
  8. #define BOOST_OCTONION_HPP
  9. #include <boost/math/quaternion.hpp>
  10. #include <valarray>
  11. namespace boost
  12. {
  13. namespace math
  14. {
  15. #define BOOST_OCTONION_ACCESSOR_GENERATOR(type) \
  16. type real() const \
  17. { \
  18. return(a); \
  19. } \
  20. \
  21. octonion<type> unreal() const \
  22. { \
  23. return( octonion<type>(static_cast<type>(0),b,c,d,e,f,g,h)); \
  24. } \
  25. \
  26. type R_component_1() const \
  27. { \
  28. return(a); \
  29. } \
  30. \
  31. type R_component_2() const \
  32. { \
  33. return(b); \
  34. } \
  35. \
  36. type R_component_3() const \
  37. { \
  38. return(c); \
  39. } \
  40. \
  41. type R_component_4() const \
  42. { \
  43. return(d); \
  44. } \
  45. \
  46. type R_component_5() const \
  47. { \
  48. return(e); \
  49. } \
  50. \
  51. type R_component_6() const \
  52. { \
  53. return(f); \
  54. } \
  55. \
  56. type R_component_7() const \
  57. { \
  58. return(g); \
  59. } \
  60. \
  61. type R_component_8() const \
  62. { \
  63. return(h); \
  64. } \
  65. \
  66. ::std::complex<type> C_component_1() const \
  67. { \
  68. return(::std::complex<type>(a,b)); \
  69. } \
  70. \
  71. ::std::complex<type> C_component_2() const \
  72. { \
  73. return(::std::complex<type>(c,d)); \
  74. } \
  75. \
  76. ::std::complex<type> C_component_3() const \
  77. { \
  78. return(::std::complex<type>(e,f)); \
  79. } \
  80. \
  81. ::std::complex<type> C_component_4() const \
  82. { \
  83. return(::std::complex<type>(g,h)); \
  84. } \
  85. \
  86. ::boost::math::quaternion<type> H_component_1() const \
  87. { \
  88. return(::boost::math::quaternion<type>(a,b,c,d)); \
  89. } \
  90. \
  91. ::boost::math::quaternion<type> H_component_2() const \
  92. { \
  93. return(::boost::math::quaternion<type>(e,f,g,h)); \
  94. }
  95. #define BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(type) \
  96. template<typename X> \
  97. octonion<type> & operator = (octonion<X> const & a_affecter) \
  98. { \
  99. a = static_cast<type>(a_affecter.R_component_1()); \
  100. b = static_cast<type>(a_affecter.R_component_2()); \
  101. c = static_cast<type>(a_affecter.R_component_3()); \
  102. d = static_cast<type>(a_affecter.R_component_4()); \
  103. e = static_cast<type>(a_affecter.R_component_5()); \
  104. f = static_cast<type>(a_affecter.R_component_6()); \
  105. g = static_cast<type>(a_affecter.R_component_7()); \
  106. h = static_cast<type>(a_affecter.R_component_8()); \
  107. \
  108. return(*this); \
  109. } \
  110. \
  111. octonion<type> & operator = (octonion<type> const & a_affecter) \
  112. { \
  113. a = a_affecter.a; \
  114. b = a_affecter.b; \
  115. c = a_affecter.c; \
  116. d = a_affecter.d; \
  117. e = a_affecter.e; \
  118. f = a_affecter.f; \
  119. g = a_affecter.g; \
  120. h = a_affecter.h; \
  121. \
  122. return(*this); \
  123. } \
  124. \
  125. octonion<type> & operator = (type const & a_affecter) \
  126. { \
  127. a = a_affecter; \
  128. \
  129. b = c = d = e = f= g = h = static_cast<type>(0); \
  130. \
  131. return(*this); \
  132. } \
  133. \
  134. octonion<type> & operator = (::std::complex<type> const & a_affecter) \
  135. { \
  136. a = a_affecter.real(); \
  137. b = a_affecter.imag(); \
  138. \
  139. c = d = e = f = g = h = static_cast<type>(0); \
  140. \
  141. return(*this); \
  142. } \
  143. \
  144. octonion<type> & operator = (::boost::math::quaternion<type> const & a_affecter) \
  145. { \
  146. a = a_affecter.R_component_1(); \
  147. b = a_affecter.R_component_2(); \
  148. c = a_affecter.R_component_3(); \
  149. d = a_affecter.R_component_4(); \
  150. \
  151. e = f = g = h = static_cast<type>(0); \
  152. \
  153. return(*this); \
  154. }
  155. #define BOOST_OCTONION_MEMBER_DATA_GENERATOR(type) \
  156. type a; \
  157. type b; \
  158. type c; \
  159. type d; \
  160. type e; \
  161. type f; \
  162. type g; \
  163. type h; \
  164. // LCOV_EXCL_START
  165. // No code coverage for the generic case, like std::complex,
  166. // the The behavior of octonion is unspecified if T is not
  167. // one of float, double or long double.
  168. template<typename T>
  169. class octonion
  170. {
  171. public:
  172. using value_type = T;
  173. // constructor for O seen as R^8
  174. // (also default constructor)
  175. explicit octonion( T const & requested_a = T(),
  176. T const & requested_b = T(),
  177. T const & requested_c = T(),
  178. T const & requested_d = T(),
  179. T const & requested_e = T(),
  180. T const & requested_f = T(),
  181. T const & requested_g = T(),
  182. T const & requested_h = T())
  183. : a(requested_a),
  184. b(requested_b),
  185. c(requested_c),
  186. d(requested_d),
  187. e(requested_e),
  188. f(requested_f),
  189. g(requested_g),
  190. h(requested_h)
  191. {
  192. // nothing to do!
  193. }
  194. // constructor for H seen as C^4
  195. explicit octonion( ::std::complex<T> const & z0,
  196. ::std::complex<T> const & z1 = ::std::complex<T>(),
  197. ::std::complex<T> const & z2 = ::std::complex<T>(),
  198. ::std::complex<T> const & z3 = ::std::complex<T>())
  199. : a(z0.real()),
  200. b(z0.imag()),
  201. c(z1.real()),
  202. d(z1.imag()),
  203. e(z2.real()),
  204. f(z2.imag()),
  205. g(z3.real()),
  206. h(z3.imag())
  207. {
  208. // nothing to do!
  209. }
  210. // constructor for O seen as H^2
  211. explicit octonion( ::boost::math::quaternion<T> const & q0,
  212. ::boost::math::quaternion<T> const & q1 = ::boost::math::quaternion<T>())
  213. : a(q0.R_component_1()),
  214. b(q0.R_component_2()),
  215. c(q0.R_component_3()),
  216. d(q0.R_component_4()),
  217. e(q1.R_component_1()),
  218. f(q1.R_component_2()),
  219. g(q1.R_component_3()),
  220. h(q1.R_component_4())
  221. {
  222. // nothing to do!
  223. }
  224. // UNtemplated copy constructor
  225. octonion(const octonion&) = default;
  226. // templated copy constructor
  227. template<typename X>
  228. explicit octonion(octonion<X> const & a_recopier)
  229. : a(static_cast<T>(a_recopier.R_component_1())),
  230. b(static_cast<T>(a_recopier.R_component_2())),
  231. c(static_cast<T>(a_recopier.R_component_3())),
  232. d(static_cast<T>(a_recopier.R_component_4())),
  233. e(static_cast<T>(a_recopier.R_component_5())),
  234. f(static_cast<T>(a_recopier.R_component_6())),
  235. g(static_cast<T>(a_recopier.R_component_7())),
  236. h(static_cast<T>(a_recopier.R_component_8()))
  237. {
  238. // nothing to do!
  239. }
  240. // destructor
  241. ~octonion() = default;
  242. // accessors
  243. //
  244. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  245. // but unlike them there is no meaningful notion of "imaginary part".
  246. // Instead there is an "unreal part" which itself is an octonion, and usually
  247. // nothing simpler (as opposed to the complex number case).
  248. // However, for practicality, there are accessors for the other components
  249. // (these are necessary for the templated copy constructor, for instance).
  250. BOOST_OCTONION_ACCESSOR_GENERATOR(T)
  251. // assignment operators
  252. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(T)
  253. // other assignment-related operators
  254. //
  255. // NOTE: Octonion multiplication is *NOT* commutative;
  256. // symbolically, "q *= rhs;" means "q = q * rhs;"
  257. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  258. // octonion multiplication is also *NOT* associative
  259. octonion<T> & operator += (T const & rhs)
  260. {
  261. T at = a + rhs; // exception guard
  262. a = at;
  263. return(*this);
  264. }
  265. octonion<T> & operator += (::std::complex<T> const & rhs)
  266. {
  267. T at = a + rhs.real(); // exception guard
  268. T bt = b + rhs.imag(); // exception guard
  269. a = at;
  270. b = bt;
  271. return(*this);
  272. }
  273. octonion<T> & operator += (::boost::math::quaternion<T> const & rhs)
  274. {
  275. T at = a + rhs.R_component_1(); // exception guard
  276. T bt = b + rhs.R_component_2(); // exception guard
  277. T ct = c + rhs.R_component_3(); // exception guard
  278. T dt = d + rhs.R_component_4(); // exception guard
  279. a = at;
  280. b = bt;
  281. c = ct;
  282. d = dt;
  283. return(*this);
  284. }
  285. template<typename X>
  286. octonion<T> & operator += (octonion<X> const & rhs)
  287. {
  288. T at = a + static_cast<T>(rhs.R_component_1()); // exception guard
  289. T bt = b + static_cast<T>(rhs.R_component_2()); // exception guard
  290. T ct = c + static_cast<T>(rhs.R_component_3()); // exception guard
  291. T dt = d + static_cast<T>(rhs.R_component_4()); // exception guard
  292. T et = e + static_cast<T>(rhs.R_component_5()); // exception guard
  293. T ft = f + static_cast<T>(rhs.R_component_6()); // exception guard
  294. T gt = g + static_cast<T>(rhs.R_component_7()); // exception guard
  295. T ht = h + static_cast<T>(rhs.R_component_8()); // exception guard
  296. a = at;
  297. b = bt;
  298. c = ct;
  299. d = dt;
  300. e = et;
  301. f = ft;
  302. g = gt;
  303. h = ht;
  304. return(*this);
  305. }
  306. octonion<T> & operator -= (T const & rhs)
  307. {
  308. T at = a - rhs; // exception guard
  309. a = at;
  310. return(*this);
  311. }
  312. octonion<T> & operator -= (::std::complex<T> const & rhs)
  313. {
  314. T at = a - rhs.real(); // exception guard
  315. T bt = b - rhs.imag(); // exception guard
  316. a = at;
  317. b = bt;
  318. return(*this);
  319. }
  320. octonion<T> & operator -= (::boost::math::quaternion<T> const & rhs)
  321. {
  322. T at = a - rhs.R_component_1(); // exception guard
  323. T bt = b - rhs.R_component_2(); // exception guard
  324. T ct = c - rhs.R_component_3(); // exception guard
  325. T dt = d - rhs.R_component_4(); // exception guard
  326. a = at;
  327. b = bt;
  328. c = ct;
  329. d = dt;
  330. return(*this);
  331. }
  332. template<typename X>
  333. octonion<T> & operator -= (octonion<X> const & rhs)
  334. {
  335. T at = a - static_cast<T>(rhs.R_component_1()); // exception guard
  336. T bt = b - static_cast<T>(rhs.R_component_2()); // exception guard
  337. T ct = c - static_cast<T>(rhs.R_component_3()); // exception guard
  338. T dt = d - static_cast<T>(rhs.R_component_4()); // exception guard
  339. T et = e - static_cast<T>(rhs.R_component_5()); // exception guard
  340. T ft = f - static_cast<T>(rhs.R_component_6()); // exception guard
  341. T gt = g - static_cast<T>(rhs.R_component_7()); // exception guard
  342. T ht = h - static_cast<T>(rhs.R_component_8()); // exception guard
  343. a = at;
  344. b = bt;
  345. c = ct;
  346. d = dt;
  347. e = et;
  348. f = ft;
  349. g = gt;
  350. h = ht;
  351. return(*this);
  352. }
  353. octonion<T> & operator *= (T const & rhs)
  354. {
  355. T at = a * rhs; // exception guard
  356. T bt = b * rhs; // exception guard
  357. T ct = c * rhs; // exception guard
  358. T dt = d * rhs; // exception guard
  359. T et = e * rhs; // exception guard
  360. T ft = f * rhs; // exception guard
  361. T gt = g * rhs; // exception guard
  362. T ht = h * rhs; // exception guard
  363. a = at;
  364. b = bt;
  365. c = ct;
  366. d = dt;
  367. e = et;
  368. f = ft;
  369. g = gt;
  370. h = ht;
  371. return(*this);
  372. }
  373. octonion<T> & operator *= (::std::complex<T> const & rhs)
  374. {
  375. T ar = rhs.real();
  376. T br = rhs.imag();
  377. T at = +a*ar-b*br;
  378. T bt = +a*br+b*ar;
  379. T ct = +c*ar+d*br;
  380. T dt = -c*br+d*ar;
  381. T et = +e*ar+f*br;
  382. T ft = -e*br+f*ar;
  383. T gt = +g*ar-h*br;
  384. T ht = +g*br+h*ar;
  385. a = at;
  386. b = bt;
  387. c = ct;
  388. d = dt;
  389. e = et;
  390. f = ft;
  391. g = gt;
  392. h = ht;
  393. return(*this);
  394. }
  395. octonion<T> & operator *= (::boost::math::quaternion<T> const & rhs)
  396. {
  397. T ar = rhs.R_component_1();
  398. T br = rhs.R_component_2();
  399. T cr = rhs.R_component_2();
  400. T dr = rhs.R_component_2();
  401. T at = +a*ar-b*br-c*cr-d*dr;
  402. T bt = +a*br+b*ar+c*dr-d*cr;
  403. T ct = +a*cr-b*dr+c*ar+d*br;
  404. T dt = +a*dr+b*cr-c*br+d*ar;
  405. T et = +e*ar+f*br+g*cr+h*dr;
  406. T ft = -e*br+f*ar-g*dr+h*cr;
  407. T gt = -e*cr+f*dr+g*ar-h*br;
  408. T ht = -e*dr-f*cr+g*br+h*ar;
  409. a = at;
  410. b = bt;
  411. c = ct;
  412. d = dt;
  413. e = et;
  414. f = ft;
  415. g = gt;
  416. h = ht;
  417. return(*this);
  418. }
  419. template<typename X>
  420. octonion<T> & operator *= (octonion<X> const & rhs)
  421. {
  422. T ar = static_cast<T>(rhs.R_component_1());
  423. T br = static_cast<T>(rhs.R_component_2());
  424. T cr = static_cast<T>(rhs.R_component_3());
  425. T dr = static_cast<T>(rhs.R_component_4());
  426. T er = static_cast<T>(rhs.R_component_5());
  427. T fr = static_cast<T>(rhs.R_component_6());
  428. T gr = static_cast<T>(rhs.R_component_7());
  429. T hr = static_cast<T>(rhs.R_component_8());
  430. T at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr;
  431. T bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr;
  432. T ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr;
  433. T dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er;
  434. T et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr;
  435. T ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr;
  436. T gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br;
  437. T ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar;
  438. a = at;
  439. b = bt;
  440. c = ct;
  441. d = dt;
  442. e = et;
  443. f = ft;
  444. g = gt;
  445. h = ht;
  446. return(*this);
  447. }
  448. octonion<T> & operator /= (T const & rhs)
  449. {
  450. T at = a / rhs; // exception guard
  451. T bt = b / rhs; // exception guard
  452. T ct = c / rhs; // exception guard
  453. T dt = d / rhs; // exception guard
  454. T et = e / rhs; // exception guard
  455. T ft = f / rhs; // exception guard
  456. T gt = g / rhs; // exception guard
  457. T ht = h / rhs; // exception guard
  458. a = at;
  459. b = bt;
  460. c = ct;
  461. d = dt;
  462. e = et;
  463. f = ft;
  464. g = gt;
  465. h = ht;
  466. return(*this);
  467. }
  468. octonion<T> & operator /= (::std::complex<T> const & rhs)
  469. {
  470. T ar = rhs.real();
  471. T br = rhs.imag();
  472. T denominator = ar*ar+br*br;
  473. T at = (+a*ar-b*br)/denominator;
  474. T bt = (-a*br+b*ar)/denominator;
  475. T ct = (+c*ar-d*br)/denominator;
  476. T dt = (+c*br+d*ar)/denominator;
  477. T et = (+e*ar-f*br)/denominator;
  478. T ft = (+e*br+f*ar)/denominator;
  479. T gt = (+g*ar+h*br)/denominator;
  480. T ht = (+g*br+h*ar)/denominator;
  481. a = at;
  482. b = bt;
  483. c = ct;
  484. d = dt;
  485. e = et;
  486. f = ft;
  487. g = gt;
  488. h = ht;
  489. return(*this);
  490. }
  491. octonion<T> & operator /= (::boost::math::quaternion<T> const & rhs)
  492. {
  493. T ar = rhs.R_component_1();
  494. T br = rhs.R_component_2();
  495. T cr = rhs.R_component_2();
  496. T dr = rhs.R_component_2();
  497. T denominator = ar*ar+br*br+cr*cr+dr*dr;
  498. T at = (+a*ar+b*br+c*cr+d*dr)/denominator;
  499. T bt = (-a*br+b*ar-c*dr+d*cr)/denominator;
  500. T ct = (-a*cr+b*dr+c*ar-d*br)/denominator;
  501. T dt = (-a*dr-b*cr+c*br+d*ar)/denominator;
  502. T et = (+e*ar-f*br-g*cr-h*dr)/denominator;
  503. T ft = (+e*br+f*ar+g*dr-h*cr)/denominator;
  504. T gt = (+e*cr-f*dr+g*ar+h*br)/denominator;
  505. T ht = (+e*dr+f*cr-g*br+h*ar)/denominator;
  506. a = at;
  507. b = bt;
  508. c = ct;
  509. d = dt;
  510. e = et;
  511. f = ft;
  512. g = gt;
  513. h = ht;
  514. return(*this);
  515. }
  516. template<typename X>
  517. octonion<T> & operator /= (octonion<X> const & rhs)
  518. {
  519. T ar = static_cast<T>(rhs.R_component_1());
  520. T br = static_cast<T>(rhs.R_component_2());
  521. T cr = static_cast<T>(rhs.R_component_3());
  522. T dr = static_cast<T>(rhs.R_component_4());
  523. T er = static_cast<T>(rhs.R_component_5());
  524. T fr = static_cast<T>(rhs.R_component_6());
  525. T gr = static_cast<T>(rhs.R_component_7());
  526. T hr = static_cast<T>(rhs.R_component_8());
  527. T denominator = ar*ar+br*br+cr*cr+dr*dr+er*er+fr*fr+gr*gr+hr*hr;
  528. T at = (+a*ar+b*br+c*cr+d*dr+e*er+f*fr+g*gr+h*hr)/denominator;
  529. T bt = (-a*br+b*ar-c*dr+d*cr-e*fr+f*er+g*hr-h*gr)/denominator;
  530. T ct = (-a*cr+b*dr+c*ar-d*br-e*gr-f*hr+g*er+h*fr)/denominator;
  531. T dt = (-a*dr-b*cr+c*br+d*ar-e*hr+f*gr-g*fr+h*er)/denominator;
  532. T et = (-a*er+b*fr+c*gr+d*hr+e*ar-f*br-g*cr-h*dr)/denominator;
  533. T ft = (-a*fr-b*er+c*hr-d*gr+e*br+f*ar+g*dr-h*cr)/denominator;
  534. T gt = (-a*gr-b*hr-c*er+d*fr+e*cr-f*dr+g*ar+h*br)/denominator;
  535. T ht = (-a*hr+b*gr-c*fr-d*er+e*dr+f*cr-g*br+h*ar)/denominator;
  536. a = at;
  537. b = bt;
  538. c = ct;
  539. d = dt;
  540. e = et;
  541. f = ft;
  542. g = gt;
  543. h = ht;
  544. return(*this);
  545. }
  546. protected:
  547. BOOST_OCTONION_MEMBER_DATA_GENERATOR(T)
  548. private:
  549. };
  550. // LCOV_EXCL_STOP
  551. // declaration of octonion specialization
  552. template<> class octonion<float>;
  553. template<> class octonion<double>;
  554. template<> class octonion<long double>;
  555. // helper templates for converting copy constructors (declaration)
  556. namespace detail
  557. {
  558. template< typename T,
  559. typename U
  560. >
  561. octonion<T> octonion_type_converter(octonion<U> const & rhs);
  562. }
  563. // implementation of octonion specialization
  564. #define BOOST_OCTONION_CONSTRUCTOR_GENERATOR(type) \
  565. explicit octonion( type const & requested_a = static_cast<type>(0), \
  566. type const & requested_b = static_cast<type>(0), \
  567. type const & requested_c = static_cast<type>(0), \
  568. type const & requested_d = static_cast<type>(0), \
  569. type const & requested_e = static_cast<type>(0), \
  570. type const & requested_f = static_cast<type>(0), \
  571. type const & requested_g = static_cast<type>(0), \
  572. type const & requested_h = static_cast<type>(0)) \
  573. : a(requested_a), \
  574. b(requested_b), \
  575. c(requested_c), \
  576. d(requested_d), \
  577. e(requested_e), \
  578. f(requested_f), \
  579. g(requested_g), \
  580. h(requested_h) \
  581. { \
  582. } \
  583. \
  584. explicit octonion( ::std::complex<type> const & z0, \
  585. ::std::complex<type> const & z1 = ::std::complex<type>(), \
  586. ::std::complex<type> const & z2 = ::std::complex<type>(), \
  587. ::std::complex<type> const & z3 = ::std::complex<type>()) \
  588. : a(z0.real()), \
  589. b(z0.imag()), \
  590. c(z1.real()), \
  591. d(z1.imag()), \
  592. e(z2.real()), \
  593. f(z2.imag()), \
  594. g(z3.real()), \
  595. h(z3.imag()) \
  596. { \
  597. } \
  598. \
  599. explicit octonion( ::boost::math::quaternion<type> const & q0, \
  600. ::boost::math::quaternion<type> const & q1 = ::boost::math::quaternion<type>()) \
  601. : a(q0.R_component_1()), \
  602. b(q0.R_component_2()), \
  603. c(q0.R_component_3()), \
  604. d(q0.R_component_4()), \
  605. e(q1.R_component_1()), \
  606. f(q1.R_component_2()), \
  607. g(q1.R_component_3()), \
  608. h(q1.R_component_4()) \
  609. { \
  610. }
  611. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \
  612. octonion<type> & operator += (type const & rhs) \
  613. { \
  614. a += rhs; \
  615. \
  616. return(*this); \
  617. }
  618. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \
  619. octonion<type> & operator += (::std::complex<type> const & rhs) \
  620. { \
  621. a += rhs.real(); \
  622. b += rhs.imag(); \
  623. \
  624. return(*this); \
  625. }
  626. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \
  627. octonion<type> & operator += (::boost::math::quaternion<type> const & rhs) \
  628. { \
  629. a += rhs.R_component_1(); \
  630. b += rhs.R_component_2(); \
  631. c += rhs.R_component_3(); \
  632. d += rhs.R_component_4(); \
  633. \
  634. return(*this); \
  635. }
  636. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) \
  637. template<typename X> \
  638. octonion<type> & operator += (octonion<X> const & rhs) \
  639. { \
  640. a += static_cast<type>(rhs.R_component_1()); \
  641. b += static_cast<type>(rhs.R_component_2()); \
  642. c += static_cast<type>(rhs.R_component_3()); \
  643. d += static_cast<type>(rhs.R_component_4()); \
  644. e += static_cast<type>(rhs.R_component_5()); \
  645. f += static_cast<type>(rhs.R_component_6()); \
  646. g += static_cast<type>(rhs.R_component_7()); \
  647. h += static_cast<type>(rhs.R_component_8()); \
  648. \
  649. return(*this); \
  650. }
  651. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \
  652. octonion<type> & operator -= (type const & rhs) \
  653. { \
  654. a -= rhs; \
  655. \
  656. return(*this); \
  657. }
  658. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \
  659. octonion<type> & operator -= (::std::complex<type> const & rhs) \
  660. { \
  661. a -= rhs.real(); \
  662. b -= rhs.imag(); \
  663. \
  664. return(*this); \
  665. }
  666. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \
  667. octonion<type> & operator -= (::boost::math::quaternion<type> const & rhs) \
  668. { \
  669. a -= rhs.R_component_1(); \
  670. b -= rhs.R_component_2(); \
  671. c -= rhs.R_component_3(); \
  672. d -= rhs.R_component_4(); \
  673. \
  674. return(*this); \
  675. }
  676. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) \
  677. template<typename X> \
  678. octonion<type> & operator -= (octonion<X> const & rhs) \
  679. { \
  680. a -= static_cast<type>(rhs.R_component_1()); \
  681. b -= static_cast<type>(rhs.R_component_2()); \
  682. c -= static_cast<type>(rhs.R_component_3()); \
  683. d -= static_cast<type>(rhs.R_component_4()); \
  684. e -= static_cast<type>(rhs.R_component_5()); \
  685. f -= static_cast<type>(rhs.R_component_6()); \
  686. g -= static_cast<type>(rhs.R_component_7()); \
  687. h -= static_cast<type>(rhs.R_component_8()); \
  688. \
  689. return(*this); \
  690. }
  691. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \
  692. octonion<type> & operator *= (type const & rhs) \
  693. { \
  694. a *= rhs; \
  695. b *= rhs; \
  696. c *= rhs; \
  697. d *= rhs; \
  698. e *= rhs; \
  699. f *= rhs; \
  700. g *= rhs; \
  701. h *= rhs; \
  702. \
  703. return(*this); \
  704. }
  705. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \
  706. octonion<type> & operator *= (::std::complex<type> const & rhs) \
  707. { \
  708. type ar = rhs.real(); \
  709. type br = rhs.imag(); \
  710. \
  711. type at = +a*ar-b*br; \
  712. type bt = +a*br+b*ar; \
  713. type ct = +c*ar+d*br; \
  714. type dt = -c*br+d*ar; \
  715. type et = +e*ar+f*br; \
  716. type ft = -e*br+f*ar; \
  717. type gt = +g*ar-h*br; \
  718. type ht = +g*br+h*ar; \
  719. \
  720. a = at; \
  721. b = bt; \
  722. c = ct; \
  723. d = dt; \
  724. e = et; \
  725. f = ft; \
  726. g = gt; \
  727. h = ht; \
  728. \
  729. return(*this); \
  730. }
  731. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \
  732. octonion<type> & operator *= (::boost::math::quaternion<type> const & rhs) \
  733. { \
  734. type ar = rhs.R_component_1(); \
  735. type br = rhs.R_component_2(); \
  736. type cr = rhs.R_component_2(); \
  737. type dr = rhs.R_component_2(); \
  738. \
  739. type at = +a*ar-b*br-c*cr-d*dr; \
  740. type bt = +a*br+b*ar+c*dr-d*cr; \
  741. type ct = +a*cr-b*dr+c*ar+d*br; \
  742. type dt = +a*dr+b*cr-c*br+d*ar; \
  743. type et = +e*ar+f*br+g*cr+h*dr; \
  744. type ft = -e*br+f*ar-g*dr+h*cr; \
  745. type gt = -e*cr+f*dr+g*ar-h*br; \
  746. type ht = -e*dr-f*cr+g*br+h*ar; \
  747. \
  748. a = at; \
  749. b = bt; \
  750. c = ct; \
  751. d = dt; \
  752. e = et; \
  753. f = ft; \
  754. g = gt; \
  755. h = ht; \
  756. \
  757. return(*this); \
  758. }
  759. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) \
  760. template<typename X> \
  761. octonion<type> & operator *= (octonion<X> const & rhs) \
  762. { \
  763. type ar = static_cast<type>(rhs.R_component_1()); \
  764. type br = static_cast<type>(rhs.R_component_2()); \
  765. type cr = static_cast<type>(rhs.R_component_3()); \
  766. type dr = static_cast<type>(rhs.R_component_4()); \
  767. type er = static_cast<type>(rhs.R_component_5()); \
  768. type fr = static_cast<type>(rhs.R_component_6()); \
  769. type gr = static_cast<type>(rhs.R_component_7()); \
  770. type hr = static_cast<type>(rhs.R_component_8()); \
  771. \
  772. type at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; \
  773. type bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; \
  774. type ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; \
  775. type dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; \
  776. type et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; \
  777. type ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; \
  778. type gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; \
  779. type ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; \
  780. \
  781. a = at; \
  782. b = bt; \
  783. c = ct; \
  784. d = dt; \
  785. e = et; \
  786. f = ft; \
  787. g = gt; \
  788. h = ht; \
  789. \
  790. return(*this); \
  791. }
  792. // There is quite a lot of repetition in the code below. This is intentional.
  793. // The last conditional block is the normal form, and the others merely
  794. // consist of workarounds for various compiler deficiencies. Hopefully, when
  795. // more compilers are conformant and we can retire support for those that are
  796. // not, we will be able to remove the clutter. This is makes the situation
  797. // (painfully) explicit.
  798. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \
  799. octonion<type> & operator /= (type const & rhs) \
  800. { \
  801. a /= rhs; \
  802. b /= rhs; \
  803. c /= rhs; \
  804. d /= rhs; \
  805. \
  806. return(*this); \
  807. }
  808. #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
  809. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
  810. octonion<type> & operator /= (::std::complex<type> const & rhs) \
  811. { \
  812. using ::std::valarray; \
  813. using ::std::abs; \
  814. \
  815. valarray<type> tr(2); \
  816. \
  817. tr[0] = rhs.real(); \
  818. tr[1] = rhs.imag(); \
  819. \
  820. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  821. \
  822. tr *= mixam; \
  823. \
  824. valarray<type> tt(8); \
  825. \
  826. tt[0] = +a*tr[0]-b*tr[1]; \
  827. tt[1] = -a*tr[1]+b*tr[0]; \
  828. tt[2] = +c*tr[0]-d*tr[1]; \
  829. tt[3] = +c*tr[1]+d*tr[0]; \
  830. tt[4] = +e*tr[0]-f*tr[1]; \
  831. tt[5] = +e*tr[1]+f*tr[0]; \
  832. tt[6] = +g*tr[0]+h*tr[1]; \
  833. tt[7] = +g*tr[1]+h*tr[0]; \
  834. \
  835. tr *= tr; \
  836. \
  837. tt *= (mixam/tr.sum()); \
  838. \
  839. a = tt[0]; \
  840. b = tt[1]; \
  841. c = tt[2]; \
  842. d = tt[3]; \
  843. e = tt[4]; \
  844. f = tt[5]; \
  845. g = tt[6]; \
  846. h = tt[7]; \
  847. \
  848. return(*this); \
  849. }
  850. #else
  851. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
  852. octonion<type> & operator /= (::std::complex<type> const & rhs) \
  853. { \
  854. using ::std::valarray; \
  855. \
  856. valarray<type> tr(2); \
  857. \
  858. tr[0] = rhs.real(); \
  859. tr[1] = rhs.imag(); \
  860. \
  861. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  862. \
  863. tr *= mixam; \
  864. \
  865. valarray<type> tt(8); \
  866. \
  867. tt[0] = +a*tr[0]-b*tr[1]; \
  868. tt[1] = -a*tr[1]+b*tr[0]; \
  869. tt[2] = +c*tr[0]-d*tr[1]; \
  870. tt[3] = +c*tr[1]+d*tr[0]; \
  871. tt[4] = +e*tr[0]-f*tr[1]; \
  872. tt[5] = +e*tr[1]+f*tr[0]; \
  873. tt[6] = +g*tr[0]+h*tr[1]; \
  874. tt[7] = +g*tr[1]+h*tr[0]; \
  875. \
  876. tr *= tr; \
  877. \
  878. tt *= (mixam/tr.sum()); \
  879. \
  880. a = tt[0]; \
  881. b = tt[1]; \
  882. c = tt[2]; \
  883. d = tt[3]; \
  884. e = tt[4]; \
  885. f = tt[5]; \
  886. g = tt[6]; \
  887. h = tt[7]; \
  888. \
  889. return(*this); \
  890. }
  891. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  892. #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
  893. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
  894. octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \
  895. { \
  896. using ::std::valarray; \
  897. using ::std::abs; \
  898. \
  899. valarray<type> tr(4); \
  900. \
  901. tr[0] = static_cast<type>(rhs.R_component_1()); \
  902. tr[1] = static_cast<type>(rhs.R_component_2()); \
  903. tr[2] = static_cast<type>(rhs.R_component_3()); \
  904. tr[3] = static_cast<type>(rhs.R_component_4()); \
  905. \
  906. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  907. \
  908. tr *= mixam; \
  909. \
  910. valarray<type> tt(8); \
  911. \
  912. tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \
  913. tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \
  914. tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \
  915. tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \
  916. tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
  917. tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
  918. tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
  919. tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
  920. \
  921. tr *= tr; \
  922. \
  923. tt *= (mixam/tr.sum()); \
  924. \
  925. a = tt[0]; \
  926. b = tt[1]; \
  927. c = tt[2]; \
  928. d = tt[3]; \
  929. e = tt[4]; \
  930. f = tt[5]; \
  931. g = tt[6]; \
  932. h = tt[7]; \
  933. \
  934. return(*this); \
  935. }
  936. #else
  937. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
  938. octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \
  939. { \
  940. using ::std::valarray; \
  941. \
  942. valarray<type> tr(4); \
  943. \
  944. tr[0] = static_cast<type>(rhs.R_component_1()); \
  945. tr[1] = static_cast<type>(rhs.R_component_2()); \
  946. tr[2] = static_cast<type>(rhs.R_component_3()); \
  947. tr[3] = static_cast<type>(rhs.R_component_4()); \
  948. \
  949. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  950. \
  951. tr *= mixam; \
  952. \
  953. valarray<type> tt(8); \
  954. \
  955. tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \
  956. tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \
  957. tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \
  958. tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \
  959. tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
  960. tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
  961. tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
  962. tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
  963. \
  964. tr *= tr; \
  965. \
  966. tt *= (mixam/tr.sum()); \
  967. \
  968. a = tt[0]; \
  969. b = tt[1]; \
  970. c = tt[2]; \
  971. d = tt[3]; \
  972. e = tt[4]; \
  973. f = tt[5]; \
  974. g = tt[6]; \
  975. h = tt[7]; \
  976. \
  977. return(*this); \
  978. }
  979. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  980. #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
  981. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \
  982. template<typename X> \
  983. octonion<type> & operator /= (octonion<X> const & rhs) \
  984. { \
  985. using ::std::valarray; \
  986. using ::std::abs; \
  987. \
  988. valarray<type> tr(8); \
  989. \
  990. tr[0] = static_cast<type>(rhs.R_component_1()); \
  991. tr[1] = static_cast<type>(rhs.R_component_2()); \
  992. tr[2] = static_cast<type>(rhs.R_component_3()); \
  993. tr[3] = static_cast<type>(rhs.R_component_4()); \
  994. tr[4] = static_cast<type>(rhs.R_component_5()); \
  995. tr[5] = static_cast<type>(rhs.R_component_6()); \
  996. tr[6] = static_cast<type>(rhs.R_component_7()); \
  997. tr[7] = static_cast<type>(rhs.R_component_8()); \
  998. \
  999. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  1000. \
  1001. tr *= mixam; \
  1002. \
  1003. valarray<type> tt(8); \
  1004. \
  1005. tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \
  1006. tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \
  1007. tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \
  1008. tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \
  1009. tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
  1010. tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
  1011. tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
  1012. tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
  1013. \
  1014. tr *= tr; \
  1015. \
  1016. tt *= (mixam/tr.sum()); \
  1017. \
  1018. a = tt[0]; \
  1019. b = tt[1]; \
  1020. c = tt[2]; \
  1021. d = tt[3]; \
  1022. e = tt[4]; \
  1023. f = tt[5]; \
  1024. g = tt[6]; \
  1025. h = tt[7]; \
  1026. \
  1027. return(*this); \
  1028. }
  1029. #else
  1030. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \
  1031. template<typename X> \
  1032. octonion<type> & operator /= (octonion<X> const & rhs) \
  1033. { \
  1034. using ::std::valarray; \
  1035. \
  1036. valarray<type> tr(8); \
  1037. \
  1038. tr[0] = static_cast<type>(rhs.R_component_1()); \
  1039. tr[1] = static_cast<type>(rhs.R_component_2()); \
  1040. tr[2] = static_cast<type>(rhs.R_component_3()); \
  1041. tr[3] = static_cast<type>(rhs.R_component_4()); \
  1042. tr[4] = static_cast<type>(rhs.R_component_5()); \
  1043. tr[5] = static_cast<type>(rhs.R_component_6()); \
  1044. tr[6] = static_cast<type>(rhs.R_component_7()); \
  1045. tr[7] = static_cast<type>(rhs.R_component_8()); \
  1046. \
  1047. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  1048. \
  1049. tr *= mixam; \
  1050. \
  1051. valarray<type> tt(8); \
  1052. \
  1053. tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \
  1054. tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \
  1055. tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \
  1056. tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \
  1057. tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
  1058. tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
  1059. tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
  1060. tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
  1061. \
  1062. tr *= tr; \
  1063. \
  1064. tt *= (mixam/tr.sum()); \
  1065. \
  1066. a = tt[0]; \
  1067. b = tt[1]; \
  1068. c = tt[2]; \
  1069. d = tt[3]; \
  1070. e = tt[4]; \
  1071. f = tt[5]; \
  1072. g = tt[6]; \
  1073. h = tt[7]; \
  1074. \
  1075. return(*this); \
  1076. }
  1077. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  1078. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \
  1079. BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \
  1080. BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \
  1081. BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \
  1082. BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type)
  1083. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \
  1084. BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \
  1085. BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \
  1086. BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \
  1087. BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type)
  1088. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \
  1089. BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \
  1090. BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \
  1091. BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \
  1092. BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type)
  1093. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR(type) \
  1094. BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \
  1095. BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
  1096. BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
  1097. BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type)
  1098. #define BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(type) \
  1099. BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \
  1100. BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \
  1101. BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \
  1102. BOOST_OCTONION_MEMBER_DIV_GENERATOR(type)
  1103. template<>
  1104. class octonion<float>
  1105. {
  1106. public:
  1107. using value_type = float;
  1108. BOOST_OCTONION_CONSTRUCTOR_GENERATOR(float)
  1109. // UNtemplated copy constructor
  1110. octonion(const octonion&) = default;
  1111. // explicit copy constructors (precision-losing converters)
  1112. explicit octonion(octonion<double> const & a_recopier)
  1113. {
  1114. *this = detail::octonion_type_converter<float, double>(a_recopier);
  1115. }
  1116. explicit octonion(octonion<long double> const & a_recopier)
  1117. {
  1118. *this = detail::octonion_type_converter<float, long double>(a_recopier);
  1119. }
  1120. // destructor
  1121. ~octonion() = default;
  1122. // accessors
  1123. //
  1124. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  1125. // but unlike them there is no meaningful notion of "imaginary part".
  1126. // Instead there is an "unreal part" which itself is an octonion, and usually
  1127. // nothing simpler (as opposed to the complex number case).
  1128. // However, for practicality, there are accessors for the other components
  1129. // (these are necessary for the templated copy constructor, for instance).
  1130. BOOST_OCTONION_ACCESSOR_GENERATOR(float)
  1131. // assignment operators
  1132. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(float)
  1133. // other assignment-related operators
  1134. //
  1135. // NOTE: Octonion multiplication is *NOT* commutative;
  1136. // symbolically, "q *= rhs;" means "q = q * rhs;"
  1137. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  1138. // octonion multiplication is also *NOT* associative
  1139. BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(float)
  1140. protected:
  1141. BOOST_OCTONION_MEMBER_DATA_GENERATOR(float)
  1142. };
  1143. template<>
  1144. class octonion<double>
  1145. {
  1146. public:
  1147. using value_type = double;
  1148. BOOST_OCTONION_CONSTRUCTOR_GENERATOR(double)
  1149. // Untemplated copy constructor
  1150. octonion(const octonion&) = default;
  1151. // converting copy constructor
  1152. explicit octonion(octonion<float> const & a_recopier)
  1153. {
  1154. *this = detail::octonion_type_converter<double, float>(a_recopier);
  1155. }
  1156. // explicit copy constructors (precision-losing converters)
  1157. explicit octonion(octonion<long double> const & a_recopier)
  1158. {
  1159. *this = detail::octonion_type_converter<double, long double>(a_recopier);
  1160. }
  1161. // destructor
  1162. // (this is taken care of by the compiler itself)
  1163. // accessors
  1164. //
  1165. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  1166. // but unlike them there is no meaningful notion of "imaginary part".
  1167. // Instead there is an "unreal part" which itself is an octonion, and usually
  1168. // nothing simpler (as opposed to the complex number case).
  1169. // However, for practicality, there are accessors for the other components
  1170. // (these are necessary for the templated copy constructor, for instance).
  1171. BOOST_OCTONION_ACCESSOR_GENERATOR(double)
  1172. // assignment operators
  1173. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(double)
  1174. // other assignment-related operators
  1175. //
  1176. // NOTE: Octonion multiplication is *NOT* commutative;
  1177. // symbolically, "q *= rhs;" means "q = q * rhs;"
  1178. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  1179. // octonion multiplication is also *NOT* associative
  1180. BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(double)
  1181. protected:
  1182. BOOST_OCTONION_MEMBER_DATA_GENERATOR(double)
  1183. };
  1184. template<>
  1185. class octonion<long double>
  1186. {
  1187. public:
  1188. using value_type = long double;
  1189. BOOST_OCTONION_CONSTRUCTOR_GENERATOR(long double)
  1190. // UNtemplated copy constructor
  1191. octonion(const octonion&) = default;
  1192. // converting copy constructor
  1193. explicit octonion(octonion<float> const & a_recopier)
  1194. {
  1195. *this = detail::octonion_type_converter<long double, float>(a_recopier);
  1196. }
  1197. explicit octonion(octonion<double> const & a_recopier)
  1198. {
  1199. *this = detail::octonion_type_converter<long double, double>(a_recopier);
  1200. }
  1201. // destructor
  1202. // (this is taken care of by the compiler itself)
  1203. // accessors
  1204. //
  1205. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  1206. // but unlike them there is no meaningful notion of "imaginary part".
  1207. // Instead there is an "unreal part" which itself is an octonion, and usually
  1208. // nothing simpler (as opposed to the complex number case).
  1209. // However, for practicality, there are accessors for the other components
  1210. // (these are necessary for the templated copy constructor, for instance).
  1211. BOOST_OCTONION_ACCESSOR_GENERATOR(long double)
  1212. // assignment operators
  1213. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(long double)
  1214. // other assignment-related operators
  1215. //
  1216. // NOTE: Octonion multiplication is *NOT* commutative;
  1217. // symbolically, "q *= rhs;" means "q = q * rhs;"
  1218. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  1219. // octonion multiplication is also *NOT* associative
  1220. BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(long double)
  1221. protected:
  1222. BOOST_OCTONION_MEMBER_DATA_GENERATOR(long double)
  1223. private:
  1224. };
  1225. #undef BOOST_OCTONION_CONSTRUCTOR_GENERATOR
  1226. #undef BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR
  1227. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR
  1228. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR
  1229. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR
  1230. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR
  1231. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_1
  1232. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_2
  1233. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_3
  1234. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_4
  1235. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_1
  1236. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_2
  1237. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_3
  1238. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_4
  1239. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_1
  1240. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_2
  1241. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_3
  1242. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_4
  1243. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_1
  1244. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_2
  1245. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_3
  1246. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_4
  1247. #undef BOOST_OCTONION_MEMBER_DATA_GENERATOR
  1248. #undef BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR
  1249. #undef BOOST_OCTONION_ACCESSOR_GENERATOR
  1250. // operators
  1251. #define BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) \
  1252. { \
  1253. octonion<T> res(lhs); \
  1254. res op##= rhs; \
  1255. return(res); \
  1256. }
  1257. #define BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \
  1258. template<typename T> \
  1259. inline octonion<T> operator op (T const & lhs, octonion<T> const & rhs) \
  1260. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1261. #define BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \
  1262. template<typename T> \
  1263. inline octonion<T> operator op (octonion<T> const & lhs, T const & rhs) \
  1264. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1265. #define BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \
  1266. template<typename T> \
  1267. inline octonion<T> operator op (::std::complex<T> const & lhs, octonion<T> const & rhs) \
  1268. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1269. #define BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \
  1270. template<typename T> \
  1271. inline octonion<T> operator op (octonion<T> const & lhs, ::std::complex<T> const & rhs) \
  1272. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1273. #define BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \
  1274. template<typename T> \
  1275. inline octonion<T> operator op (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs) \
  1276. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1277. #define BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \
  1278. template<typename T> \
  1279. inline octonion<T> operator op (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs) \
  1280. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1281. #define BOOST_OCTONION_OPERATOR_GENERATOR_4(op) \
  1282. template<typename T> \
  1283. inline octonion<T> operator op (octonion<T> const & lhs, octonion<T> const & rhs) \
  1284. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1285. #define BOOST_OCTONION_OPERATOR_GENERATOR(op) \
  1286. BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \
  1287. BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \
  1288. BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \
  1289. BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \
  1290. BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \
  1291. BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \
  1292. BOOST_OCTONION_OPERATOR_GENERATOR_4(op)
  1293. BOOST_OCTONION_OPERATOR_GENERATOR(+)
  1294. BOOST_OCTONION_OPERATOR_GENERATOR(-)
  1295. BOOST_OCTONION_OPERATOR_GENERATOR(*)
  1296. BOOST_OCTONION_OPERATOR_GENERATOR(/)
  1297. #undef BOOST_OCTONION_OPERATOR_GENERATOR
  1298. #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_L
  1299. #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_R
  1300. #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_L
  1301. #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_R
  1302. #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_L
  1303. #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_R
  1304. #undef BOOST_OCTONION_OPERATOR_GENERATOR_4
  1305. #undef BOOST_OCTONION_OPERATOR_GENERATOR_BODY
  1306. template<typename T>
  1307. inline octonion<T> operator + (octonion<T> const & o)
  1308. {
  1309. return(o);
  1310. }
  1311. template<typename T>
  1312. inline octonion<T> operator - (octonion<T> const & o)
  1313. {
  1314. return(octonion<T>(-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()));
  1315. }
  1316. template<typename T>
  1317. inline bool operator == (T const & lhs, octonion<T> const & rhs)
  1318. {
  1319. return(
  1320. (rhs.R_component_1() == lhs)&&
  1321. (rhs.R_component_2() == static_cast<T>(0))&&
  1322. (rhs.R_component_3() == static_cast<T>(0))&&
  1323. (rhs.R_component_4() == static_cast<T>(0))&&
  1324. (rhs.R_component_5() == static_cast<T>(0))&&
  1325. (rhs.R_component_6() == static_cast<T>(0))&&
  1326. (rhs.R_component_7() == static_cast<T>(0))&&
  1327. (rhs.R_component_8() == static_cast<T>(0))
  1328. );
  1329. }
  1330. template<typename T>
  1331. inline bool operator == (octonion<T> const & lhs, T const & rhs)
  1332. {
  1333. return(
  1334. (lhs.R_component_1() == rhs)&&
  1335. (lhs.R_component_2() == static_cast<T>(0))&&
  1336. (lhs.R_component_3() == static_cast<T>(0))&&
  1337. (lhs.R_component_4() == static_cast<T>(0))&&
  1338. (lhs.R_component_5() == static_cast<T>(0))&&
  1339. (lhs.R_component_6() == static_cast<T>(0))&&
  1340. (lhs.R_component_7() == static_cast<T>(0))&&
  1341. (lhs.R_component_8() == static_cast<T>(0))
  1342. );
  1343. }
  1344. template<typename T>
  1345. inline bool operator == (::std::complex<T> const & lhs, octonion<T> const & rhs)
  1346. {
  1347. return(
  1348. (rhs.R_component_1() == lhs.real())&&
  1349. (rhs.R_component_2() == lhs.imag())&&
  1350. (rhs.R_component_3() == static_cast<T>(0))&&
  1351. (rhs.R_component_4() == static_cast<T>(0))&&
  1352. (rhs.R_component_5() == static_cast<T>(0))&&
  1353. (rhs.R_component_6() == static_cast<T>(0))&&
  1354. (rhs.R_component_7() == static_cast<T>(0))&&
  1355. (rhs.R_component_8() == static_cast<T>(0))
  1356. );
  1357. }
  1358. template<typename T>
  1359. inline bool operator == (octonion<T> const & lhs, ::std::complex<T> const & rhs)
  1360. {
  1361. return(
  1362. (lhs.R_component_1() == rhs.real())&&
  1363. (lhs.R_component_2() == rhs.imag())&&
  1364. (lhs.R_component_3() == static_cast<T>(0))&&
  1365. (lhs.R_component_4() == static_cast<T>(0))&&
  1366. (lhs.R_component_5() == static_cast<T>(0))&&
  1367. (lhs.R_component_6() == static_cast<T>(0))&&
  1368. (lhs.R_component_7() == static_cast<T>(0))&&
  1369. (lhs.R_component_8() == static_cast<T>(0))
  1370. );
  1371. }
  1372. template<typename T>
  1373. inline bool operator == (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs)
  1374. {
  1375. return(
  1376. (rhs.R_component_1() == lhs.R_component_1())&&
  1377. (rhs.R_component_2() == lhs.R_component_2())&&
  1378. (rhs.R_component_3() == lhs.R_component_3())&&
  1379. (rhs.R_component_4() == lhs.R_component_4())&&
  1380. (rhs.R_component_5() == static_cast<T>(0))&&
  1381. (rhs.R_component_6() == static_cast<T>(0))&&
  1382. (rhs.R_component_7() == static_cast<T>(0))&&
  1383. (rhs.R_component_8() == static_cast<T>(0))
  1384. );
  1385. }
  1386. template<typename T>
  1387. inline bool operator == (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs)
  1388. {
  1389. return(
  1390. (lhs.R_component_1() == rhs.R_component_1())&&
  1391. (lhs.R_component_2() == rhs.R_component_2())&&
  1392. (lhs.R_component_3() == rhs.R_component_3())&&
  1393. (lhs.R_component_4() == rhs.R_component_4())&&
  1394. (lhs.R_component_5() == static_cast<T>(0))&&
  1395. (lhs.R_component_6() == static_cast<T>(0))&&
  1396. (lhs.R_component_7() == static_cast<T>(0))&&
  1397. (lhs.R_component_8() == static_cast<T>(0))
  1398. );
  1399. }
  1400. template<typename T>
  1401. inline bool operator == (octonion<T> const & lhs, octonion<T> const & rhs)
  1402. {
  1403. return(
  1404. (rhs.R_component_1() == lhs.R_component_1())&&
  1405. (rhs.R_component_2() == lhs.R_component_2())&&
  1406. (rhs.R_component_3() == lhs.R_component_3())&&
  1407. (rhs.R_component_4() == lhs.R_component_4())&&
  1408. (rhs.R_component_5() == lhs.R_component_5())&&
  1409. (rhs.R_component_6() == lhs.R_component_6())&&
  1410. (rhs.R_component_7() == lhs.R_component_7())&&
  1411. (rhs.R_component_8() == lhs.R_component_8())
  1412. );
  1413. }
  1414. #define BOOST_OCTONION_NOT_EQUAL_GENERATOR \
  1415. { \
  1416. return(!(lhs == rhs)); \
  1417. }
  1418. template<typename T>
  1419. inline bool operator != (T const & lhs, octonion<T> const & rhs)
  1420. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1421. template<typename T>
  1422. inline bool operator != (octonion<T> const & lhs, T const & rhs)
  1423. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1424. template<typename T>
  1425. inline bool operator != (::std::complex<T> const & lhs, octonion<T> const & rhs)
  1426. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1427. template<typename T>
  1428. inline bool operator != (octonion<T> const & lhs, ::std::complex<T> const & rhs)
  1429. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1430. template<typename T>
  1431. inline bool operator != (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs)
  1432. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1433. template<typename T>
  1434. inline bool operator != (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs)
  1435. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1436. template<typename T>
  1437. inline bool operator != (octonion<T> const & lhs, octonion<T> const & rhs)
  1438. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1439. #undef BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1440. // LCOV_EXCL_START
  1441. // Something like 2,100 lines of input-streaming up to line 3,800 and beyond.
  1442. // Note: the default values in the constructors of the complex and quaternions make for
  1443. // a very complex and ambiguous situation; we have made choices to disambiguate.
  1444. template<typename T, typename charT, class traits>
  1445. ::std::basic_istream<charT,traits> & operator >> ( ::std::basic_istream<charT,traits> & is,
  1446. octonion<T> & o)
  1447. {
  1448. #ifdef BOOST_NO_STD_LOCALE
  1449. #else
  1450. const ::std::ctype<charT> & ct = ::std::use_facet< ::std::ctype<charT> >(is.getloc());
  1451. #endif /* BOOST_NO_STD_LOCALE */
  1452. T a = T();
  1453. T b = T();
  1454. T c = T();
  1455. T d = T();
  1456. T e = T();
  1457. T f = T();
  1458. T g = T();
  1459. T h = T();
  1460. ::std::complex<T> u = ::std::complex<T>();
  1461. ::std::complex<T> v = ::std::complex<T>();
  1462. ::std::complex<T> x = ::std::complex<T>();
  1463. ::std::complex<T> y = ::std::complex<T>();
  1464. ::boost::math::quaternion<T> p = ::boost::math::quaternion<T>();
  1465. ::boost::math::quaternion<T> q = ::boost::math::quaternion<T>();
  1466. charT ch = charT();
  1467. char cc;
  1468. is >> ch; // get the first lexeme
  1469. if (!is.good()) goto finish;
  1470. #ifdef BOOST_NO_STD_LOCALE
  1471. cc = ch;
  1472. #else
  1473. cc = ct.narrow(ch, char());
  1474. #endif /* BOOST_NO_STD_LOCALE */
  1475. if (cc == '(') // read "("
  1476. {
  1477. is >> ch; // get the second lexeme
  1478. if (!is.good()) goto finish;
  1479. #ifdef BOOST_NO_STD_LOCALE
  1480. cc = ch;
  1481. #else
  1482. cc = ct.narrow(ch, char());
  1483. #endif /* BOOST_NO_STD_LOCALE */
  1484. if (cc == '(') // read "(("
  1485. {
  1486. is >> ch; // get the third lexeme
  1487. if (!is.good()) goto finish;
  1488. #ifdef BOOST_NO_STD_LOCALE
  1489. cc = ch;
  1490. #else
  1491. cc = ct.narrow(ch, char());
  1492. #endif /* BOOST_NO_STD_LOCALE */
  1493. if (cc == '(') // read "((("
  1494. {
  1495. is.putback(ch);
  1496. is >> u; // read "((u"
  1497. if (!is.good()) goto finish;
  1498. is >> ch; // get the next lexeme
  1499. if (!is.good()) goto finish;
  1500. #ifdef BOOST_NO_STD_LOCALE
  1501. cc = ch;
  1502. #else
  1503. cc = ct.narrow(ch, char());
  1504. #endif /* BOOST_NO_STD_LOCALE */
  1505. if (cc == ')') // read "((u)"
  1506. {
  1507. is >> ch; // get the next lexeme
  1508. if (!is.good()) goto finish;
  1509. #ifdef BOOST_NO_STD_LOCALE
  1510. cc = ch;
  1511. #else
  1512. cc = ct.narrow(ch, char());
  1513. #endif /* BOOST_NO_STD_LOCALE */
  1514. if (cc == ')') // format: (((a))), (((a,b)))
  1515. {
  1516. o = octonion<T>(u);
  1517. }
  1518. else if (cc == ',') // read "((u),"
  1519. {
  1520. p = ::boost::math::quaternion<T>(u);
  1521. is >> q; // read "((u),q"
  1522. if (!is.good()) goto finish;
  1523. is >> ch; // get the next lexeme
  1524. if (!is.good()) goto finish;
  1525. #ifdef BOOST_NO_STD_LOCALE
  1526. cc = ch;
  1527. #else
  1528. cc = ct.narrow(ch, char());
  1529. #endif /* BOOST_NO_STD_LOCALE */
  1530. if (cc == ')') // format: (((a)),q), (((a,b)),q)
  1531. {
  1532. o = octonion<T>(p,q);
  1533. }
  1534. else // error
  1535. {
  1536. is.setstate(::std::ios_base::failbit);
  1537. }
  1538. }
  1539. else // error
  1540. {
  1541. is.setstate(::std::ios_base::failbit);
  1542. }
  1543. }
  1544. else if (cc ==',') // read "((u,"
  1545. {
  1546. is >> v; // read "((u,v"
  1547. if (!is.good()) goto finish;
  1548. is >> ch; // get the next lexeme
  1549. if (!is.good()) goto finish;
  1550. #ifdef BOOST_NO_STD_LOCALE
  1551. cc = ch;
  1552. #else
  1553. cc = ct.narrow(ch, char());
  1554. #endif /* BOOST_NO_STD_LOCALE */
  1555. if (cc == ')') // read "((u,v)"
  1556. {
  1557. p = ::boost::math::quaternion<T>(u,v);
  1558. is >> ch; // get the next lexeme
  1559. if (!is.good()) goto finish;
  1560. #ifdef BOOST_NO_STD_LOCALE
  1561. cc = ch;
  1562. #else
  1563. cc = ct.narrow(ch, char());
  1564. #endif /* BOOST_NO_STD_LOCALE */
  1565. if (cc == ')') // format: (((a),v)), (((a,b),v))
  1566. {
  1567. o = octonion<T>(p);
  1568. }
  1569. else if (cc == ',') // read "((u,v),"
  1570. {
  1571. is >> q; // read "(p,q"
  1572. if (!is.good()) goto finish;
  1573. is >> ch; // get the next lexeme
  1574. if (!is.good()) goto finish;
  1575. #ifdef BOOST_NO_STD_LOCALE
  1576. cc = ch;
  1577. #else
  1578. cc = ct.narrow(ch, char());
  1579. #endif /* BOOST_NO_STD_LOCALE */
  1580. if (cc == ')') // format: (((a),v),q), (((a,b),v),q)
  1581. {
  1582. o = octonion<T>(p,q);
  1583. }
  1584. else // error
  1585. {
  1586. is.setstate(::std::ios_base::failbit);
  1587. }
  1588. }
  1589. else // error
  1590. {
  1591. is.setstate(::std::ios_base::failbit);
  1592. }
  1593. }
  1594. else // error
  1595. {
  1596. is.setstate(::std::ios_base::failbit);
  1597. }
  1598. }
  1599. else // error
  1600. {
  1601. is.setstate(::std::ios_base::failbit);
  1602. }
  1603. }
  1604. else // read "((a"
  1605. {
  1606. is.putback(ch);
  1607. is >> a; // we extract the first component
  1608. if (!is.good()) goto finish;
  1609. is >> ch; // get the next lexeme
  1610. if (!is.good()) goto finish;
  1611. #ifdef BOOST_NO_STD_LOCALE
  1612. cc = ch;
  1613. #else
  1614. cc = ct.narrow(ch, char());
  1615. #endif /* BOOST_NO_STD_LOCALE */
  1616. if (cc == ')') // read "((a)"
  1617. {
  1618. is >> ch; // get the next lexeme
  1619. if (!is.good()) goto finish;
  1620. #ifdef BOOST_NO_STD_LOCALE
  1621. cc = ch;
  1622. #else
  1623. cc = ct.narrow(ch, char());
  1624. #endif /* BOOST_NO_STD_LOCALE */
  1625. if (cc == ')') // read "((a))"
  1626. {
  1627. o = octonion<T>(a);
  1628. }
  1629. else if (cc == ',') // read "((a),"
  1630. {
  1631. is >> ch; // get the next lexeme
  1632. if (!is.good()) goto finish;
  1633. #ifdef BOOST_NO_STD_LOCALE
  1634. cc = ch;
  1635. #else
  1636. cc = ct.narrow(ch, char());
  1637. #endif /* BOOST_NO_STD_LOCALE */
  1638. if (cc == '(') // read "((a),("
  1639. {
  1640. is >> ch; // get the next lexeme
  1641. if (!is.good()) goto finish;
  1642. #ifdef BOOST_NO_STD_LOCALE
  1643. cc = ch;
  1644. #else
  1645. cc = ct.narrow(ch, char());
  1646. #endif /* BOOST_NO_STD_LOCALE */
  1647. if (cc == '(') // read "((a),(("
  1648. {
  1649. is.putback(ch);
  1650. is.putback(ch); // we backtrack twice, with the same value!
  1651. is >> q; // read "((a),q"
  1652. if (!is.good()) goto finish;
  1653. is >> ch; // get the next lexeme
  1654. if (!is.good()) goto finish;
  1655. #ifdef BOOST_NO_STD_LOCALE
  1656. cc = ch;
  1657. #else
  1658. cc = ct.narrow(ch, char());
  1659. #endif /* BOOST_NO_STD_LOCALE */
  1660. if (cc == ')') // read "((a),q)"
  1661. {
  1662. p = ::boost::math::quaternion<T>(a);
  1663. o = octonion<T>(p,q);
  1664. }
  1665. else // error
  1666. {
  1667. is.setstate(::std::ios_base::failbit);
  1668. }
  1669. }
  1670. else // read "((a),(c" or "((a),(e"
  1671. {
  1672. is.putback(ch);
  1673. is >> c;
  1674. if (!is.good()) goto finish;
  1675. is >> ch; // get the next lexeme
  1676. if (!is.good()) goto finish;
  1677. #ifdef BOOST_NO_STD_LOCALE
  1678. cc = ch;
  1679. #else
  1680. cc = ct.narrow(ch, char());
  1681. #endif /* BOOST_NO_STD_LOCALE */
  1682. if (cc == ')') // read "((a),(c)" (ambiguity resolution)
  1683. {
  1684. is >> ch; // get the next lexeme
  1685. if (!is.good()) goto finish;
  1686. #ifdef BOOST_NO_STD_LOCALE
  1687. cc = ch;
  1688. #else
  1689. cc = ct.narrow(ch, char());
  1690. #endif /* BOOST_NO_STD_LOCALE */
  1691. if (cc == ')') // read "((a),(c))"
  1692. {
  1693. o = octonion<T>(a,b,c);
  1694. }
  1695. else if (cc == ',') // read "((a),(c),"
  1696. {
  1697. u = ::std::complex<T>(a);
  1698. v = ::std::complex<T>(c);
  1699. is >> x; // read "((a),(c),x"
  1700. if (!is.good()) goto finish;
  1701. is >> ch; // get the next lexeme
  1702. if (!is.good()) goto finish;
  1703. #ifdef BOOST_NO_STD_LOCALE
  1704. cc = ch;
  1705. #else
  1706. cc = ct.narrow(ch, char());
  1707. #endif /* BOOST_NO_STD_LOCALE */
  1708. if (cc == ')') // read "((a),(c),x)"
  1709. {
  1710. o = octonion<T>(u,v,x);
  1711. }
  1712. else if (cc == ',') // read "((a),(c),x,"
  1713. {
  1714. is >> y; // read "((a),(c),x,y"
  1715. if (!is.good()) goto finish;
  1716. is >> ch; // get the next lexeme
  1717. if (!is.good()) goto finish;
  1718. #ifdef BOOST_NO_STD_LOCALE
  1719. cc = ch;
  1720. #else
  1721. cc = ct.narrow(ch, char());
  1722. #endif /* BOOST_NO_STD_LOCALE */
  1723. if (cc == ')') // read "((a),(c),x,y)"
  1724. {
  1725. o = octonion<T>(u,v,x,y);
  1726. }
  1727. else // error
  1728. {
  1729. is.setstate(::std::ios_base::failbit);
  1730. }
  1731. }
  1732. else // error
  1733. {
  1734. is.setstate(::std::ios_base::failbit);
  1735. }
  1736. }
  1737. else // error
  1738. {
  1739. is.setstate(::std::ios_base::failbit);
  1740. }
  1741. }
  1742. else if (cc == ',') // read "((a),(c," or "((a),(e,"
  1743. {
  1744. is >> ch; // get the next lexeme
  1745. if (!is.good()) goto finish;
  1746. #ifdef BOOST_NO_STD_LOCALE
  1747. cc = ch;
  1748. #else
  1749. cc = ct.narrow(ch, char());
  1750. #endif /* BOOST_NO_STD_LOCALE */
  1751. if (cc == '(') // read "((a),(e,(" (ambiguity resolution)
  1752. {
  1753. p = ::boost::math::quaternion<T>(a);
  1754. x = ::std::complex<T>(c); // "c" was actually "e"
  1755. is.putback(ch); // we can only backtrace once
  1756. is >> y; // read "((a),(e,y"
  1757. if (!is.good()) goto finish;
  1758. is >> ch; // get the next lexeme
  1759. #ifdef BOOST_NO_STD_LOCALE
  1760. cc = ch;
  1761. #else
  1762. cc = ct.narrow(ch, char());
  1763. #endif /* BOOST_NO_STD_LOCALE */
  1764. if (cc == ')') // read "((a),(e,y)"
  1765. {
  1766. q = ::boost::math::quaternion<T>(x,y);
  1767. is >> ch; // get the next lexeme
  1768. #ifdef BOOST_NO_STD_LOCALE
  1769. cc = ch;
  1770. #else
  1771. cc = ct.narrow(ch, char());
  1772. #endif /* BOOST_NO_STD_LOCALE */
  1773. if (cc == ')') // read "((a),(e,y))"
  1774. {
  1775. o = octonion<T>(p,q);
  1776. }
  1777. else // error
  1778. {
  1779. is.setstate(::std::ios_base::failbit);
  1780. }
  1781. }
  1782. else // error
  1783. {
  1784. is.setstate(::std::ios_base::failbit);
  1785. }
  1786. }
  1787. else // read "((a),(c,d" or "((a),(e,f"
  1788. {
  1789. is.putback(ch);
  1790. is >> d;
  1791. if (!is.good()) goto finish;
  1792. is >> ch; // get the next lexeme
  1793. if (!is.good()) goto finish;
  1794. #ifdef BOOST_NO_STD_LOCALE
  1795. cc = ch;
  1796. #else
  1797. cc = ct.narrow(ch, char());
  1798. #endif /* BOOST_NO_STD_LOCALE */
  1799. if (cc == ')') // read "((a),(c,d)" (ambiguity resolution)
  1800. {
  1801. is >> ch; // get the next lexeme
  1802. if (!is.good()) goto finish;
  1803. #ifdef BOOST_NO_STD_LOCALE
  1804. cc = ch;
  1805. #else
  1806. cc = ct.narrow(ch, char());
  1807. #endif /* BOOST_NO_STD_LOCALE */
  1808. if (cc == ')') // read "((a),(c,d))"
  1809. {
  1810. o = octonion<T>(a,b,c,d);
  1811. }
  1812. else if (cc == ',') // read "((a),(c,d),"
  1813. {
  1814. u = ::std::complex<T>(a);
  1815. v = ::std::complex<T>(c,d);
  1816. is >> x; // read "((a),(c,d),x"
  1817. if (!is.good()) goto finish;
  1818. is >> ch; // get the next lexeme
  1819. if (!is.good()) goto finish;
  1820. #ifdef BOOST_NO_STD_LOCALE
  1821. cc = ch;
  1822. #else
  1823. cc = ct.narrow(ch, char());
  1824. #endif /* BOOST_NO_STD_LOCALE */
  1825. if (cc == ')') // read "((a),(c,d),x)"
  1826. {
  1827. o = octonion<T>(u,v,x);
  1828. }
  1829. else if (cc == ',') // read "((a),(c,d),x,"
  1830. {
  1831. is >> y; // read "((a),(c,d),x,y"
  1832. if (!is.good()) goto finish;
  1833. is >> ch; // get the next lexeme
  1834. if (!is.good()) goto finish;
  1835. #ifdef BOOST_NO_STD_LOCALE
  1836. cc = ch;
  1837. #else
  1838. cc = ct.narrow(ch, char());
  1839. #endif /* BOOST_NO_STD_LOCALE */
  1840. if (cc == ')') // read "((a),(c,d),x,y)"
  1841. {
  1842. o = octonion<T>(u,v,x,y);
  1843. }
  1844. else // error
  1845. {
  1846. is.setstate(::std::ios_base::failbit);
  1847. }
  1848. }
  1849. else // error
  1850. {
  1851. is.setstate(::std::ios_base::failbit);
  1852. }
  1853. }
  1854. else // error
  1855. {
  1856. is.setstate(::std::ios_base::failbit);
  1857. }
  1858. }
  1859. else if (cc == ',') // read "((a),(e,f," (ambiguity resolution)
  1860. {
  1861. p = ::boost::math::quaternion<T>(a);
  1862. is >> g; // read "((a),(e,f,g" (too late to backtrack)
  1863. if (!is.good()) goto finish;
  1864. is >> ch; // get the next lexeme
  1865. if (!is.good()) goto finish;
  1866. #ifdef BOOST_NO_STD_LOCALE
  1867. cc = ch;
  1868. #else
  1869. cc = ct.narrow(ch, char());
  1870. #endif /* BOOST_NO_STD_LOCALE */
  1871. if (cc == ')') // read "((a),(e,f,g)"
  1872. {
  1873. q = ::boost::math::quaternion<T>(c,d,g); // "c" was actually "e", and "d" was actually "f"
  1874. is >> ch; // get the next lexeme
  1875. if (!is.good()) goto finish;
  1876. #ifdef BOOST_NO_STD_LOCALE
  1877. cc = ch;
  1878. #else
  1879. cc = ct.narrow(ch, char());
  1880. #endif /* BOOST_NO_STD_LOCALE */
  1881. if (cc == ')') // read "((a),(e,f,g))"
  1882. {
  1883. o = octonion<T>(p,q);
  1884. }
  1885. else // error
  1886. {
  1887. is.setstate(::std::ios_base::failbit);
  1888. }
  1889. }
  1890. else if (cc == ',') // read "((a),(e,f,g,"
  1891. {
  1892. is >> h; // read "((a),(e,f,g,h"
  1893. if (!is.good()) goto finish;
  1894. is >> ch; // get the next lexeme
  1895. if (!is.good()) goto finish;
  1896. #ifdef BOOST_NO_STD_LOCALE
  1897. cc = ch;
  1898. #else
  1899. cc = ct.narrow(ch, char());
  1900. #endif /* BOOST_NO_STD_LOCALE */
  1901. if (cc == ')') // read "((a),(e,f,g,h)"
  1902. {
  1903. q = ::boost::math::quaternion<T>(c,d,g,h); // "c" was actually "e", and "d" was actually "f"
  1904. is >> ch; // get the next lexeme
  1905. if (!is.good()) goto finish;
  1906. #ifdef BOOST_NO_STD_LOCALE
  1907. cc = ch;
  1908. #else
  1909. cc = ct.narrow(ch, char());
  1910. #endif /* BOOST_NO_STD_LOCALE */
  1911. if (cc == ')') // read "((a),(e,f,g,h))"
  1912. {
  1913. o = octonion<T>(p,q);
  1914. }
  1915. else // error
  1916. {
  1917. is.setstate(::std::ios_base::failbit);
  1918. }
  1919. }
  1920. else // error
  1921. {
  1922. is.setstate(::std::ios_base::failbit);
  1923. }
  1924. }
  1925. else // error
  1926. {
  1927. is.setstate(::std::ios_base::failbit);
  1928. }
  1929. }
  1930. else // error
  1931. {
  1932. is.setstate(::std::ios_base::failbit);
  1933. }
  1934. }
  1935. }
  1936. else // error
  1937. {
  1938. is.setstate(::std::ios_base::failbit);
  1939. }
  1940. }
  1941. }
  1942. else // read "((a),c" (ambiguity resolution)
  1943. {
  1944. is.putback(ch);
  1945. is >> c; // we extract the third component
  1946. if (!is.good()) goto finish;
  1947. is >> ch; // get the next lexeme
  1948. if (!is.good()) goto finish;
  1949. #ifdef BOOST_NO_STD_LOCALE
  1950. cc = ch;
  1951. #else
  1952. cc = ct.narrow(ch, char());
  1953. #endif /* BOOST_NO_STD_LOCALE */
  1954. if (cc == ')') // read "((a),c)"
  1955. {
  1956. o = octonion<T>(a,b,c);
  1957. }
  1958. else if (cc == ',') // read "((a),c,"
  1959. {
  1960. is >> x; // read "((a),c,x"
  1961. if (!is.good()) goto finish;
  1962. is >> ch; // get the next lexeme
  1963. if (!is.good()) goto finish;
  1964. #ifdef BOOST_NO_STD_LOCALE
  1965. cc = ch;
  1966. #else
  1967. cc = ct.narrow(ch, char());
  1968. #endif /* BOOST_NO_STD_LOCALE */
  1969. if (cc == ')') // read "((a),c,x)"
  1970. {
  1971. o = octonion<T>(a,b,c,d,x.real(),x.imag());
  1972. }
  1973. else if (cc == ',') // read "((a),c,x,"
  1974. {
  1975. is >> y;if (!is.good()) goto finish; // read "((a),c,x,y"
  1976. is >> ch; // get the next lexeme
  1977. if (!is.good()) goto finish;
  1978. #ifdef BOOST_NO_STD_LOCALE
  1979. cc = ch;
  1980. #else
  1981. cc = ct.narrow(ch, char());
  1982. #endif /* BOOST_NO_STD_LOCALE */
  1983. if (cc == ')') // read "((a),c,x,y)"
  1984. {
  1985. o = octonion<T>(a,b,c,d,x.real(),x.imag(),y.real(),y.imag());
  1986. }
  1987. else // error
  1988. {
  1989. is.setstate(::std::ios_base::failbit);
  1990. }
  1991. }
  1992. else // error
  1993. {
  1994. is.setstate(::std::ios_base::failbit);
  1995. }
  1996. }
  1997. else // error
  1998. {
  1999. is.setstate(::std::ios_base::failbit);
  2000. }
  2001. }
  2002. }
  2003. else // error
  2004. {
  2005. is.setstate(::std::ios_base::failbit);
  2006. }
  2007. }
  2008. else if (cc ==',') // read "((a,"
  2009. {
  2010. is >> ch; // get the next lexeme
  2011. if (!is.good()) goto finish;
  2012. #ifdef BOOST_NO_STD_LOCALE
  2013. cc = ch;
  2014. #else
  2015. cc = ct.narrow(ch, char());
  2016. #endif /* BOOST_NO_STD_LOCALE */
  2017. if (cc == '(') // read "((a,("
  2018. {
  2019. u = ::std::complex<T>(a);
  2020. is.putback(ch); // can only backtrack so much
  2021. is >> v; // read "((a,v"
  2022. if (!is.good()) goto finish;
  2023. is >> ch; // get the next lexeme
  2024. if (!is.good()) goto finish;
  2025. #ifdef BOOST_NO_STD_LOCALE
  2026. cc = ch;
  2027. #else
  2028. cc = ct.narrow(ch, char());
  2029. #endif /* BOOST_NO_STD_LOCALE */
  2030. if (cc == ')') // read "((a,v)"
  2031. {
  2032. is >> ch; // get the next lexeme
  2033. if (!is.good()) goto finish;
  2034. #ifdef BOOST_NO_STD_LOCALE
  2035. cc = ch;
  2036. #else
  2037. cc = ct.narrow(ch, char());
  2038. #endif /* BOOST_NO_STD_LOCALE */
  2039. if (cc == ')') // read "((a,v))"
  2040. {
  2041. o = octonion<T>(u,v);
  2042. }
  2043. else if (cc == ',') // read "((a,v),"
  2044. {
  2045. p = ::boost::math::quaternion<T>(u,v);
  2046. is >> q; // read "((a,v),q"
  2047. if (!is.good()) goto finish;
  2048. is >> ch; // get the next lexeme
  2049. if (!is.good()) goto finish;
  2050. #ifdef BOOST_NO_STD_LOCALE
  2051. cc = ch;
  2052. #else
  2053. cc = ct.narrow(ch, char());
  2054. #endif /* BOOST_NO_STD_LOCALE */
  2055. if (cc == ')') // read "((a,v),q)"
  2056. {
  2057. o = octonion<T>(p,q);
  2058. }
  2059. else // error
  2060. {
  2061. is.setstate(::std::ios_base::failbit);
  2062. }
  2063. }
  2064. else // error
  2065. {
  2066. is.setstate(::std::ios_base::failbit);
  2067. }
  2068. }
  2069. else // error
  2070. {
  2071. is.setstate(::std::ios_base::failbit);
  2072. }
  2073. }
  2074. else
  2075. {
  2076. is.putback(ch);
  2077. is >> b; // read "((a,b"
  2078. if (!is.good()) goto finish;
  2079. is >> ch; // get the next lexeme
  2080. if (!is.good()) goto finish;
  2081. #ifdef BOOST_NO_STD_LOCALE
  2082. cc = ch;
  2083. #else
  2084. cc = ct.narrow(ch, char());
  2085. #endif /* BOOST_NO_STD_LOCALE */
  2086. if (cc == ')') // read "((a,b)"
  2087. {
  2088. is >> ch; // get the next lexeme
  2089. if (!is.good()) goto finish;
  2090. #ifdef BOOST_NO_STD_LOCALE
  2091. cc = ch;
  2092. #else
  2093. cc = ct.narrow(ch, char());
  2094. #endif /* BOOST_NO_STD_LOCALE */
  2095. if (cc == ')') // read "((a,b))"
  2096. {
  2097. o = octonion<T>(a,b);
  2098. }
  2099. else if (cc == ',') // read "((a,b),"
  2100. {
  2101. is >> ch; // get the next lexeme
  2102. if (!is.good()) goto finish;
  2103. #ifdef BOOST_NO_STD_LOCALE
  2104. cc = ch;
  2105. #else
  2106. cc = ct.narrow(ch, char());
  2107. #endif /* BOOST_NO_STD_LOCALE */
  2108. if (cc == '(') // read "((a,b),("
  2109. {
  2110. is >> ch; // get the next lexeme
  2111. if (!is.good()) goto finish;
  2112. #ifdef BOOST_NO_STD_LOCALE
  2113. cc = ch;
  2114. #else
  2115. cc = ct.narrow(ch, char());
  2116. #endif /* BOOST_NO_STD_LOCALE */
  2117. if (cc == '(') // read "((a,b),(("
  2118. {
  2119. p = ::boost::math::quaternion<T>(a,b);
  2120. is.putback(ch);
  2121. is.putback(ch); // we backtrack twice, with the same value
  2122. is >> q; // read "((a,b),q"
  2123. if (!is.good()) goto finish;
  2124. is >> ch; // get the next lexeme
  2125. if (!is.good()) goto finish;
  2126. #ifdef BOOST_NO_STD_LOCALE
  2127. cc = ch;
  2128. #else
  2129. cc = ct.narrow(ch, char());
  2130. #endif /* BOOST_NO_STD_LOCALE */
  2131. if (cc == ')') // read "((a,b),q)"
  2132. {
  2133. o = octonion<T>(p,q);
  2134. }
  2135. else // error
  2136. {
  2137. is.setstate(::std::ios_base::failbit);
  2138. }
  2139. }
  2140. else // read "((a,b),(c" or "((a,b),(e"
  2141. {
  2142. is.putback(ch);
  2143. is >> c;
  2144. if (!is.good()) goto finish;
  2145. is >> ch; // get the next lexeme
  2146. if (!is.good()) goto finish;
  2147. #ifdef BOOST_NO_STD_LOCALE
  2148. cc = ch;
  2149. #else
  2150. cc = ct.narrow(ch, char());
  2151. #endif /* BOOST_NO_STD_LOCALE */
  2152. if (cc == ')') // read "((a,b),(c)" (ambiguity resolution)
  2153. {
  2154. is >> ch; // get the next lexeme
  2155. if (!is.good()) goto finish;
  2156. #ifdef BOOST_NO_STD_LOCALE
  2157. cc = ch;
  2158. #else
  2159. cc = ct.narrow(ch, char());
  2160. #endif /* BOOST_NO_STD_LOCALE */
  2161. if (cc == ')') // read "((a,b),(c))"
  2162. {
  2163. o = octonion<T>(a,b,c);
  2164. }
  2165. else if (cc == ',') // read "((a,b),(c),"
  2166. {
  2167. u = ::std::complex<T>(a,b);
  2168. v = ::std::complex<T>(c);
  2169. is >> x; // read "((a,b),(c),x"
  2170. if (!is.good()) goto finish;
  2171. is >> ch; // get the next lexeme
  2172. if (!is.good()) goto finish;
  2173. #ifdef BOOST_NO_STD_LOCALE
  2174. cc = ch;
  2175. #else
  2176. cc = ct.narrow(ch, char());
  2177. #endif /* BOOST_NO_STD_LOCALE */
  2178. if (cc == ')') // read "((a,b),(c),x)"
  2179. {
  2180. o = octonion<T>(u,v,x);
  2181. }
  2182. else if (cc == ',') // read "((a,b),(c),x,"
  2183. {
  2184. is >> y; // read "((a,b),(c),x,y"
  2185. if (!is.good()) goto finish;
  2186. is >> ch; // get the next lexeme
  2187. if (!is.good()) goto finish;
  2188. #ifdef BOOST_NO_STD_LOCALE
  2189. cc = ch;
  2190. #else
  2191. cc = ct.narrow(ch, char());
  2192. #endif /* BOOST_NO_STD_LOCALE */
  2193. if (cc == ')') // read "((a,b),(c),x,y)"
  2194. {
  2195. o = octonion<T>(u,v,x,y);
  2196. }
  2197. else // error
  2198. {
  2199. is.setstate(::std::ios_base::failbit);
  2200. }
  2201. }
  2202. else // error
  2203. {
  2204. is.setstate(::std::ios_base::failbit);
  2205. }
  2206. }
  2207. else // error
  2208. {
  2209. is.setstate(::std::ios_base::failbit);
  2210. }
  2211. }
  2212. else if (cc == ',') // read "((a,b),(c," or "((a,b),(e,"
  2213. {
  2214. is >> ch; // get the next lexeme
  2215. if (!is.good()) goto finish;
  2216. #ifdef BOOST_NO_STD_LOCALE
  2217. cc = ch;
  2218. #else
  2219. cc = ct.narrow(ch, char());
  2220. #endif /* BOOST_NO_STD_LOCALE */
  2221. if (cc == '(') // read "((a,b),(e,(" (ambiguity resolution)
  2222. {
  2223. u = ::std::complex<T>(a,b);
  2224. x = ::std::complex<T>(c); // "c" is actually "e"
  2225. is.putback(ch);
  2226. is >> y; // read "((a,b),(e,y"
  2227. if (!is.good()) goto finish;
  2228. is >> ch; // get the next lexeme
  2229. if (!is.good()) goto finish;
  2230. #ifdef BOOST_NO_STD_LOCALE
  2231. cc = ch;
  2232. #else
  2233. cc = ct.narrow(ch, char());
  2234. #endif /* BOOST_NO_STD_LOCALE */
  2235. if (cc == ')') // read "((a,b),(e,y)"
  2236. {
  2237. is >> ch; // get the next lexeme
  2238. if (!is.good()) goto finish;
  2239. #ifdef BOOST_NO_STD_LOCALE
  2240. cc = ch;
  2241. #else
  2242. cc = ct.narrow(ch, char());
  2243. #endif /* BOOST_NO_STD_LOCALE */
  2244. if (cc == ')') // read "((a,b),(e,y))"
  2245. {
  2246. o = octonion<T>(u,v,x,y);
  2247. }
  2248. else // error
  2249. {
  2250. is.setstate(::std::ios_base::failbit);
  2251. }
  2252. }
  2253. else // error
  2254. {
  2255. is.setstate(::std::ios_base::failbit);
  2256. }
  2257. }
  2258. else // read "((a,b),(c,d" or "((a,b),(e,f"
  2259. {
  2260. is.putback(ch);
  2261. is >> d;
  2262. if (!is.good()) goto finish;
  2263. is >> ch; // get the next lexeme
  2264. if (!is.good()) goto finish;
  2265. #ifdef BOOST_NO_STD_LOCALE
  2266. cc = ch;
  2267. #else
  2268. cc = ct.narrow(ch, char());
  2269. #endif /* BOOST_NO_STD_LOCALE */
  2270. if (cc == ')') // read "((a,b),(c,d)" (ambiguity resolution)
  2271. {
  2272. u = ::std::complex<T>(a,b);
  2273. v = ::std::complex<T>(c,d);
  2274. is >> ch; // get the next lexeme
  2275. if (!is.good()) goto finish;
  2276. #ifdef BOOST_NO_STD_LOCALE
  2277. cc = ch;
  2278. #else
  2279. cc = ct.narrow(ch, char());
  2280. #endif /* BOOST_NO_STD_LOCALE */
  2281. if (cc == ')') // read "((a,b),(c,d))"
  2282. {
  2283. o = octonion<T>(u,v);
  2284. }
  2285. else if (cc == ',') // read "((a,b),(c,d),"
  2286. {
  2287. is >> x; // read "((a,b),(c,d),x
  2288. if (!is.good()) goto finish;
  2289. is >> ch; // get the next lexeme
  2290. if (!is.good()) goto finish;
  2291. #ifdef BOOST_NO_STD_LOCALE
  2292. cc = ch;
  2293. #else
  2294. cc = ct.narrow(ch, char());
  2295. #endif /* BOOST_NO_STD_LOCALE */
  2296. if (cc == ')') // read "((a,b),(c,d),x)"
  2297. {
  2298. o = octonion<T>(u,v,x);
  2299. }
  2300. else if (cc == ',') // read "((a,b),(c,d),x,"
  2301. {
  2302. is >> y; // read "((a,b),(c,d),x,y"
  2303. if (!is.good()) goto finish;
  2304. is >> ch; // get the next lexeme
  2305. if (!is.good()) goto finish;
  2306. #ifdef BOOST_NO_STD_LOCALE
  2307. cc = ch;
  2308. #else
  2309. cc = ct.narrow(ch, char());
  2310. #endif /* BOOST_NO_STD_LOCALE */
  2311. if (cc == ')') // read "((a,b),(c,d),x,y)"
  2312. {
  2313. o = octonion<T>(u,v,x,y);
  2314. }
  2315. else // error
  2316. {
  2317. is.setstate(::std::ios_base::failbit);
  2318. }
  2319. }
  2320. else // error
  2321. {
  2322. is.setstate(::std::ios_base::failbit);
  2323. }
  2324. }
  2325. else // error
  2326. {
  2327. is.setstate(::std::ios_base::failbit);
  2328. }
  2329. }
  2330. else if (cc == ',') // read "((a,b),(e,f," (ambiguity resolution)
  2331. {
  2332. p = ::boost::math::quaternion<T>(a,b); // too late to backtrack
  2333. is >> g; // read "((a,b),(e,f,g"
  2334. if (!is.good()) goto finish;
  2335. is >> ch; // get the next lexeme
  2336. if (!is.good()) goto finish;
  2337. #ifdef BOOST_NO_STD_LOCALE
  2338. cc = ch;
  2339. #else
  2340. cc = ct.narrow(ch, char());
  2341. #endif /* BOOST_NO_STD_LOCALE */
  2342. if (cc == ')') // read "((a,b),(e,f,g)"
  2343. {
  2344. is >> ch; // get the next lexeme
  2345. if (!is.good()) goto finish;
  2346. #ifdef BOOST_NO_STD_LOCALE
  2347. cc = ch;
  2348. #else
  2349. cc = ct.narrow(ch, char());
  2350. #endif /* BOOST_NO_STD_LOCALE */
  2351. if (cc == ')') // read "((a,b),(e,f,g))"
  2352. {
  2353. q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f"
  2354. o = octonion<T>(p,q);
  2355. }
  2356. else // error
  2357. {
  2358. is.setstate(::std::ios_base::failbit);
  2359. }
  2360. }
  2361. else if (cc == ',') // read "((a,b),(e,f,g,"
  2362. {
  2363. is >> h; // read "((a,b),(e,f,g,h"
  2364. if (!is.good()) goto finish;
  2365. is >> ch; // get the next lexeme
  2366. if (!is.good()) goto finish;
  2367. #ifdef BOOST_NO_STD_LOCALE
  2368. cc = ch;
  2369. #else
  2370. cc = ct.narrow(ch, char());
  2371. #endif /* BOOST_NO_STD_LOCALE */
  2372. if (cc == ')') // read "((a,b),(e,f,g,h)"
  2373. {
  2374. is >> ch; // get the next lexeme
  2375. if (!is.good()) goto finish;
  2376. #ifdef BOOST_NO_STD_LOCALE
  2377. cc = ch;
  2378. #else
  2379. cc = ct.narrow(ch, char());
  2380. #endif /* BOOST_NO_STD_LOCALE */
  2381. if (cc == ')') // read ((a,b),(e,f,g,h))"
  2382. {
  2383. q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f"
  2384. o = octonion<T>(p,q);
  2385. }
  2386. else // error
  2387. {
  2388. is.setstate(::std::ios_base::failbit);
  2389. }
  2390. }
  2391. else // error
  2392. {
  2393. is.setstate(::std::ios_base::failbit);
  2394. }
  2395. }
  2396. else // error
  2397. {
  2398. is.setstate(::std::ios_base::failbit);
  2399. }
  2400. }
  2401. else // error
  2402. {
  2403. is.setstate(::std::ios_base::failbit);
  2404. }
  2405. }
  2406. }
  2407. else // error
  2408. {
  2409. is.setstate(::std::ios_base::failbit);
  2410. }
  2411. }
  2412. }
  2413. else // error
  2414. {
  2415. is.setstate(::std::ios_base::failbit);
  2416. }
  2417. }
  2418. else // error
  2419. {
  2420. is.setstate(::std::ios_base::failbit);
  2421. }
  2422. }
  2423. else if (cc == ',') // read "((a,b,"
  2424. {
  2425. is >> c; // read "((a,b,c"
  2426. if (!is.good()) goto finish;
  2427. is >> ch; // get the next lexeme
  2428. if (!is.good()) goto finish;
  2429. #ifdef BOOST_NO_STD_LOCALE
  2430. cc = ch;
  2431. #else
  2432. cc = ct.narrow(ch, char());
  2433. #endif /* BOOST_NO_STD_LOCALE */
  2434. if (cc == ')') // read "((a,b,c)"
  2435. {
  2436. is >> ch; // get the next lexeme
  2437. if (!is.good()) goto finish;
  2438. #ifdef BOOST_NO_STD_LOCALE
  2439. cc = ch;
  2440. #else
  2441. cc = ct.narrow(ch, char());
  2442. #endif /* BOOST_NO_STD_LOCALE */
  2443. if (cc == ')') // read "((a,b,c))"
  2444. {
  2445. o = octonion<T>(a,b,c);
  2446. }
  2447. else if (cc == ',') // read "((a,b,c),"
  2448. {
  2449. p = ::boost::math::quaternion<T>(a,b,c);
  2450. is >> q; // read "((a,b,c),q"
  2451. if (!is.good()) goto finish;
  2452. is >> ch; // get the next lexeme
  2453. if (!is.good()) goto finish;
  2454. #ifdef BOOST_NO_STD_LOCALE
  2455. cc = ch;
  2456. #else
  2457. cc = ct.narrow(ch, char());
  2458. #endif /* BOOST_NO_STD_LOCALE */
  2459. if (cc == ')') // read "((a,b,c),q)"
  2460. {
  2461. o = octonion<T>(p,q);
  2462. }
  2463. else // error
  2464. {
  2465. is.setstate(::std::ios_base::failbit);
  2466. }
  2467. }
  2468. else // error
  2469. {
  2470. is.setstate(::std::ios_base::failbit);
  2471. }
  2472. }
  2473. else if (cc == ',') // read "((a,b,c,"
  2474. {
  2475. is >> d; // read "((a,b,c,d"
  2476. if (!is.good()) goto finish;
  2477. is >> ch; // get the next lexeme
  2478. if (!is.good()) goto finish;
  2479. #ifdef BOOST_NO_STD_LOCALE
  2480. cc = ch;
  2481. #else
  2482. cc = ct.narrow(ch, char());
  2483. #endif /* BOOST_NO_STD_LOCALE */
  2484. if (cc == ')') // read "((a,b,c,d)"
  2485. {
  2486. is >> ch; // get the next lexeme
  2487. if (!is.good()) goto finish;
  2488. #ifdef BOOST_NO_STD_LOCALE
  2489. cc = ch;
  2490. #else
  2491. cc = ct.narrow(ch, char());
  2492. #endif /* BOOST_NO_STD_LOCALE */
  2493. if (cc == ')') // read "((a,b,c,d))"
  2494. {
  2495. o = octonion<T>(a,b,c,d);
  2496. }
  2497. else if (cc == ',') // read "((a,b,c,d),"
  2498. {
  2499. p = ::boost::math::quaternion<T>(a,b,c,d);
  2500. is >> q; // read "((a,b,c,d),q"
  2501. if (!is.good()) goto finish;
  2502. is >> ch; // get the next lexeme
  2503. if (!is.good()) goto finish;
  2504. #ifdef BOOST_NO_STD_LOCALE
  2505. cc = ch;
  2506. #else
  2507. cc = ct.narrow(ch, char());
  2508. #endif /* BOOST_NO_STD_LOCALE */
  2509. if (cc == ')') // read "((a,b,c,d),q)"
  2510. {
  2511. o = octonion<T>(p,q);
  2512. }
  2513. else // error
  2514. {
  2515. is.setstate(::std::ios_base::failbit);
  2516. }
  2517. }
  2518. else // error
  2519. {
  2520. is.setstate(::std::ios_base::failbit);
  2521. }
  2522. }
  2523. else // error
  2524. {
  2525. is.setstate(::std::ios_base::failbit);
  2526. }
  2527. }
  2528. else // error
  2529. {
  2530. is.setstate(::std::ios_base::failbit);
  2531. }
  2532. }
  2533. else // error
  2534. {
  2535. is.setstate(::std::ios_base::failbit);
  2536. }
  2537. }
  2538. }
  2539. else // error
  2540. {
  2541. is.setstate(::std::ios_base::failbit);
  2542. }
  2543. }
  2544. }
  2545. else // read "(a"
  2546. {
  2547. is.putback(ch);
  2548. is >> a; // we extract the first component
  2549. if (!is.good()) goto finish;
  2550. is >> ch; // get the next lexeme
  2551. if (!is.good()) goto finish;
  2552. #ifdef BOOST_NO_STD_LOCALE
  2553. cc = ch;
  2554. #else
  2555. cc = ct.narrow(ch, char());
  2556. #endif /* BOOST_NO_STD_LOCALE */
  2557. if (cc == ')') // read "(a)"
  2558. {
  2559. o = octonion<T>(a);
  2560. }
  2561. else if (cc == ',') // read "(a,"
  2562. {
  2563. is >> ch; // get the next lexeme
  2564. if (!is.good()) goto finish;
  2565. #ifdef BOOST_NO_STD_LOCALE
  2566. cc = ch;
  2567. #else
  2568. cc = ct.narrow(ch, char());
  2569. #endif /* BOOST_NO_STD_LOCALE */
  2570. if (cc == '(') // read "(a,("
  2571. {
  2572. is >> ch; // get the next lexeme
  2573. if (!is.good()) goto finish;
  2574. #ifdef BOOST_NO_STD_LOCALE
  2575. cc = ch;
  2576. #else
  2577. cc = ct.narrow(ch, char());
  2578. #endif /* BOOST_NO_STD_LOCALE */
  2579. if (cc == '(') // read "(a,(("
  2580. {
  2581. p = ::boost::math::quaternion<T>(a);
  2582. is.putback(ch);
  2583. is.putback(ch); // we backtrack twice, with the same value
  2584. is >> q; // read "(a,q"
  2585. if (!is.good()) goto finish;
  2586. is >> ch; // get the next lexeme
  2587. if (!is.good()) goto finish;
  2588. #ifdef BOOST_NO_STD_LOCALE
  2589. cc = ch;
  2590. #else
  2591. cc = ct.narrow(ch, char());
  2592. #endif /* BOOST_NO_STD_LOCALE */
  2593. if (cc == ')') // read "(a,q)"
  2594. {
  2595. o = octonion<T>(p,q);
  2596. }
  2597. else // error
  2598. {
  2599. is.setstate(::std::ios_base::failbit);
  2600. }
  2601. }
  2602. else // read "(a,(c" or "(a,(e"
  2603. {
  2604. is.putback(ch);
  2605. is >> c;
  2606. if (!is.good()) goto finish;
  2607. is >> ch; // get the next lexeme
  2608. if (!is.good()) goto finish;
  2609. #ifdef BOOST_NO_STD_LOCALE
  2610. cc = ch;
  2611. #else
  2612. cc = ct.narrow(ch, char());
  2613. #endif /* BOOST_NO_STD_LOCALE */
  2614. if (cc == ')') // read "(a,(c)" (ambiguity resolution)
  2615. {
  2616. is >> ch; // get the next lexeme
  2617. if (!is.good()) goto finish;
  2618. #ifdef BOOST_NO_STD_LOCALE
  2619. cc = ch;
  2620. #else
  2621. cc = ct.narrow(ch, char());
  2622. #endif /* BOOST_NO_STD_LOCALE */
  2623. if (cc == ')') // read "(a,(c))"
  2624. {
  2625. o = octonion<T>(a,b,c);
  2626. }
  2627. else if (cc == ',') // read "(a,(c),"
  2628. {
  2629. u = ::std::complex<T>(a);
  2630. v = ::std::complex<T>(c);
  2631. is >> x; // read "(a,(c),x"
  2632. if (!is.good()) goto finish;
  2633. is >> ch; // get the next lexeme
  2634. if (!is.good()) goto finish;
  2635. #ifdef BOOST_NO_STD_LOCALE
  2636. cc = ch;
  2637. #else
  2638. cc = ct.narrow(ch, char());
  2639. #endif /* BOOST_NO_STD_LOCALE */
  2640. if (cc == ')') // read "(a,(c),x)"
  2641. {
  2642. o = octonion<T>(u,v,x);
  2643. }
  2644. else if (cc == ',') // read "(a,(c),x,"
  2645. {
  2646. is >> y; // read "(a,(c),x,y"
  2647. if (!is.good()) goto finish;
  2648. is >> ch; // get the next lexeme
  2649. if (!is.good()) goto finish;
  2650. #ifdef BOOST_NO_STD_LOCALE
  2651. cc = ch;
  2652. #else
  2653. cc = ct.narrow(ch, char());
  2654. #endif /* BOOST_NO_STD_LOCALE */
  2655. if (cc == ')') // read "(a,(c),x,y)"
  2656. {
  2657. o = octonion<T>(u,v,x,y);
  2658. }
  2659. else // error
  2660. {
  2661. is.setstate(::std::ios_base::failbit);
  2662. }
  2663. }
  2664. else // error
  2665. {
  2666. is.setstate(::std::ios_base::failbit);
  2667. }
  2668. }
  2669. else // error
  2670. {
  2671. is.setstate(::std::ios_base::failbit);
  2672. }
  2673. }
  2674. else if (cc == ',') // read "(a,(c," or "(a,(e,"
  2675. {
  2676. is >> ch; // get the next lexeme
  2677. if (!is.good()) goto finish;
  2678. #ifdef BOOST_NO_STD_LOCALE
  2679. cc = ch;
  2680. #else
  2681. cc = ct.narrow(ch, char());
  2682. #endif /* BOOST_NO_STD_LOCALE */
  2683. if (cc == '(') // read "(a,(e,(" (ambiguity resolution)
  2684. {
  2685. u = ::std::complex<T>(a);
  2686. x = ::std::complex<T>(c); // "c" is actually "e"
  2687. is.putback(ch); // we backtrack
  2688. is >> y; // read "(a,(e,y"
  2689. if (!is.good()) goto finish;
  2690. is >> ch; // get the next lexeme
  2691. if (!is.good()) goto finish;
  2692. #ifdef BOOST_NO_STD_LOCALE
  2693. cc = ch;
  2694. #else
  2695. cc = ct.narrow(ch, char());
  2696. #endif /* BOOST_NO_STD_LOCALE */
  2697. if (cc == ')') // read "(a,(e,y)"
  2698. {
  2699. is >> ch; // get the next lexeme
  2700. if (!is.good()) goto finish;
  2701. #ifdef BOOST_NO_STD_LOCALE
  2702. cc = ch;
  2703. #else
  2704. cc = ct.narrow(ch, char());
  2705. #endif /* BOOST_NO_STD_LOCALE */
  2706. if (cc == ')') // read "(a,(e,y))"
  2707. {
  2708. o = octonion<T>(u,v,x,y);
  2709. }
  2710. else // error
  2711. {
  2712. is.setstate(::std::ios_base::failbit);
  2713. }
  2714. }
  2715. else // error
  2716. {
  2717. is.setstate(::std::ios_base::failbit);
  2718. }
  2719. }
  2720. else // read "(a,(c,d" or "(a,(e,f"
  2721. {
  2722. is.putback(ch);
  2723. is >> d;
  2724. if (!is.good()) goto finish;
  2725. is >> ch; // get the next lexeme
  2726. if (!is.good()) goto finish;
  2727. #ifdef BOOST_NO_STD_LOCALE
  2728. cc = ch;
  2729. #else
  2730. cc = ct.narrow(ch, char());
  2731. #endif /* BOOST_NO_STD_LOCALE */
  2732. if (cc == ')') // read "(a,(c,d)" (ambiguity resolution)
  2733. {
  2734. is >> ch; // get the next lexeme
  2735. if (!is.good()) goto finish;
  2736. #ifdef BOOST_NO_STD_LOCALE
  2737. cc = ch;
  2738. #else
  2739. cc = ct.narrow(ch, char());
  2740. #endif /* BOOST_NO_STD_LOCALE */
  2741. if (cc == ')') // read "(a,(c,d))"
  2742. {
  2743. o = octonion<T>(a,b,c,d);
  2744. }
  2745. else if (cc == ',') // read "(a,(c,d),"
  2746. {
  2747. u = ::std::complex<T>(a);
  2748. v = ::std::complex<T>(c,d);
  2749. is >> x; // read "(a,(c,d),x"
  2750. if (!is.good()) goto finish;
  2751. is >> ch; // get the next lexeme
  2752. if (!is.good()) goto finish;
  2753. #ifdef BOOST_NO_STD_LOCALE
  2754. cc = ch;
  2755. #else
  2756. cc = ct.narrow(ch, char());
  2757. #endif /* BOOST_NO_STD_LOCALE */
  2758. if (cc == ')') // read "(a,(c,d),x)"
  2759. {
  2760. o = octonion<T>(u,v,x);
  2761. }
  2762. else if (cc == ',') // read "(a,(c,d),x,"
  2763. {
  2764. is >> y; // read "(a,(c,d),x,y"
  2765. if (!is.good()) goto finish;
  2766. is >> ch; // get the next lexeme
  2767. if (!is.good()) goto finish;
  2768. #ifdef BOOST_NO_STD_LOCALE
  2769. cc = ch;
  2770. #else
  2771. cc = ct.narrow(ch, char());
  2772. #endif /* BOOST_NO_STD_LOCALE */
  2773. if (cc == ')') // read "(a,(c,d),x,y)"
  2774. {
  2775. o = octonion<T>(u,v,x,y);
  2776. }
  2777. else // error
  2778. {
  2779. is.setstate(::std::ios_base::failbit);
  2780. }
  2781. }
  2782. else // error
  2783. {
  2784. is.setstate(::std::ios_base::failbit);
  2785. }
  2786. }
  2787. else // error
  2788. {
  2789. is.setstate(::std::ios_base::failbit);
  2790. }
  2791. }
  2792. else if (cc == ',') // read "(a,(e,f," (ambiguity resolution)
  2793. {
  2794. p = ::boost::math::quaternion<T>(a);
  2795. is >> g; // read "(a,(e,f,g"
  2796. if (!is.good()) goto finish;
  2797. is >> ch; // get the next lexeme
  2798. if (!is.good()) goto finish;
  2799. #ifdef BOOST_NO_STD_LOCALE
  2800. cc = ch;
  2801. #else
  2802. cc = ct.narrow(ch, char());
  2803. #endif /* BOOST_NO_STD_LOCALE */
  2804. if (cc == ')') // read "(a,(e,f,g)"
  2805. {
  2806. is >> ch; // get the next lexeme
  2807. if (!is.good()) goto finish;
  2808. #ifdef BOOST_NO_STD_LOCALE
  2809. cc = ch;
  2810. #else
  2811. cc = ct.narrow(ch, char());
  2812. #endif /* BOOST_NO_STD_LOCALE */
  2813. if (cc == ')') // read "(a,(e,f,g))"
  2814. {
  2815. q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f"
  2816. o = octonion<T>(p,q);
  2817. }
  2818. else // error
  2819. {
  2820. is.setstate(::std::ios_base::failbit);
  2821. }
  2822. }
  2823. else if (cc == ',') // read "(a,(e,f,g,"
  2824. {
  2825. is >> h; // read "(a,(e,f,g,h"
  2826. if (!is.good()) goto finish;
  2827. is >> ch; // get the next lexeme
  2828. if (!is.good()) goto finish;
  2829. #ifdef BOOST_NO_STD_LOCALE
  2830. cc = ch;
  2831. #else
  2832. cc = ct.narrow(ch, char());
  2833. #endif /* BOOST_NO_STD_LOCALE */
  2834. if (cc == ')') // read "(a,(e,f,g,h)"
  2835. {
  2836. is >> ch; // get the next lexeme
  2837. if (!is.good()) goto finish;
  2838. #ifdef BOOST_NO_STD_LOCALE
  2839. cc = ch;
  2840. #else
  2841. cc = ct.narrow(ch, char());
  2842. #endif /* BOOST_NO_STD_LOCALE */
  2843. if (cc == ')') // read "(a,(e,f,g,h))"
  2844. {
  2845. q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f"
  2846. o = octonion<T>(p,q);
  2847. }
  2848. else // error
  2849. {
  2850. is.setstate(::std::ios_base::failbit);
  2851. }
  2852. }
  2853. else // error
  2854. {
  2855. is.setstate(::std::ios_base::failbit);
  2856. }
  2857. }
  2858. else // error
  2859. {
  2860. is.setstate(::std::ios_base::failbit);
  2861. }
  2862. }
  2863. else // error
  2864. {
  2865. is.setstate(::std::ios_base::failbit);
  2866. }
  2867. }
  2868. }
  2869. else // error
  2870. {
  2871. is.setstate(::std::ios_base::failbit);
  2872. }
  2873. }
  2874. }
  2875. else // read "(a,b" or "(a,c" (ambiguity resolution)
  2876. {
  2877. is.putback(ch);
  2878. is >> b;
  2879. if (!is.good()) goto finish;
  2880. is >> ch; // get the next lexeme
  2881. if (!is.good()) goto finish;
  2882. #ifdef BOOST_NO_STD_LOCALE
  2883. cc = ch;
  2884. #else
  2885. cc = ct.narrow(ch, char());
  2886. #endif /* BOOST_NO_STD_LOCALE */
  2887. if (cc == ')') // read "(a,b)" (ambiguity resolution)
  2888. {
  2889. o = octonion<T>(a,b);
  2890. }
  2891. else if (cc == ',') // read "(a,b," or "(a,c,"
  2892. {
  2893. is >> ch; // get the next lexeme
  2894. if (!is.good()) goto finish;
  2895. #ifdef BOOST_NO_STD_LOCALE
  2896. cc = ch;
  2897. #else
  2898. cc = ct.narrow(ch, char());
  2899. #endif /* BOOST_NO_STD_LOCALE */
  2900. if (cc == '(') // read "(a,c,(" (ambiguity resolution)
  2901. {
  2902. u = ::std::complex<T>(a);
  2903. v = ::std::complex<T>(b); // "b" is actually "c"
  2904. is.putback(ch); // we backtrack
  2905. is >> x; // read "(a,c,x"
  2906. if (!is.good()) goto finish;
  2907. is >> ch; // get the next lexeme
  2908. if (!is.good()) goto finish;
  2909. #ifdef BOOST_NO_STD_LOCALE
  2910. cc = ch;
  2911. #else
  2912. cc = ct.narrow(ch, char());
  2913. #endif /* BOOST_NO_STD_LOCALE */
  2914. if (cc == ')') // read "(a,c,x)"
  2915. {
  2916. o = octonion<T>(u,v,x);
  2917. }
  2918. else if (cc == ',') // read "(a,c,x,"
  2919. {
  2920. is >> y; // read "(a,c,x,y" // read "(a,c,x"
  2921. if (!is.good()) goto finish;
  2922. is >> ch; // get the next lexeme
  2923. if (!is.good()) goto finish;
  2924. #ifdef BOOST_NO_STD_LOCALE
  2925. cc = ch;
  2926. #else
  2927. cc = ct.narrow(ch, char());
  2928. #endif /* BOOST_NO_STD_LOCALE */
  2929. if (cc == ')') // read "(a,c,x,y)"
  2930. {
  2931. o = octonion<T>(u,v,x,y);
  2932. }
  2933. else // error
  2934. {
  2935. is.setstate(::std::ios_base::failbit);
  2936. }
  2937. }
  2938. else // error
  2939. {
  2940. is.setstate(::std::ios_base::failbit);
  2941. }
  2942. }
  2943. else // read "(a,b,c" or "(a,c,e"
  2944. {
  2945. is.putback(ch);
  2946. is >> c;
  2947. if (!is.good()) goto finish;
  2948. is >> ch; // get the next lexeme
  2949. if (!is.good()) goto finish;
  2950. #ifdef BOOST_NO_STD_LOCALE
  2951. cc = ch;
  2952. #else
  2953. cc = ct.narrow(ch, char());
  2954. #endif /* BOOST_NO_STD_LOCALE */
  2955. if (cc == ')') // read "(a,b,c)" (ambiguity resolution)
  2956. {
  2957. o = octonion<T>(a,b,c);
  2958. }
  2959. else if (cc == ',') // read "(a,b,c," or "(a,c,e,"
  2960. {
  2961. is >> ch; // get the next lexeme
  2962. if (!is.good()) goto finish;
  2963. #ifdef BOOST_NO_STD_LOCALE
  2964. cc = ch;
  2965. #else
  2966. cc = ct.narrow(ch, char());
  2967. #endif /* BOOST_NO_STD_LOCALE */
  2968. if (cc == '(') // read "(a,c,e,(") (ambiguity resolution)
  2969. {
  2970. u = ::std::complex<T>(a);
  2971. v = ::std::complex<T>(b); // "b" is actually "c"
  2972. x = ::std::complex<T>(c); // "c" is actually "e"
  2973. is.putback(ch); // we backtrack
  2974. is >> y; // read "(a,c,e,y"
  2975. if (!is.good()) goto finish;
  2976. is >> ch; // get the next lexeme
  2977. if (!is.good()) goto finish;
  2978. #ifdef BOOST_NO_STD_LOCALE
  2979. cc = ch;
  2980. #else
  2981. cc = ct.narrow(ch, char());
  2982. #endif /* BOOST_NO_STD_LOCALE */
  2983. if (cc == ')') // read "(a,c,e,y)"
  2984. {
  2985. o = octonion<T>(u,v,x,y);
  2986. }
  2987. else // error
  2988. {
  2989. is.setstate(::std::ios_base::failbit);
  2990. }
  2991. }
  2992. else // read "(a,b,c,d" (ambiguity resolution)
  2993. {
  2994. is.putback(ch); // we backtrack
  2995. is >> d;
  2996. if (!is.good()) goto finish;
  2997. is >> ch; // get the next lexeme
  2998. if (!is.good()) goto finish;
  2999. #ifdef BOOST_NO_STD_LOCALE
  3000. cc = ch;
  3001. #else
  3002. cc = ct.narrow(ch, char());
  3003. #endif /* BOOST_NO_STD_LOCALE */
  3004. if (cc == ')') // read "(a,b,c,d)"
  3005. {
  3006. o = octonion<T>(a,b,c,d);
  3007. }
  3008. else if (cc == ',') // read "(a,b,c,d,"
  3009. {
  3010. is >> e; // read "(a,b,c,d,e"
  3011. if (!is.good()) goto finish;
  3012. is >> ch; // get the next lexeme
  3013. if (!is.good()) goto finish;
  3014. #ifdef BOOST_NO_STD_LOCALE
  3015. cc = ch;
  3016. #else
  3017. cc = ct.narrow(ch, char());
  3018. #endif /* BOOST_NO_STD_LOCALE */
  3019. if (cc == ')') // read "(a,b,c,d,e)"
  3020. {
  3021. o = octonion<T>(a,b,c,d,e);
  3022. }
  3023. else if (cc == ',') // read "(a,b,c,d,e,"
  3024. {
  3025. is >> f; // read "(a,b,c,d,e,f"
  3026. if (!is.good()) goto finish;
  3027. is >> ch; // get the next lexeme
  3028. if (!is.good()) goto finish;
  3029. #ifdef BOOST_NO_STD_LOCALE
  3030. cc = ch;
  3031. #else
  3032. cc = ct.narrow(ch, char());
  3033. #endif /* BOOST_NO_STD_LOCALE */
  3034. if (cc == ')') // read "(a,b,c,d,e,f)"
  3035. {
  3036. o = octonion<T>(a,b,c,d,e,f);
  3037. }
  3038. else if (cc == ',') // read "(a,b,c,d,e,f,"
  3039. {
  3040. is >> g; // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f"
  3041. if (!is.good()) goto finish;
  3042. is >> ch; // get the next lexeme
  3043. if (!is.good()) goto finish;
  3044. #ifdef BOOST_NO_STD_LOCALE
  3045. cc = ch;
  3046. #else
  3047. cc = ct.narrow(ch, char());
  3048. #endif /* BOOST_NO_STD_LOCALE */
  3049. if (cc == ')') // read "(a,b,c,d,e,f,g)"
  3050. {
  3051. o = octonion<T>(a,b,c,d,e,f,g);
  3052. }
  3053. else if (cc == ',') // read "(a,b,c,d,e,f,g,"
  3054. {
  3055. is >> h; // read "(a,b,c,d,e,f,g,h" // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f"
  3056. if (!is.good()) goto finish;
  3057. is >> ch; // get the next lexeme
  3058. if (!is.good()) goto finish;
  3059. #ifdef BOOST_NO_STD_LOCALE
  3060. cc = ch;
  3061. #else
  3062. cc = ct.narrow(ch, char());
  3063. #endif /* BOOST_NO_STD_LOCALE */
  3064. if (cc == ')') // read "(a,b,c,d,e,f,g,h)"
  3065. {
  3066. o = octonion<T>(a,b,c,d,e,f,g,h);
  3067. }
  3068. else // error
  3069. {
  3070. is.setstate(::std::ios_base::failbit);
  3071. }
  3072. }
  3073. else // error
  3074. {
  3075. is.setstate(::std::ios_base::failbit);
  3076. }
  3077. }
  3078. else // error
  3079. {
  3080. is.setstate(::std::ios_base::failbit);
  3081. }
  3082. }
  3083. else // error
  3084. {
  3085. is.setstate(::std::ios_base::failbit);
  3086. }
  3087. }
  3088. else // error
  3089. {
  3090. is.setstate(::std::ios_base::failbit);
  3091. }
  3092. }
  3093. }
  3094. else // error
  3095. {
  3096. is.setstate(::std::ios_base::failbit);
  3097. }
  3098. }
  3099. }
  3100. else // error
  3101. {
  3102. is.setstate(::std::ios_base::failbit);
  3103. }
  3104. }
  3105. }
  3106. else // error
  3107. {
  3108. is.setstate(::std::ios_base::failbit);
  3109. }
  3110. }
  3111. }
  3112. else // format: a
  3113. {
  3114. is.putback(ch);
  3115. is >> a; // we extract the first component
  3116. if (!is.good()) goto finish;
  3117. o = octonion<T>(a);
  3118. }
  3119. finish:
  3120. return(is);
  3121. }
  3122. // LCOV_EXCL_STOP
  3123. template<typename T, typename charT, class traits>
  3124. ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os,
  3125. octonion<T> const & o)
  3126. {
  3127. ::std::basic_ostringstream<charT,traits> s;
  3128. s.flags(os.flags());
  3129. #ifdef BOOST_NO_STD_LOCALE
  3130. #else
  3131. s.imbue(os.getloc());
  3132. #endif /* BOOST_NO_STD_LOCALE */
  3133. s.precision(os.precision());
  3134. s << '(' << o.R_component_1() << ','
  3135. << o.R_component_2() << ','
  3136. << o.R_component_3() << ','
  3137. << o.R_component_4() << ','
  3138. << o.R_component_5() << ','
  3139. << o.R_component_6() << ','
  3140. << o.R_component_7() << ','
  3141. << o.R_component_8() << ')';
  3142. return os << s.str();
  3143. }
  3144. // values
  3145. template<typename T>
  3146. inline T real(octonion<T> const & o)
  3147. {
  3148. return(o.real());
  3149. }
  3150. template<typename T>
  3151. inline octonion<T> unreal(octonion<T> const & o)
  3152. {
  3153. return(o.unreal());
  3154. }
  3155. #define BOOST_OCTONION_VALARRAY_LOADER \
  3156. using ::std::valarray; \
  3157. \
  3158. valarray<T> temp(8); \
  3159. \
  3160. temp[0] = o.R_component_1(); \
  3161. temp[1] = o.R_component_2(); \
  3162. temp[2] = o.R_component_3(); \
  3163. temp[3] = o.R_component_4(); \
  3164. temp[4] = o.R_component_5(); \
  3165. temp[5] = o.R_component_6(); \
  3166. temp[6] = o.R_component_7(); \
  3167. temp[7] = o.R_component_8();
  3168. template<typename T>
  3169. inline T sup(octonion<T> const & o)
  3170. {
  3171. #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
  3172. using ::std::abs;
  3173. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  3174. BOOST_OCTONION_VALARRAY_LOADER
  3175. return((abs(temp).max)());
  3176. }
  3177. template<typename T>
  3178. inline T l1(octonion<T> const & o)
  3179. {
  3180. #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
  3181. using ::std::abs;
  3182. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  3183. BOOST_OCTONION_VALARRAY_LOADER
  3184. return(abs(temp).sum());
  3185. }
  3186. template<typename T>
  3187. inline T abs(const octonion<T> & o)
  3188. {
  3189. #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
  3190. using ::std::abs;
  3191. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  3192. using ::std::sqrt;
  3193. BOOST_OCTONION_VALARRAY_LOADER
  3194. T maxim = (abs(temp).max)(); // overflow protection
  3195. if (maxim == static_cast<T>(0))
  3196. {
  3197. return(maxim);
  3198. }
  3199. else
  3200. {
  3201. T mixam = static_cast<T>(1)/maxim; // prefer multiplications over divisions
  3202. temp *= mixam;
  3203. temp *= temp;
  3204. return(maxim*sqrt(temp.sum()));
  3205. }
  3206. //return(::std::sqrt(norm(o)));
  3207. }
  3208. #undef BOOST_OCTONION_VALARRAY_LOADER
  3209. // Note: This is the Cayley norm, not the Euclidean norm...
  3210. template<typename T>
  3211. inline T norm(octonion<T> const & o)
  3212. {
  3213. return(real(o*conj(o)));
  3214. }
  3215. template<typename T>
  3216. inline octonion<T> conj(octonion<T> const & o)
  3217. {
  3218. return(octonion<T>( +o.R_component_1(),
  3219. -o.R_component_2(),
  3220. -o.R_component_3(),
  3221. -o.R_component_4(),
  3222. -o.R_component_5(),
  3223. -o.R_component_6(),
  3224. -o.R_component_7(),
  3225. -o.R_component_8()));
  3226. }
  3227. // Note: There is little point, for the octonions, to introduce the equivalents
  3228. // to the complex "arg" and the quaternionic "cylindropolar".
  3229. template<typename T>
  3230. inline octonion<T> spherical(T const & rho,
  3231. T const & theta,
  3232. T const & phi1,
  3233. T const & phi2,
  3234. T const & phi3,
  3235. T const & phi4,
  3236. T const & phi5,
  3237. T const & phi6)
  3238. {
  3239. using ::std::cos;
  3240. using ::std::sin;
  3241. //T a = cos(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3242. //T b = sin(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3243. //T c = sin(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3244. //T d = sin(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3245. //T e = sin(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3246. //T f = sin(phi4)*cos(phi5)*cos(phi6);
  3247. //T g = sin(phi5)*cos(phi6);
  3248. //T h = sin(phi6);
  3249. T courrant = static_cast<T>(1);
  3250. T h = sin(phi6);
  3251. courrant *= cos(phi6);
  3252. T g = sin(phi5)*courrant;
  3253. courrant *= cos(phi5);
  3254. T f = sin(phi4)*courrant;
  3255. courrant *= cos(phi4);
  3256. T e = sin(phi3)*courrant;
  3257. courrant *= cos(phi3);
  3258. T d = sin(phi2)*courrant;
  3259. courrant *= cos(phi2);
  3260. T c = sin(phi1)*courrant;
  3261. courrant *= cos(phi1);
  3262. T b = sin(theta)*courrant;
  3263. T a = cos(theta)*courrant;
  3264. return(rho*octonion<T>(a,b,c,d,e,f,g,h));
  3265. }
  3266. template<typename T>
  3267. inline octonion<T> multipolar(T const & rho1,
  3268. T const & theta1,
  3269. T const & rho2,
  3270. T const & theta2,
  3271. T const & rho3,
  3272. T const & theta3,
  3273. T const & rho4,
  3274. T const & theta4)
  3275. {
  3276. using ::std::cos;
  3277. using ::std::sin;
  3278. T a = rho1*cos(theta1);
  3279. T b = rho1*sin(theta1);
  3280. T c = rho2*cos(theta2);
  3281. T d = rho2*sin(theta2);
  3282. T e = rho3*cos(theta3);
  3283. T f = rho3*sin(theta3);
  3284. T g = rho4*cos(theta4);
  3285. T h = rho4*sin(theta4);
  3286. return(octonion<T>(a,b,c,d,e,f,g,h));
  3287. }
  3288. template<typename T>
  3289. inline octonion<T> cylindrical(T const & r,
  3290. T const & angle,
  3291. T const & h1,
  3292. T const & h2,
  3293. T const & h3,
  3294. T const & h4,
  3295. T const & h5,
  3296. T const & h6)
  3297. {
  3298. using ::std::cos;
  3299. using ::std::sin;
  3300. T a = r*cos(angle);
  3301. T b = r*sin(angle);
  3302. return(octonion<T>(a,b,h1,h2,h3,h4,h5,h6));
  3303. }
  3304. template<typename T>
  3305. inline octonion<T> exp(octonion<T> const & o)
  3306. {
  3307. using ::std::exp;
  3308. using ::std::cos;
  3309. using ::boost::math::sinc_pi;
  3310. T u = exp(real(o));
  3311. T z = abs(unreal(o));
  3312. T w = sinc_pi(z);
  3313. return(u*octonion<T>(cos(z),
  3314. w*o.R_component_2(), w*o.R_component_3(),
  3315. w*o.R_component_4(), w*o.R_component_5(),
  3316. w*o.R_component_6(), w*o.R_component_7(),
  3317. w*o.R_component_8()));
  3318. }
  3319. template<typename T>
  3320. inline octonion<T> cos(octonion<T> const & o)
  3321. {
  3322. using ::std::sin;
  3323. using ::std::cos;
  3324. using ::std::cosh;
  3325. using ::boost::math::sinhc_pi;
  3326. T z = abs(unreal(o));
  3327. T w = -sin(o.real())*sinhc_pi(z);
  3328. return(octonion<T>(cos(o.real())*cosh(z),
  3329. w*o.R_component_2(), w*o.R_component_3(),
  3330. w*o.R_component_4(), w*o.R_component_5(),
  3331. w*o.R_component_6(), w*o.R_component_7(),
  3332. w*o.R_component_8()));
  3333. }
  3334. template<typename T>
  3335. inline octonion<T> sin(octonion<T> const & o)
  3336. {
  3337. using ::std::sin;
  3338. using ::std::cos;
  3339. using ::std::cosh;
  3340. using ::boost::math::sinhc_pi;
  3341. T z = abs(unreal(o));
  3342. T w = +cos(o.real())*sinhc_pi(z);
  3343. return(octonion<T>(sin(o.real())*cosh(z),
  3344. w*o.R_component_2(), w*o.R_component_3(),
  3345. w*o.R_component_4(), w*o.R_component_5(),
  3346. w*o.R_component_6(), w*o.R_component_7(),
  3347. w*o.R_component_8()));
  3348. }
  3349. template<typename T>
  3350. inline octonion<T> tan(octonion<T> const & o)
  3351. {
  3352. return(sin(o)/cos(o));
  3353. }
  3354. template<typename T>
  3355. inline octonion<T> cosh(octonion<T> const & o)
  3356. {
  3357. return((exp(+o)+exp(-o))/static_cast<T>(2));
  3358. }
  3359. template<typename T>
  3360. inline octonion<T> sinh(octonion<T> const & o)
  3361. {
  3362. return((exp(+o)-exp(-o))/static_cast<T>(2));
  3363. }
  3364. template<typename T>
  3365. inline octonion<T> tanh(octonion<T> const & o)
  3366. {
  3367. return(sinh(o)/cosh(o));
  3368. }
  3369. template<typename T>
  3370. octonion<T> pow(octonion<T> const & o,
  3371. int n)
  3372. {
  3373. if (n > 1)
  3374. {
  3375. int m = n>>1;
  3376. octonion<T> result = pow(o, m);
  3377. result *= result;
  3378. if (n != (m<<1))
  3379. {
  3380. result *= o; // n odd
  3381. }
  3382. return(result);
  3383. }
  3384. else if (n == 1)
  3385. {
  3386. return(o);
  3387. }
  3388. else if (n == 0)
  3389. {
  3390. return(octonion<T>(static_cast<T>(1)));
  3391. }
  3392. else /* n < 0 */
  3393. {
  3394. return(pow(octonion<T>(static_cast<T>(1))/o,-n));
  3395. }
  3396. }
  3397. // helper templates for converting copy constructors (definition)
  3398. namespace detail
  3399. {
  3400. template< typename T,
  3401. typename U
  3402. >
  3403. octonion<T> octonion_type_converter(octonion<U> const & rhs)
  3404. {
  3405. return(octonion<T>( static_cast<T>(rhs.R_component_1()),
  3406. static_cast<T>(rhs.R_component_2()),
  3407. static_cast<T>(rhs.R_component_3()),
  3408. static_cast<T>(rhs.R_component_4()),
  3409. static_cast<T>(rhs.R_component_5()),
  3410. static_cast<T>(rhs.R_component_6()),
  3411. static_cast<T>(rhs.R_component_7()),
  3412. static_cast<T>(rhs.R_component_8())));
  3413. }
  3414. }
  3415. }
  3416. }
  3417. #endif /* BOOST_OCTONION_HPP */