⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blitz_3.html

📁 c++经典教材 Blitz++ v0.8
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<P><DT><CODE>log1p()</CODE><DD><A NAME="IDX253"></A>Calculates log(1+x), where x is the parameter. <P><DT><CODE>nearest()</CODE><DD><A NAME="IDX254"></A>Returns the nearest floating-point integer value to theparameter.  If the parameter is exactly halfway between two integer values,an even value is returned. <P><DT><CODE>rint()</CODE><DD><A NAME="IDX255"></A><A NAME="IDX256"></A>Rounds the parameter and returns a floating-point integer value.  Whether<CODE>rint()</CODE> rounds up or down or to the nearest integer depends on thecurrent floating-point rounding mode.  If you haven't altered the roundingmode, <CODE>rint()</CODE> should be equivalent to <CODE>nearest()</CODE>.  If roundingmode is set to round towards +INF, <CODE>rint()</CODE> is equivalent to<CODE>ceil()</CODE>.  If the mode is round toward -INF, <CODE>rint()</CODE> isequivalent to <CODE>floor()</CODE>.  If the mode is round toward zero,<CODE>rint()</CODE> is equivalent to <CODE>trunc()</CODE>. <P><DT><CODE>rsqrt()</CODE><DD><A NAME="IDX257"></A>Reciprocal square root. <P><DT><CODE>uitrunc()</CODE><DD><A NAME="IDX258"></A>Returns the nearest unsigned integer to the parameter in thedirection of zero. <P><DT><CODE>y0()</CODE><DD><A NAME="IDX259"></A>Bessel function of the second kind, order 0. <P><DT><CODE>y1()</CODE><DD><A NAME="IDX260"></A>Bessel function of the second kind, order 1. </DL><P>There may be better descriptions of these functions in yoursystem man pages.</P><P><A NAME="Math functions 2"></A><HR SIZE="6"><A NAME="SEC89"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC88"> &lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC87"> &gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC74"> &lt;&lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC74"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC92"> &gt;&gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.9 Two-argument math functions </H2><!--docid::SEC89::--><P>The math functions described in this section take two arguments.Most combinations of these types may be used as arguments:</P><P><UL><LI>An Array object<LI>An Array expression<LI>An index placeholder<LI>A scalar of type <CODE>float</CODE>, <CODE>double</CODE>, <CODE>long double</CODE>,or <CODE>complex&#60;T&#62;</CODE></UL><P><HR SIZE="6"><A NAME="SEC87"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC89"> &lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC88"> &gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ &gt;&gt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> ANSI C++ math functions  </H3><!--docid::SEC90::--><P>These math functions are available on all platforms, and work forcomplex numbers.</P><P><A NAME="IDX261"></A><A NAME="IDX262"></A></P><P><DL COMPACT><DT><CODE>atan2(x,y)</CODE><DD><A NAME="IDX263"></A>Inverse tangent of (y/x).  The signs of both parametersare used to determine the quadrant of the return value, which is in therange <EM>[-\pi, \pi]</EM>.  Works for <CODE>complex&#60;T&#62;</CODE>. <P><DT><CODE>blitz::polar(r,t)</CODE><DD><A NAME="IDX264"></A>Computes ; i.e. converts polar-form toCartesian form complex numbers.  The <CODE>blitz::</CODE> scope qualifier isneeded to disambiguate the ANSI C++ function template <CODE>polar(T,T)</CODE>.This qualifier will hopefully disappear in a future version.<P><DT><CODE>pow(x,y)</CODE><DD><A NAME="IDX265"></A>Computes x to the exponent y.  Works for <CODE>complex&#60;T&#62;</CODE>. </DL><P><HR SIZE="6"><A NAME="SEC88"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC87"> &lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC92"> &gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ &gt;&gt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> IEEE/System V math functions  </H3><!--docid::SEC91::--><P>See the notes about IEEE/System V math functions in the previous section.None of these functions work for complex numbers.  They will all cast theirarguments to double precision.</P><P><DL COMPACT><DT><CODE>copysign(x,y)</CODE><DD><A NAME="IDX266"></A>Returns the x parameter with the same sign as the y parameter. <P><DT><CODE>drem(x,y)</CODE><DD><A NAME="IDX267"></A><A NAME="IDX268"></A>Computes a floating point remainder.  The return value r is equal to r = x -n * y, where n is equal to <CODE>nearest(x/y)</CODE> (the nearest integer to x/y).The return value will lie in the range [ -y/2, +y/2 ].  If y is zero or x is+INF or -INF, NaNQ is returned.<P><DT><CODE>fmod(x,y)</CODE><DD><A NAME="IDX269"></A><A NAME="IDX270"></A>Computes a floating point modulo remainder.  The return value r is equal tor = x - n * y, where n is selected so that r has the same sign as x andmagnitude less than abs(y).  In order words, if x &#62; 0, r is in the range [0,|y|], and if x &#60; 0, r is in the range [-|y|, 0].<P><DT><CODE>hypot(x,y)</CODE><DD><A NAME="IDX271"></A>Computes so that underflow does not occur and overflow occurs only if thefinal result warrants it. <P><DT><CODE>nextafter(x,y)</CODE><DD><A NAME="IDX272"></A>Returns the next representable number after x in the direction of y. <P><DT><CODE>remainder(x,y)</CODE><DD><A NAME="IDX273"></A>Equivalent to drem(x,y). <P><DT><CODE>scalb(x,y)</CODE><DD><A NAME="IDX274"></A>Calculates. <P><DT><CODE>unordered(x,y)</CODE><DD><A NAME="IDX275"></A>Returns a nonzero value if a floating-point comparison between x and y wouldbe unordered.  Otherwise, it returns zero.</DL><P><A NAME="User et"></A><HR SIZE="6"><A NAME="SEC92"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC88"> &lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC93"> &gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC76"> &lt;&lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC74"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> &gt;&gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.10 Declaring your own math functions on arrays </H2><!--docid::SEC92::--><P><A NAME="IDX276"></A><A NAME="IDX277"></A></P><P>There are four macros which make it easy to turn your own scalar functionsinto functions defined on arrays.  They are:</P><P><A NAME="IDX278"></A></P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>BZ_DECLARE_FUNCTION(f)                   // 1BZ_DECLARE_FUNCTION_RET(f,return_type)   // 2BZ_DECLARE_FUNCTION2(f)                  // 3BZ_DECLARE_FUNCTION2_RET(f,return_type)  // 4</pre></td></tr></table></P><P>Use version 1 when you have a function which takes one argument and returnsa result of the same type.  For example:</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>#include &#60;blitz/array.h&#62;using namespace blitz;double myFunction(double x){     return 1.0 / (1 + x); }BZ_DECLARE_FUNCTION(myFunction)int main(){    Array&#60;double,2&#62; A(4,4), B(4,4);  // ...    B = myFunction(A);}</pre></td></tr></table></P><P>Use version 2 when you have a one argument function whose return type isdifferent than the argument type, such as</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>int g(double x);</pre></td></tr></table></P><P>Use version 3 for a function which takes two arguments and returns a resultof the same type, such as:</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>double g(double x, double y);</pre></td></tr></table></P><P>Use version 4 for a function of two arguments which returns a differenttype, such as:</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>int g(double x, double y);</pre></td></tr></table></P><P><HR SIZE="6"><A NAME="SEC93"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC92"> &lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC94"> &gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC76"> &lt;&lt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC74"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> &gt;&gt; </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.11 Tensor notation </H2><!--docid::SEC93::--><P><A NAME="IDX279"></A><A NAME="IDX280"></A></P><P>Blitz++ arrays support a tensor-like notation.  Here's an example ofreal-world tensor notation:<pre> ijk    ij kA    = B  C</pre></P><P><EM>A</EM> is a rank 3 tensor (a three dimensional array), <EM>B</EM> is a rank2 tensor (a two dimensional array), and <EM>C</EM> is a rank 1 tensor (a onedimensional array).  The above expression sets <CODE>A(i,j,k) = B(i,j) * C(k)</CODE>.</P><P>To implement this product using Blitz++, we'll need the arrays and someindex placeholders:</P><P><A NAME="IDX281"></A></P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>Array&#60;float,3&#62; A(4,4,4);Array&#60;float,2&#62; B(4,4);Array&#60;float,1&#62; C(4);firstIndex i;    // Alternately, could just saysecondIndex j;   // using namespace blitz::tensor;thirdIndex k;</pre></td></tr></table></P><P>Here's the Blitz++ code which is equivalent to the tensor expression:</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>A = B(i,j) * C(k);</pre></td></tr></table></P><P>The index placeholder arguments tell an array how to map its dimensions ontothe dimensions of the destination array.  For example, here's somereal-world tensor notation:<pre> ijk    ij k    jk iC    = A  x  - A  y</pre></P><P>In Blitz++, this would be coded as:</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>using namespace blitz::tensor;C = A(i,j) * x(k) - A(j,k) * y(i);</pre></td></tr></table></P><P>This tensor expression can be visualized in the following way:</P><P><center> <CENTER><IMG SRC="tensor1.gif" ALT="tensor1"></CENTER></center><center> Examples of array indexing, subarrays, and slicing.</center></P><P>Here's an example which computes an outer product of two one-dimensionalarrays:<A NAME="IDX282"></A><A NAME="IDX283"></A><A NAME="IDX284"></A></P><P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -