summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-15 07:53:49 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-15 07:53:49 -0800
commit9ddfef0aa6718731db7823c20c5ff21be4311197 (patch)
treedaab6391b211d18ec52cad30cd70c3605f38ec20
parent4a2d84b3dcfed6226b95c4cc32dd3d58bc848868 (diff)
downloadtxr-9ddfef0aa6718731db7823c20c5ff21be4311197.tar.gz
txr-9ddfef0aa6718731db7823c20c5ff21be4311197.tar.bz2
txr-9ddfef0aa6718731db7823c20c5ff21be4311197.zip
* arith.c (atang2): New function.
* eval.c (eval_init): Register as atang2 as a atan2 intrinsic. * lib.h (atang2): Declared. * txr.1: Documented atan2.
-rw-r--r--arith.c6
-rw-r--r--eval.c1
-rw-r--r--lib.h1
-rw-r--r--txr.16
4 files changed, 12 insertions, 2 deletions
diff --git a/arith.c b/arith.c
index e4972209..09828f59 100644
--- a/arith.c
+++ b/arith.c
@@ -1431,6 +1431,12 @@ val atang(val num)
return flo(atan(c_flo(to_float(lit("atan"), num))));
}
+val atang2(val y, val x)
+{
+ return flo(atan2(c_flo(to_float(lit("atan2"), y)),
+ c_flo(to_float(lit("atan2"), x))));
+}
+
val loga(val num)
{
return flo(log(c_flo(to_float(lit("log"), num))));
diff --git a/eval.c b/eval.c
index ce610dd1..6bb4b5d9 100644
--- a/eval.c
+++ b/eval.c
@@ -2361,6 +2361,7 @@ void eval_init(void)
reg_fun(intern(lit("asin"), user_package), func_n1(asine));
reg_fun(intern(lit("acos"), user_package), func_n1(acosi));
reg_fun(intern(lit("atan"), user_package), func_n1(atang));
+ reg_fun(intern(lit("atan2"), user_package), func_n2(atang2));
reg_fun(intern(lit("log"), user_package), func_n1(loga));
reg_fun(intern(lit("exp"), user_package), func_n1(expo));
reg_fun(intern(lit("sqrt"), user_package), func_n1(sqroot));
diff --git a/lib.h b/lib.h
index f4558bf2..d5158b64 100644
--- a/lib.h
+++ b/lib.h
@@ -479,6 +479,7 @@ val tang(val);
val asine(val);
val acosi(val);
val atang(val);
+val atang2(val, val);
val loga(val);
val expo(val);
val logand(val, val);
diff --git a/txr.1 b/txr.1
index df8ef0dd..42255176 100644
--- a/txr.1
+++ b/txr.1
@@ -8895,7 +8895,7 @@ If <number> an integer, it is simply returned.
If the argument is a float, then the value returned is a float.
For instance (floor 1.1) returns 1.0 rather than 1.
-.SS Functions sin, cos, tan, asin, acos, atan
+.SS Functions sin, cos, tan, asin, acos, atan, atan2
.TP
Syntax:
@@ -8904,6 +8904,7 @@ Syntax:
(cos <radians>)
(tan <radians>)
(atan <slope>)
+ (atan2 <y> <x>)
(asin <num>)
(acos <num>)
@@ -8915,7 +8916,8 @@ return a float result. The sin, cos and tan functions compute the sine and
cosine and tangent of the <radians> argument which represents an angle
expressed in radians. The atan, acos and asin are their respective inverse
functions. The <num> argument to asin and acos must be in the
-range -1.0 to 1.0.
+range -1.0 to 1.0. The atan2 function converts the rectilinear coordinates
+<x> and <y> to an angle in polar coordinates in the range [0, 2pi).
.SS Functions log, exp