[pure-lang-svn] SF.net SVN: pure-lang: [350] pure/trunk/lib/math.pure
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-07-01 13:18:56
|
Revision: 350 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=350&view=rev Author: agraef Date: 2008-07-01 06:19:05 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Overhaul of complex powers. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-01 11:22:42 UTC (rev 349) +++ pure/trunk/lib/math.pure 2008-07-01 13:19:05 UTC (rev 350) @@ -279,16 +279,6 @@ (x1+:y1) / (x2+:y2) = (x1*x2+y1*y2 +: y1*x2-x1*y2) / (x2*x2+y2*y2); (r1<:t1) / (r2<:t2) = r1/r2 <: t1-t2; -z1@(x1+:y1)^z2@(x2+:y2) = exp (ln z1*z2) if z1!=0; - = 0.0+:0.0 if z2!=0; - = 1.0+:0.0 otherwise; -z1@(r1<:t1)^z2@(r2<:t2) = exp (ln z1*z2) if z1!=0; - = 0.0<:0.0 if z2!=0; - = 1.0<:0.0 otherwise; - -// Complex powers of negative reals. -x1::double^x2::double = exp (ln x1*x2) if x1<0; - /* Mixed rect/polar and polar/rect forms always return a rect result. */ z1@(x1+:y1)+z2@(r2<:t2) = z1 + rect z2; @@ -303,9 +293,6 @@ z1@(x1+:y1)/z2@(r2<:t2) = z1 / rect z2; z1@(r1<:t1)/z2@(x2+:y2) = rect z1 / z2; -z1@(x1+:y1)^z2@(r2<:t2) = z1 ^ rect z2; -z1@(r1<:t1)^z2@(x2+:y2) = rect z1 ^ z2; - /* Mixed complex/real and real/complex forms yield a rect or polar result, depending on what the complex input was. */ @@ -329,11 +316,24 @@ (r1<:t1)/x2 = r1/x2 <: t1; x1/(r2<:t2) = x1/r2 <: -t2; +/* Complex powers. */ + +// These are computed most easily if the 1st operand is in polar form. +// FIXME: Deal with special cases like 0^0. These always give nan now. +z1@(x1+:y1)^z2@(x2+:y2) = polar z1^z2; +z1@(x1+:y1)^z2@(r2<:t2) = polar z1^rect z2; +(r1<:t1)^z2@(x2+:y2) | +(r1<:t1)^z2@(r2<:t2) = exp (ln r1*z2)*exp((0+:t1)*z2); + +// Mixed complex/real cases. z1@(x1+:y1)^x2 = z1 ^ (x2+:0); x1^z2@(x2+:y2) = (x1+:0) ^ z2; (r1<:t1)^x2 = r1^x2 <: t1*x2; x1^z2@(r2<:t2) = (x1<:0) ^ z2; +// Complex powers of negative reals. +x1::double^x2::double = exp (ln x1*x2) if x1<0; + /* Equality. */ (x1+:y1) == (x2+:y2) = x1==x2 && y1==y2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |