octonion.hpp 221 KB

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