Codebase list cppad / upstream/2015.00.00.7 doc / base_complex.hpp.xml
upstream/2015.00.00.7

Tree @upstream/2015.00.00.7 (Download .tar.gz)

base_complex.hpp.xml @upstream/2015.00.00.7raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Enable use of AD&lt;Base&gt; where Base is std::complex&lt;double&gt;</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="Enable use of AD&lt;Base&gt; where Base is std::complex&lt;double&gt;"/>
<meta name="keywords" id="keywords" content=" complex double Base enable use of ad&lt;base&gt; where base is std::complex&lt;double&gt; example include order condexpop condexprel equalopseq identical ordered erf integer isnan valid unary math invalid pow limits "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_base_complex.hpp_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="base_double.hpp.xml" target="_top">Prev</a>
</td><td><a href="complex_poly.cpp.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>AD</option>
<option>base_require</option>
<option>base_example</option>
<option>base_complex.hpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>AD-&gt;</option>
<option>ad_ctor</option>
<option>ad_assign</option>
<option>Convert</option>
<option>ADValued</option>
<option>BoolValued</option>
<option>VecAD</option>
<option>base_require</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>base_require-&gt;</option>
<option>base_member</option>
<option>base_cond_exp</option>
<option>base_identical</option>
<option>base_ordered</option>
<option>base_std_math</option>
<option>base_example</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>base_example-&gt;</option>
<option>base_alloc.hpp</option>
<option>base_require.cpp</option>
<option>base_adolc.hpp</option>
<option>base_float.hpp</option>
<option>base_double.hpp</option>
<option>base_complex.hpp</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>base_complex.hpp-&gt;</option>
<option>complex_poly.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Example</option>
<option>Include Order</option>
<option>CondExpOp</option>
<option>CondExpRel</option>
<option>EqualOpSeq</option>
<option>Identical</option>
<option>Ordered</option>
<option>erf</option>
<option>Integer</option>
<option>isnan</option>
<option>Valid Unary Math</option>
<option>Invalid Unary Math</option>
<option>pow</option>
<option>limits</option>
</select>
</td>
</tr></table><br/>







<center><b><big><big>Enable use of AD&lt;Base&gt; where Base is std::complex&lt;double&gt;</big></big></b></center>
<br/>
<b><big><a name="Example" id="Example">Example</a></big></b>
<br/>
The file <a href="complex_poly.cpp.xml" target="_top"><span style='white-space: nowrap'>complex_poly.cpp</span></a>
 contains an example use of
<code><font color="blue">std::complex&lt;double&gt;</font></code> type for a CppAD 
<code><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i></code>
 type.
It returns true if it succeeds and false otherwise.

<br/>
<br/>
<b><big><a name="Include Order" id="Include Order">Include Order</a></big></b>
<br/>
This file is included before <code><font color="blue">&lt;cppad/cppad.hpp&gt;</font></code>
so it is necessary to define the error handler
in addition to including
<a href="base_require.xml#Include Order" target="_top"><span style='white-space: nowrap'>base_require.hpp</span></a>

<code><font color='blue'><pre style='display:inline'> 
# include &lt;limits&gt;
# include &lt;complex&gt;
# include &lt;cppad/base_require.hpp&gt;
# include &lt;cppad/local/cppad_assert.hpp&gt;

</pre></font></code>


<br/>
<br/>
<b><big><a name="CondExpOp" id="CondExpOp">CondExpOp</a></big></b>
<br/>
The type <code><font color="blue">std::complex&lt;double&gt;</font></code> does not supports the
<code><font color="blue">&lt;</font></code>, <code><font color="blue">&lt;=</font></code>, <code><font color="blue">==</font></code>, <code><font color="blue">&gt;=</font></code>, and <code><font color="blue">&gt;</font></code> operators; see
<a href="base_cond_exp.xml#CondExpTemplate.Not Ordered" target="_top"><span style='white-space: nowrap'>not&#xA0;ordered</span></a>
.
Hence its <code><font color="blue">CondExpOp</font></code> function is defined by
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	inline std::complex&lt;double&gt; CondExpOp(
		enum CppAD::CompareOp      cop        ,
		const std::complex&lt;double&gt; &amp;left      ,
		const std::complex&lt;double&gt; &amp;right     ,
		const std::complex&lt;double&gt; &amp;trueCase  ,
		const std::complex&lt;double&gt; &amp;falseCase )
	{	CppAD::ErrorHandler::Call(
			true     , __LINE__ , __FILE__ ,
			&quot;std::complex&lt;float&gt; CondExpOp(...)&quot;,
			&quot;Error: cannot use CondExp with a complex type&quot;
		);
		return std::complex&lt;double&gt;(0);
	}
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="CondExpRel" id="CondExpRel">CondExpRel</a></big></b>
<br/>
The <a href="base_cond_exp.xml#CondExpRel" target="_top"><span style='white-space: nowrap'>CPPAD_COND_EXP_REL</span></a>
 macro invocation
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	CPPAD_COND_EXP_REL( std::complex&lt;double&gt; )
}
</pre></font></code>

used <code><font color="blue">CondExpOp</font></code> above to
define 
<code><font color="blue"><span style='white-space: nowrap'>CondExp</span></font><i><font color="black"><span style='white-space: nowrap'>Rel</span></font></i></code>
 for <code><font color="blue">std::complex&lt;double&gt;</font></code> arguments
and 
<code><i><font color="black"><span style='white-space: nowrap'>Rel</span></font></i></code>
 equal to
<code><font color="blue">Lt</font></code>, <code><font color="blue">Le</font></code>, <code><font color="blue">Eq</font></code>, <code><font color="blue">Ge</font></code>, and <code><font color="blue">Gt</font></code>.

<br/>
<br/>
<b><big><a name="EqualOpSeq" id="EqualOpSeq">EqualOpSeq</a></big></b>
<br/>
Complex numbers do not carry operation sequence information. 
Thus they are equal in this sense if and only if there values are equal.  
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	inline bool EqualOpSeq(
		const std::complex&lt;double&gt; &amp;x , 
		const std::complex&lt;double&gt; &amp;y )
	{	return x == y; 
	}
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="Identical" id="Identical">Identical</a></big></b>
<br/>
Complex numbers do not carry operation sequence information. 
Thus they are all parameters so the identical functions just check values.
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	inline bool IdenticalPar(const std::complex&lt;double&gt; &amp;x)
	{	return true; }
	inline bool IdenticalZero(const std::complex&lt;double&gt; &amp;x)
	{	return (x == std::complex&lt;double&gt;(0., 0.) ); }
	inline bool IdenticalOne(const std::complex&lt;double&gt; &amp;x)
	{	return (x == std::complex&lt;double&gt;(1., 0.) ); }
	inline bool IdenticalEqualPar(
		const std::complex&lt;double&gt; &amp;x, const std::complex&lt;double&gt; &amp;y)
	{	return (x == y); }
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="Ordered" id="Ordered">Ordered</a></big></b>
<br/>
Complex types do not support comparison operators, 
<code><font color='blue'><pre style='display:inline'> 
# undef  CPPAD_USER_MACRO
# define CPPAD_USER_MACRO(Fun)                                     \
inline bool Fun(const std::complex&lt;double&gt;&amp; x)                     \
{      CppAD::ErrorHandler::Call(                                  \
               true     , __LINE__ , __FILE__ ,                    \
               #Fun&quot;(x)&quot;,                                          \
               &quot;Error: cannot use &quot; #Fun &quot; with x complex&lt;double&gt; &quot; \
       );                                                          \
       return false;                                               \
}
namespace CppAD {
	CPPAD_USER_MACRO(LessThanZero)
	CPPAD_USER_MACRO(LessThanOrZero)
	CPPAD_USER_MACRO(GreaterThanOrZero)
	CPPAD_USER_MACRO(GreaterThanZero)
	inline bool abs_geq(
		const std::complex&lt;double&gt;&amp; x , 
		const std::complex&lt;double&gt;&amp; y )
	{	return std::abs(x) &gt;= std::abs(y); }
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="erf" id="erf">erf</a></big></b>
<br/>
Complex types do not support the error function
(use CPPAD_USER_MACRO define above).
<code><font color='blue'><pre style='display:inline'> 
# if CPPAD_COMPILER_HAS_ERF
namespace CppAD {
	CPPAD_USER_MACRO(erf)
}
# endif
</pre></font></code>



<br/>
<br/>
<b><big><a name="Integer" id="Integer">Integer</a></big></b>
<br/>
The implementation of this function must agree
with the CppAD user specifications for complex arguments to the
<a href="integer.xml#x.Complex Types" target="_top"><span style='white-space: nowrap'>Integer</span></a>
 function:
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	inline int Integer(const std::complex&lt;double&gt; &amp;x)
	{	return static_cast&lt;int&gt;( x.real() ); }
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="isnan" id="isnan">isnan</a></big></b>
<br/>
The gcc 4.1.1 complier defines the function

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;int&#xA0;std::complex&lt;double&gt;::isnan(&#xA0;std::complex&lt;double&gt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>z</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;)<br/>
</span></font></code>
(which is not specified in the C++ 1998 standard ISO/IEC 14882).
This causes an ambiguity between the function above and the CppAD
<a href="nan.xml" target="_top"><span style='white-space: nowrap'>isnan</span></a>
 template function.
We avoid this ambiguity by defining a non-template version of
this function in the CppAD namespace.
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	inline bool isnan(const std::complex&lt;double&gt;&amp; z)
	{	return (z != z);
	}
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="Valid Unary Math" id="Valid Unary Math">Valid Unary Math</a></big></b>
<br/>
The following macro invocations define the standard unary 
math functions that are valid with complex arguments and are
required to use <code><font color="blue">AD&lt; std::complex&lt;double&gt; &gt;</font></code>.
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	CPPAD_STANDARD_MATH_UNARY(std::complex&lt;double&gt;, cos)
	CPPAD_STANDARD_MATH_UNARY(std::complex&lt;double&gt;, cosh)
	CPPAD_STANDARD_MATH_UNARY(std::complex&lt;double&gt;, exp)
	CPPAD_STANDARD_MATH_UNARY(std::complex&lt;double&gt;, log)
	CPPAD_STANDARD_MATH_UNARY(std::complex&lt;double&gt;, sin)
	CPPAD_STANDARD_MATH_UNARY(std::complex&lt;double&gt;, sinh)
	CPPAD_STANDARD_MATH_UNARY(std::complex&lt;double&gt;, sqrt)
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="Invalid Unary Math" id="Invalid Unary Math">Invalid Unary Math</a></big></b>
<br/>
The following macro definition and invocations define the standard unary 
math functions that are invalid with complex arguments and are
required to use <code><font color="blue">AD&lt; std::complex&lt;double&gt; &gt;</font></code>.
<code><font color='blue'><pre style='display:inline'> 
# undef  CPPAD_USER_MACRO
# define CPPAD_USER_MACRO(Fun)                                     \
inline std::complex&lt;double&gt; Fun(const std::complex&lt;double&gt;&amp; x)     \
{      CppAD::ErrorHandler::Call(                                  \
               true     , __LINE__ , __FILE__ ,                    \
               #Fun&quot;(x)&quot;,                                          \
               &quot;Error: cannot use &quot; #Fun &quot; with x complex&lt;double&gt; &quot; \
       );                                                          \
       return std::complex&lt;double&gt;(0);                             \
}
namespace CppAD {
	CPPAD_USER_MACRO(abs)
	CPPAD_USER_MACRO(acos)
	CPPAD_USER_MACRO(asin)
	CPPAD_USER_MACRO(atan)
	CPPAD_USER_MACRO(sign)
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="pow" id="pow">pow</a></big></b>
<br/>
The following defines a <code><font color="blue">CppAD::pow</font></code> function that
is required to use <code><font color="blue">AD&lt; std::complex&lt;double&gt; &gt;</font></code>:
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	inline std::complex&lt;double&gt; pow(
		const std::complex&lt;double&gt; &amp;x , 
		const std::complex&lt;double&gt; &amp;y )
	{	return std::pow(x, y); }
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="limits" id="limits">limits</a></big></b>
<br/>
The following defines the numeric limits functions
<code><font color="blue">epsilon</font></code>, <code><font color="blue">min</font></code>, and <code><font color="blue">max</font></code> for the type
<code><font color="blue">std::complex&lt;double&gt;</font></code>.
It also defines the deprecated <code><font color="blue">epsilon</font></code> function:
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	template &lt;&gt;
	class numeric_limits&lt; std::complex&lt;double&gt; &gt; {
	public:
		// machine epsilon
		static  std::complex&lt;double&gt; epsilon(void)
		{	double eps = std::numeric_limits&lt;double&gt;::epsilon();
			return std::complex&lt;double&gt;(eps, 0.0);
		}
		// minimum positive normalized value
		static  std::complex&lt;double&gt; min(void)
		{	double min = std::numeric_limits&lt;double&gt;::min();
			return std::complex&lt;double&gt;(min, 0.0);
		}
		// maximum finite value
		static  std::complex&lt;double&gt; max(void)
		{	double max = std::numeric_limits&lt;double&gt;::max();
			return std::complex&lt;double&gt;(max, 0.0);
		}
	};
	// deprecated machine epsilon
	template &lt;&gt; 
	inline std::complex&lt;double&gt; epsilon&lt; std::complex&lt;double&gt; &gt; (void)
	{	return numeric_limits&lt; std::complex&lt;double&gt; &gt;::epsilon(); }
}
</pre></font></code>


<hr/>Input File: cppad/local/base_complex.hpp

</body>
</html>