167 lines
14 KiB
Plaintext
167 lines
14 KiB
Plaintext
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="generator" content="TempleOS V5.03">
|
||
|
<meta name="viewport" content="width=device-width">
|
||
|
<link rel="stylesheet" href="/style/templeos.css">
|
||
|
<script src="/script/templeos.js"></script>
|
||
|
<style type="text/css">
|
||
|
.cF0{color:#000000;background-color:#ffffff;}
|
||
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
||
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
||
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
||
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
||
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
||
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
||
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
||
|
.cF8{color:#555555;background-color:#ffffff;}
|
||
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
||
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
||
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
||
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
||
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
||
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
||
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<pre id="content">
|
||
|
<a name="l1"></a><span class=cF0>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>"Math"</span><span class=cF0>
|
||
|
<a name="l2"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>R2P</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> *_mag=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>F64</span><span class=cF0> *_arg=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>F64</span><span class=cF0> x,</span><span class=cF1>F64</span><span class=cF0> y)
|
||
|
<a name="l3"></a>{</span><span class=cF2>//Rect to polar</span><span class=cF0>
|
||
|
<a name="l4"></a></span><span class=cF2>//Returns angle in range (-pi,pi]</span><span class=cF0>
|
||
|
<a name="l5"></a> </span><span class=cF1>if</span><span class=cF0> (_arg)
|
||
|
<a name="l6"></a> *_arg=</span><span class=cF5>Arg</span><span class=cF0>(x,y);
|
||
|
<a name="l7"></a> </span><span class=cF1>if</span><span class=cF0> (_mag)
|
||
|
<a name="l8"></a> *_mag=</span><span class=cF5>Sqrt</span><span class=cF0>(x*x+y*y);
|
||
|
<a name="l9"></a>}
|
||
|
<a name="l10"></a>
|
||
|
<a name="l11"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>P2R</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> *_x=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>F64</span><span class=cF0> *_y=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>F64</span><span class=cF0> mag,</span><span class=cF1>F64</span><span class=cF0> arg)
|
||
|
<a name="l12"></a>{</span><span class=cF2>//Polar to Rect</span><span class=cF0>
|
||
|
<a name="l13"></a> </span><span class=cF1>if</span><span class=cF0> (_x)
|
||
|
<a name="l14"></a> *_x=mag*</span><span class=cF5>Cos</span><span class=cF0>(arg);
|
||
|
<a name="l15"></a> </span><span class=cF1>if</span><span class=cF0> (_y)
|
||
|
<a name="l16"></a> *_y=mag*</span><span class=cF5>Sin</span><span class=cF0>(arg);
|
||
|
<a name="l17"></a>}
|
||
|
<a name="l18"></a>
|
||
|
<a name="l19"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>Wrap</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> theta,</span><span class=cF1>F64</span><span class=cF0> base=-</span><span class=cF3>pi</span><span class=cF0>)
|
||
|
<a name="l20"></a>{</span><span class=cF2>//Returns angle in range [base,base+2*pi)</span><span class=cF0>
|
||
|
<a name="l21"></a> </span><span class=cF1>F64</span><span class=cF0> res=theta%(2*</span><span class=cF3>pi</span><span class=cF0>);
|
||
|
<a name="l22"></a> </span><span class=cF1>if</span><span class=cF0> (res>=base+2*</span><span class=cF3>pi</span><span class=cF0>)
|
||
|
<a name="l23"></a> res-=2*</span><span class=cF3>pi</span><span class=cF0>;
|
||
|
<a name="l24"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (res<base)
|
||
|
<a name="l25"></a> res+=2*</span><span class=cF3>pi</span><span class=cF0>;
|
||
|
<a name="l26"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
||
|
<a name="l27"></a>}
|
||
|
<a name="l28"></a>
|
||
|
<a name="l29"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DistSqrI64</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> x1,</span><span class=cF9>I64</span><span class=cF0> y1,</span><span class=cF9>I64</span><span class=cF0> x2,</span><span class=cF9>I64</span><span class=cF0> y2)
|
||
|
<a name="l30"></a>{</span><span class=cF2>//Distance-squared between 2 points.</span><span class=cF0>
|
||
|
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> dx=x1-x2,dy=y1-y2;
|
||
|
<a name="l32"></a> </span><span class=cF1>return</span><span class=cF0> dx*dx+dy*dy;
|
||
|
<a name="l33"></a>}
|
||
|
<a name="l34"></a>
|
||
|
<a name="l35"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>ASin</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> s)
|
||
|
<a name="l36"></a>{</span><span class=cF2>//Arc Sin (Inverse Sin).</span><span class=cF0>
|
||
|
<a name="l37"></a> </span><span class=cF1>F64</span><span class=cF0> c;
|
||
|
<a name="l38"></a> c=s*s;
|
||
|
<a name="l39"></a> </span><span class=cF1>if</span><span class=cF0> (c>=1.0)
|
||
|
<a name="l40"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>pi</span><span class=cF0>/2.0;
|
||
|
<a name="l41"></a> c=</span><span class=cF5>Sqrt</span><span class=cF0>(1.0-c);
|
||
|
<a name="l42"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ATan</span><span class=cF0>(s/c);
|
||
|
<a name="l43"></a>}
|
||
|
<a name="l44"></a>
|
||
|
<a name="l45"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>ACos</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> c)
|
||
|
<a name="l46"></a>{</span><span class=cF2>//Arc Cos (Inverse Cos).</span><span class=cF0>
|
||
|
<a name="l47"></a> </span><span class=cF1>F64</span><span class=cF0> s;
|
||
|
<a name="l48"></a> </span><span class=cF1>if</span><span class=cF0> (!c)
|
||
|
<a name="l49"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>pi</span><span class=cF0>/2.0;
|
||
|
<a name="l50"></a> s=c*c;
|
||
|
<a name="l51"></a> </span><span class=cF1>if</span><span class=cF0> (s>=1.0)
|
||
|
<a name="l52"></a> </span><span class=cF1>return</span><span class=cF0> 0.0;
|
||
|
<a name="l53"></a> s=</span><span class=cF5>Sqrt</span><span class=cF0>(1.0-s);
|
||
|
<a name="l54"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ATan</span><span class=cF0>(s/c);
|
||
|
<a name="l55"></a>}
|
||
|
<a name="l56"></a>
|
||
|
<a name="l57"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>Sinh</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> x)
|
||
|
<a name="l58"></a>{</span><span class=cF2>//Hyperbolic Sine.</span><span class=cF0>
|
||
|
<a name="l59"></a> </span><span class=cF1>return</span><span class=cF0> 0.5*(</span><span class=cF5>Exp</span><span class=cF7>(</span><span class=cF0>x</span><span class=cF7>)</span><span class=cF0>-</span><span class=cF5>Exp</span><span class=cF7>(</span><span class=cF0>-x</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l60"></a>}
|
||
|
<a name="l61"></a>
|
||
|
<a name="l62"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>Cosh</span><span class=cF0>(</span><span class=cF1>F64</span><span class=cF0> x)
|
||
|
<a name="l63"></a>{</span><span class=cF2>//Hyperbolic Cosine.</span><span class=cF0>
|
||
|
<a name="l64"></a> </span><span class=cF1>return</span><span class=cF0> 0.5*(</span><span class=cF5>Exp</span><span class=cF7>(</span><span class=cF0>x</span><span class=cF7>)</span><span class=cF0>+</span><span class=cF5>Exp</span><span class=cF7>(</span><span class=cF0>-x</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l65"></a>}
|
||
|
<a name="l66"></a>
|
||
|
<a name="l67"></a>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>"Math/Complex;Data Types/Complex"</span><span class=cF0>
|
||
|
<a name="l68"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CAdd</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *sum,</span><span class=cF9>Complex</span><span class=cF0> *n1,</span><span class=cF9>Complex</span><span class=cF0> *n2)
|
||
|
<a name="l69"></a>{</span><span class=cF2>//sum=n1+n2</span><span class=cF0>
|
||
|
<a name="l70"></a> sum->x=n1->x+n2->x;
|
||
|
<a name="l71"></a> sum->y=n1->y+n2->y;
|
||
|
<a name="l72"></a> </span><span class=cF1>return</span><span class=cF0> sum;
|
||
|
<a name="l73"></a>}
|
||
|
<a name="l74"></a>
|
||
|
<a name="l75"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CSub</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *diff,</span><span class=cF9>Complex</span><span class=cF0> *n1,</span><span class=cF9>Complex</span><span class=cF0> *n2)
|
||
|
<a name="l76"></a>{</span><span class=cF2>//diff=n1-n2</span><span class=cF0>
|
||
|
<a name="l77"></a> diff->x=n1->x-n2->x;
|
||
|
<a name="l78"></a> diff->y=n1->y-n2->y;
|
||
|
<a name="l79"></a> </span><span class=cF1>return</span><span class=cF0> diff;
|
||
|
<a name="l80"></a>}
|
||
|
<a name="l81"></a>
|
||
|
<a name="l82"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CMul</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *prod,</span><span class=cF9>Complex</span><span class=cF0> *n1,</span><span class=cF9>Complex</span><span class=cF0> *n2)
|
||
|
<a name="l83"></a>{</span><span class=cF2>//prod=n1*n2</span><span class=cF0>
|
||
|
<a name="l84"></a> prod->x=n1->x*n2->x-n1->y*n2->y;
|
||
|
<a name="l85"></a> prod->y=n1->x*n2->y+n1->y*n2->x;
|
||
|
<a name="l86"></a> </span><span class=cF1>return</span><span class=cF0> prod;
|
||
|
<a name="l87"></a>}
|
||
|
<a name="l88"></a>
|
||
|
<a name="l89"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CDiv</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *quot,</span><span class=cF9>Complex</span><span class=cF0> *n1,</span><span class=cF9>Complex</span><span class=cF0> *n2)
|
||
|
<a name="l90"></a>{</span><span class=cF2>//quot=n1/n2</span><span class=cF0>
|
||
|
<a name="l91"></a> </span><span class=cF1>F64</span><span class=cF0> m1,arg1,m2,arg2;
|
||
|
<a name="l92"></a> </span><span class=cF5>R2P</span><span class=cF0>(&m1,&arg1,n1->x,n1->y);
|
||
|
<a name="l93"></a> </span><span class=cF5>R2P</span><span class=cF0>(&m2,&arg2,n2->x,n2->y);
|
||
|
<a name="l94"></a> m1/=m2;
|
||
|
<a name="l95"></a> arg1-=arg2;
|
||
|
<a name="l96"></a> quot->x=m1*</span><span class=cF5>Cos</span><span class=cF0>(arg1);
|
||
|
<a name="l97"></a> quot->y=m1*</span><span class=cF5>Sin</span><span class=cF0>(arg1);
|
||
|
<a name="l98"></a> </span><span class=cF1>return</span><span class=cF0> quot;
|
||
|
<a name="l99"></a>}
|
||
|
<a name="l100"></a>
|
||
|
<a name="l101"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CScale</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *dst,</span><span class=cF1>F64</span><span class=cF0> s)
|
||
|
<a name="l102"></a>{</span><span class=cF2>//dst*=s</span><span class=cF0>
|
||
|
<a name="l103"></a> dst->x*=s;
|
||
|
<a name="l104"></a> dst->y*=s;
|
||
|
<a name="l105"></a> </span><span class=cF1>return</span><span class=cF0> dst;
|
||
|
<a name="l106"></a>}
|
||
|
<a name="l107"></a>
|
||
|
<a name="l108"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CCopy</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *dst,</span><span class=cF9>Complex</span><span class=cF0> *src)
|
||
|
<a name="l109"></a>{</span><span class=cF2>//dst=src</span><span class=cF0>
|
||
|
<a name="l110"></a> dst->x=src->x;
|
||
|
<a name="l111"></a> dst->y=src->y;
|
||
|
<a name="l112"></a> </span><span class=cF1>return</span><span class=cF0> dst;
|
||
|
<a name="l113"></a>}
|
||
|
<a name="l114"></a>
|
||
|
<a name="l115"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CEqu</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *dst,</span><span class=cF1>F64</span><span class=cF0> x,</span><span class=cF1>F64</span><span class=cF0> y)
|
||
|
<a name="l116"></a>{</span><span class=cF2>//dst=(x,y)</span><span class=cF0>
|
||
|
<a name="l117"></a> dst->x=x;
|
||
|
<a name="l118"></a> dst->y=y;
|
||
|
<a name="l119"></a> </span><span class=cF1>return</span><span class=cF0> dst;
|
||
|
<a name="l120"></a>}
|
||
|
<a name="l121"></a>
|
||
|
<a name="l122"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>Complex</span><span class=cF0> *</span><span class=cF5>CPoly</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *dst,</span><span class=cF9>I64</span><span class=cF0> n,</span><span class=cF9>Complex</span><span class=cF0> *zeros,</span><span class=cF9>Complex</span><span class=cF0> *x)
|
||
|
<a name="l123"></a>{</span><span class=cF2>//Eval complex polynomial</span><span class=cF0>
|
||
|
<a name="l124"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
||
|
<a name="l125"></a> </span><span class=cF9>Complex</span><span class=cF0> n1,n2;
|
||
|
<a name="l126"></a> </span><span class=cF1>if</span><span class=cF0> (n>0) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l127"></a> </span><span class=cF5>CSub</span><span class=cF0>(dst,x,&zeros[0]);
|
||
|
<a name="l128"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i<n;i++) {
|
||
|
<a name="l129"></a> </span><span class=cF5>CCopy</span><span class=cF0>(&n1,dst);
|
||
|
<a name="l130"></a> </span><span class=cF5>CMul</span><span class=cF0>(dst,&n1,</span><span class=cF5>CSub</span><span class=cF7>(</span><span class=cF0>&n2,x,&zeros[i]</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l131"></a> }
|
||
|
<a name="l132"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l133"></a> </span><span class=cF5>CEqu</span><span class=cF0>(dst,1.0,0.0);
|
||
|
<a name="l134"></a> </span><span class=cF1>return</span><span class=cF0> dst;
|
||
|
<a name="l135"></a>}
|
||
|
</span></pre></body>
|
||
|
</html>
|