[pure-lang-svn] SF.net SVN: pure-lang:[576] pure/trunk/lib/math.pure
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-23 10:27:25
|
Revision: 576
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=576&view=rev
Author: agraef
Date: 2008-08-23 10:27:31 +0000 (Sat, 23 Aug 2008)
Log Message:
-----------
Fix broken complex sqrt, minor cosmetic changes in complex trig and hyperbolic functions.
Modified Paths:
--------------
pure/trunk/lib/math.pure
Modified: pure/trunk/lib/math.pure
===================================================================
--- pure/trunk/lib/math.pure 2008-08-22 20:24:48 UTC (rev 575)
+++ pure/trunk/lib/math.pure 2008-08-23 10:27:31 UTC (rev 576)
@@ -183,8 +183,8 @@
/* Complex sqrt. */
-sqrt (x+:y) = sqrt ((r+x)/2) +: sqrt ((r-x)/2)
- when r = sqrt (x*x+y*y) end;
+sqrt (x+:y) = sqrt r*(cos t +: sin t)
+ when r = sqrt (x*x+y*y); t = atan2 y x/2 end;
sqrt (r<:t) = sqrt r <: t/2;
/* Complex exponential and logarithms. */
@@ -215,9 +215,7 @@
acos z@(x+:y) |
acos z@(r<:t) = -i*ln (z+sqrt (z*z-1));
atan z@(x+:y) |
-atan z@(r<:t) = 0.0 +: inf if z==i;
- = 0.0 +: -inf if z==-i;
- = -i*0.5*ln ((1+i*z)/(1-i*z));
+atan z@(r<:t) = (ln (1+i*z)-ln (1-i*z))/(2*i);
/* Complex hyperbolic functions. */
@@ -233,10 +231,11 @@
asinh z@(r<:t) = ln (z+sqrt (z*z+1));
acosh z@(x+:y) |
acosh z@(r<:t) = ln (z+sqrt (z*z-1));
+// Alternative definition (Kahan).
+// acosh z@(x+:y) |
+// acosh z@(r<:t) = 2*ln (sqrt ((z+1)/2)+sqrt ((z-1)/2));
atanh z@(x+:y) |
-atanh z@(r<:t) = inf +: 0.0 if z==1;
- = -inf +: 0.0 if z==-1;
- = ln ((1+z)/(1-z))/2;
+atanh z@(r<:t) = (ln (1+z)-ln (1-z))/2;
/* Complex arithmetic. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|