1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>mpc_complex</title> 5<link rel="stylesheet" href="../../../multiprecision.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision"> 8<link rel="up" href="../complex.html" title="Complex Number Types"> 9<link rel="prev" href="cpp_complex.html" title="cpp_complex"> 10<link rel="next" href="complex128.html" title="complex128"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="cpp_complex.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../complex.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="complex128.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="boost_multiprecision.tut.complex.mpc_complex"></a><a class="link" href="mpc_complex.html" title="mpc_complex">mpc_complex</a> 28</h4></div></div></div> 29<p> 30 <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">mpc</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 31 </p> 32<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span> 33 34<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">></span> 35<span class="keyword">class</span> <span class="identifier">mpc_complex_backend</span><span class="special">;</span> 36 37<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpc_complex_backend</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpc_complex_50</span><span class="special">;</span> 38<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpc_complex_backend</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpc_complex_100</span><span class="special">;</span> 39<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpc_complex_backend</span><span class="special"><</span><span class="number">500</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpc_complex_500</span><span class="special">;</span> 40<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpc_complex_backend</span><span class="special"><</span><span class="number">1000</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpc_complex_1000</span><span class="special">;</span> 41<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpc_complex_backend</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpc_complex</span><span class="special">;</span> 42 43<span class="special">}}</span> <span class="comment">// namespaces</span> 44</pre> 45<p> 46 The <code class="computeroutput"><span class="identifier">mpc_complex_backend</span></code> 47 type is used in conjunction with <code class="computeroutput"><span class="identifier">number</span></code>: 48 It acts as a thin wrapper around the <a href="http://www.multiprecision.org" target="_top">MPC</a> 49 <code class="computeroutput"><span class="identifier">mpc_t</span></code> to provide an real-number 50 type that is a drop-in replacement for <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span></code>, 51 but with much greater precision. 52 </p> 53<p> 54 Type <code class="computeroutput"><span class="identifier">mpc_complex_backend</span></code> 55 can be used at fixed precision by specifying a non-zero <code class="computeroutput"><span class="identifier">Digits10</span></code> 56 template parameter, or at variable precision by setting the template argument 57 to zero. The typedefs mpc_complex_50, mpc_complex_100, mpc_complex_500, 58 mpc_complex_1000 provide complex types at 50, 100, 500 and 1000 decimal 59 digits precision respectively. The typedef mpc_complex provides a variable 60 precision type whose precision can be controlled via the <code class="computeroutput"><span class="identifier">number</span></code>s member functions. 61 </p> 62<p> 63 The <code class="computeroutput"><span class="identifier">mpc</span></code> backend should 64 allow use of the same syntax as the C++ standard library complex type. 65 When using this backend, remember to link with the flags <code class="computeroutput"><span class="special">-</span><span class="identifier">lmpc</span> <span class="special">-</span><span class="identifier">lmpfr</span> <span class="special">-</span><span class="identifier">lgmp</span></code>. 66 </p> 67<p> 68 As well as the usual conversions from arithmetic and string types, instances 69 of <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpc_complex_backend</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">></span></code> are copy constructible and assignable 70 from: 71 </p> 72<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 73<li class="listitem"> 74 The <a href="http://gmplib.org" target="_top">GMP</a> native types <code class="computeroutput"><span class="identifier">mpf_t</span></code>, <code class="computeroutput"><span class="identifier">mpz_t</span></code>, 75 <code class="computeroutput"><span class="identifier">mpq_t</span></code>. 76 </li> 77<li class="listitem"> 78 The <a href="http://www.mpfr.org" target="_top">MPFR</a> native type <code class="computeroutput"><span class="identifier">mpfr_t</span></code>. 79 </li> 80<li class="listitem"> 81 The <a href="http://www.multiprecision.org" target="_top">MPC</a> native type 82 <code class="computeroutput"><span class="identifier">mpc_t</span></code>. 83 </li> 84<li class="listitem"> 85 The <code class="computeroutput"><span class="identifier">number</span></code> wrappers 86 around those types: <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>, 87 <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpf_float</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>, <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_int</span><span class="special">></span></code>, <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_rational</span><span class="special">></span></code>. 88 </li> 89</ul></div> 90<p> 91 It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpc_t</span></code> 92 via the <code class="computeroutput"><span class="identifier">data</span><span class="special">()</span></code> 93 member function of <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>. 94 </p> 95<p> 96 Things you should know when using this type: 97 </p> 98<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 99<li class="listitem"> 100 A default constructed <code class="computeroutput"><span class="identifier">mpc_complex_backend</span></code> 101 is set to zero (<span class="emphasis"><em>Note that this is <span class="bold"><strong>not</strong></span> 102 the default <a href="http://www.multiprecision.org" target="_top">MPC</a> 103 behavior</em></span>). 104 </li> 105<li class="listitem"> 106 All operations use round to nearest. 107 </li> 108<li class="listitem"> 109 No changes are made to <a href="http://www.multiprecision.org" target="_top">MPC</a>, 110 <a href="http://gmplib.org" target="_top">GMP</a> or <a href="http://www.mpfr.org" target="_top">MPFR</a> 111 global settings, so this type can coexist with existing <a href="http://www.multiprecision.org" target="_top">MPC</a>, 112 <a href="http://www.mpfr.org" target="_top">MPFR</a> or <a href="http://gmplib.org" target="_top">GMP</a> 113 code. 114 </li> 115<li class="listitem"> 116 The code can equally use <a href="http://mpir.org/" target="_top">MPIR</a> 117 in place of <a href="http://gmplib.org" target="_top">GMP</a> - indeed that 118 is the preferred option on Win32. 119 </li> 120<li class="listitem"> 121 This backend supports rvalue-references and is move-aware, making instantiations 122 of <code class="computeroutput"><span class="identifier">number</span></code> on this backend 123 move aware. 124 </li> 125<li class="listitem"> 126 Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code> 127 being thrown if the string can not be interpreted as a valid complex 128 number. 129 </li> 130<li class="listitem"> 131 Division by zero results in a complex-infinity. 132 </li> 133<li class="listitem"> 134 Unlike <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span></code>, you can not use <code class="computeroutput"><span class="keyword">reinterpret_cast</span></code> to treat this type 135 as an array of the underlying floating point type. 136 </li> 137<li class="listitem"> 138 Unlike <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span></code>, there are no literals for 139 imaginary values. 140 </li> 141<li class="listitem"> 142 When using the variable precision type <code class="computeroutput"><span class="identifier">mpc_complex</span></code>, 143 then copy construction and assignment <span class="emphasis"><em>copies the precision 144 of the source variable</em></span>. Likewise move construction and assignment. 145 </li> 146<li class="listitem"> 147 When constructing the variable precision type <code class="computeroutput"><span class="identifier">mpc_complex</span></code> 148 you can specify two arguments to the constructor - the first is the 149 value to assign to the variable, the second is an unsigned integer 150 specifying the precision in decimal places. The <code class="computeroutput"><span class="identifier">assign</span></code> 151 member function similarly has a 2-argument overload taking the value 152 to assign and the precision. You can use this to preserve the precision 153 of the target variable using the somewhat arcane: <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">a</span><span class="special">.</span><span class="identifier">precision</span><span class="special">())</span></code>, which assigns <code class="computeroutput"><span class="identifier">b</span></code> 154 to <code class="computeroutput"><span class="identifier">a</span></code> but preserves 155 the precision of <code class="computeroutput"><span class="identifier">a</span></code>. 156 </li> 157</ul></div> 158<h6> 159<a name="boost_multiprecision.tut.complex.mpc_complex.h0"></a> 160 <span class="phrase"><a name="boost_multiprecision.tut.complex.mpc_complex.mpc_example"></a></span><a class="link" href="mpc_complex.html#boost_multiprecision.tut.complex.mpc_complex.mpc_example"> MPC example:</a> 161 </h6> 162<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 163<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">complex</span><span class="special">></span> 164<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">mpc</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 165 166<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Complex</span><span class="special">></span> 167<span class="keyword">void</span> <span class="identifier">complex_number_examples</span><span class="special">()</span> 168<span class="special">{</span> 169 <span class="identifier">Complex</span> <span class="identifier">z1</span><span class="special">{</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">};</span> 170 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Complex</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">);</span> 171 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">scientific</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">fixed</span><span class="special">;</span> 172 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Print a complex number: "</span> <span class="special"><<</span> <span class="identifier">z1</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 173 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Square it : "</span> <span class="special"><<</span> <span class="identifier">z1</span><span class="special">*</span><span class="identifier">z1</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 174 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Real part : "</span> <span class="special"><<</span> <span class="identifier">z1</span><span class="special">.</span><span class="identifier">real</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" = "</span> <span class="special"><<</span> <span class="identifier">real</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 175 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Imaginary part : "</span> <span class="special"><<</span> <span class="identifier">z1</span><span class="special">.</span><span class="identifier">imag</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" = "</span> <span class="special"><<</span> <span class="identifier">imag</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 176 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">abs</span><span class="special">;</span> 177 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Absolute value : "</span> <span class="special"><<</span> <span class="identifier">abs</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 178 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Argument : "</span> <span class="special"><<</span> <span class="identifier">arg</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 179 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Norm : "</span> <span class="special"><<</span> <span class="identifier">norm</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 180 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Complex conjugate : "</span> <span class="special"><<</span> <span class="identifier">conj</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 181 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Projection onto Riemann sphere: "</span> <span class="special"><<</span> <span class="identifier">proj</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 182 <span class="keyword">typename</span> <span class="identifier">Complex</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">r</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> 183 <span class="keyword">typename</span> <span class="identifier">Complex</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">theta</span> <span class="special">=</span> <span class="number">0.8</span><span class="special">;</span> 184 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">polar</span><span class="special">;</span> 185 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Polar coordinates (phase = 0) : "</span> <span class="special"><<</span> <span class="identifier">polar</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 186 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Polar coordinates (phase !=0) : "</span> <span class="special"><<</span> <span class="identifier">polar</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">theta</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 187 188 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"\nElementary special functions:\n"</span><span class="special">;</span> 189 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exp</span><span class="special">;</span> 190 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"exp(z1) = "</span> <span class="special"><<</span> <span class="identifier">exp</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 191 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">log</span><span class="special">;</span> 192 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"log(z1) = "</span> <span class="special"><<</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 193 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">log10</span><span class="special">;</span> 194 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"log10(z1) = "</span> <span class="special"><<</span> <span class="identifier">log10</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 195 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span><span class="special">;</span> 196 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"pow(z1, z1) = "</span> <span class="special"><<</span> <span class="identifier">pow</span><span class="special">(</span><span class="identifier">z1</span><span class="special">,</span> <span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 197 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">sqrt</span><span class="special">;</span> 198 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Take its square root : "</span> <span class="special"><<</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 199 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">sin</span><span class="special">;</span> 200 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sin(z1) = "</span> <span class="special"><<</span> <span class="identifier">sin</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 201 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cos</span><span class="special">;</span> 202 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"cos(z1) = "</span> <span class="special"><<</span> <span class="identifier">cos</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 203 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tan</span><span class="special">;</span> 204 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"tan(z1) = "</span> <span class="special"><<</span> <span class="identifier">tan</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 205 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">asin</span><span class="special">;</span> 206 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"asin(z1) = "</span> <span class="special"><<</span> <span class="identifier">asin</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 207 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">acos</span><span class="special">;</span> 208 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"acos(z1) = "</span> <span class="special"><<</span> <span class="identifier">acos</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 209 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">atan</span><span class="special">;</span> 210 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"atan(z1) = "</span> <span class="special"><<</span> <span class="identifier">atan</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 211 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">sinh</span><span class="special">;</span> 212 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sinh(z1) = "</span> <span class="special"><<</span> <span class="identifier">sinh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 213 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cosh</span><span class="special">;</span> 214 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"cosh(z1) = "</span> <span class="special"><<</span> <span class="identifier">cosh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 215 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tanh</span><span class="special">;</span> 216 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"tanh(z1) = "</span> <span class="special"><<</span> <span class="identifier">tanh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 217 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">asinh</span><span class="special">;</span> 218 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"asinh(z1) = "</span> <span class="special"><<</span> <span class="identifier">asinh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 219 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">acosh</span><span class="special">;</span> 220 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"acosh(z1) = "</span> <span class="special"><<</span> <span class="identifier">acosh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 221 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">atanh</span><span class="special">;</span> 222 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"atanh(z1) = "</span> <span class="special"><<</span> <span class="identifier">atanh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 223<span class="special">}</span> 224 225<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 226<span class="special">{</span> 227 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"First, some operations we usually perform with std::complex:\n"</span><span class="special">;</span> 228 <span class="identifier">complex_number_examples</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special"><</span><span class="keyword">double</span><span class="special">>>();</span> 229 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"\nNow the same operations performed using the MPC backend:\n"</span><span class="special">;</span> 230 <span class="identifier">complex_number_examples</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">mpc_complex_50</span><span class="special">>();</span> 231 232 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 233<span class="special">}</span> 234</pre> 235<p> 236 Which produces the output (for the multiprecision type): 237 </p> 238<pre class="programlisting"><span class="identifier">Print</span> <span class="identifier">a</span> <span class="identifier">complex</span> <span class="identifier">number</span><span class="special">:</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">1.00000000000000000000000000000000000000000000000000</span><span class="special">)</span> 239<span class="identifier">Square</span> <span class="identifier">it</span> <span class="special">:</span> <span class="special">-</span><span class="number">1.00000000000000000000000000000000000000000000000000</span> 240<span class="identifier">Real</span> <span class="identifier">part</span> <span class="special">:</span> <span class="number">0.00000000000000000000000000000000000000000000000000</span> <span class="special">=</span> <span class="number">0.00000000000000000000000000000000000000000000000000</span> 241<span class="identifier">Imaginary</span> <span class="identifier">part</span> <span class="special">:</span> <span class="number">1.00000000000000000000000000000000000000000000000000</span> <span class="special">=</span> <span class="number">1.00000000000000000000000000000000000000000000000000</span> 242<span class="identifier">Absolute</span> <span class="identifier">value</span> <span class="special">:</span> <span class="number">1.00000000000000000000000000000000000000000000000000</span> 243<span class="identifier">Argument</span> <span class="special">:</span> <span class="number">1.57079632679489661923132169163975144209858469968755</span> 244<span class="identifier">Norm</span> <span class="special">:</span> <span class="number">1.00000000000000000000000000000000000000000000000000</span> 245<span class="identifier">Complex</span> <span class="identifier">conjugate</span> <span class="special">:</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,-</span><span class="number">1.00000000000000000000000000000000000000000000000000</span><span class="special">)</span> 246<span class="identifier">Projection</span> <span class="identifier">onto</span> <span class="identifier">Riemann</span> <span class="identifier">sphere</span><span class="special">:</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">1.00000000000000000000000000000000000000000000000000</span><span class="special">)</span> 247<span class="identifier">Polar</span> <span class="identifier">coordinates</span> <span class="special">(</span><span class="identifier">phase</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span> <span class="special">:</span> <span class="number">1.00000000000000000000000000000000000000000000000000</span> 248<span class="identifier">Polar</span> <span class="identifier">coordinates</span> <span class="special">(</span><span class="identifier">phase</span> <span class="special">!=</span><span class="number">0</span><span class="special">)</span> <span class="special">:</span> <span class="special">(</span><span class="number">0.69670670934716538906374002277244853473117519431538</span><span class="special">,</span><span class="number">0.71735609089952279256716781570337728075604730751255</span><span class="special">)</span> 249 250<span class="identifier">Elementary</span> <span class="identifier">special</span> <span class="identifier">functions</span><span class="special">:</span> 251<span class="identifier">exp</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.54030230586813971740093660744297660373231042061792</span><span class="special">,</span><span class="number">0.84147098480789650665250232163029899962256306079837</span><span class="special">)</span> 252<span class="identifier">log</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">1.57079632679489661923132169163975144209858469968755</span><span class="special">)</span> 253<span class="identifier">log10</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">0.68218817692092067374289181271567788510506374186196</span><span class="special">)</span> 254<span class="identifier">pow</span><span class="special">(</span><span class="identifier">z1</span><span class="special">,</span> <span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="number">0.20787957635076190854695561983497877003387784163177</span> 255<span class="identifier">Take</span> <span class="identifier">its</span> <span class="identifier">square</span> <span class="identifier">root</span> <span class="special">:</span> <span class="special">(</span><span class="number">0.70710678118654752440084436210484903928483593768847</span><span class="special">,</span><span class="number">0.70710678118654752440084436210484903928483593768847</span><span class="special">)</span> 256<span class="identifier">sin</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">1.17520119364380145688238185059560081515571798133410</span><span class="special">)</span> 257<span class="identifier">cos</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="number">1.54308063481524377847790562075706168260152911236587</span> 258<span class="identifier">tan</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">0.76159415595576488811945828260479359041276859725794</span><span class="special">)</span> 259<span class="identifier">asin</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">0.88137358701954302523260932497979230902816032826163</span><span class="special">)</span> 260<span class="identifier">acos</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">1.57079632679489661923132169163975144209858469968755</span><span class="special">,-</span><span class="number">0.88137358701954302523260932497979230902816032826163</span><span class="special">)</span> 261<span class="identifier">atan</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="identifier">inf</span><span class="special">)</span> 262<span class="identifier">sinh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">0.84147098480789650665250232163029899962256306079837</span><span class="special">)</span> 263<span class="identifier">cosh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="number">0.54030230586813971740093660744297660373231042061792</span> 264<span class="identifier">tanh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">1.55740772465490223050697480745836017308725077238152</span><span class="special">)</span> 265<span class="identifier">asinh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">1.57079632679489661923132169163975144209858469968755</span><span class="special">)</span> 266<span class="identifier">acosh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.88137358701954302523260932497979230902816032826163</span><span class="special">,</span><span class="number">1.57079632679489661923132169163975144209858469968755</span><span class="special">)</span> 267<span class="identifier">atanh</span><span class="special">(</span><span class="identifier">z1</span><span class="special">)</span> <span class="special">=</span> <span class="special">(</span><span class="number">0.00000000000000000000000000000000000000000000000000</span><span class="special">,</span><span class="number">0.78539816339744830961566084581987572104929234984378</span><span class="special">)</span> 268</pre> 269</div> 270<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 271<td align="left"></td> 272<td align="right"><div class="copyright-footer">Copyright © 2002-2020 John 273 Maddock and Christopher Kormanyos<p> 274 Distributed under the Boost Software License, Version 1.0. (See accompanying 275 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 276 </p> 277</div></td> 278</tr></table> 279<hr> 280<div class="spirit-nav"> 281<a accesskey="p" href="cpp_complex.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../complex.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="complex128.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 282</div> 283</body> 284</html> 285