octonion.hpp 217 KB

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