summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-29 15:57:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-29 15:57:45 -0700
commit2b1e05769d01cb036cf0a82231eb87b698a33426 (patch)
treed072354049911ec058a01b9cc69f41e2ca2ebe2d /arith.c
parent9e60a829fdd3874f510ebc57d1a378d020a55fb9 (diff)
downloadtxr-2b1e05769d01cb036cf0a82231eb87b698a33426.tar.gz
txr-2b1e05769d01cb036cf0a82231eb87b698a33426.tar.bz2
txr-2b1e05769d01cb036cf0a82231eb87b698a33426.zip
* arith.c (gcd): Allow zeros. Don't issue "non-integral"
exception if MPI fails. (floorf, ceili): Map integer argument to itself. (tang, asine, acosi): New functions. * eval.c (eval_init): New intrinsics: tan, asin, acos. * lib.h (tang, asine, acosi): Declared. * txr.1: Documented gcd, abs, floor, ceil, sin, cos, tan asin, acos, atan, log, and exp. * txr.vim: Highlighting for tang, asine, acosi.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/arith.c b/arith.c
index a8cfb578..208a06a1 100644
--- a/arith.c
+++ b/arith.c
@@ -1283,6 +1283,9 @@ val gcd(val anum, val bnum)
if (!integerp(anum) || !integerp(bnum))
goto inval;
+ if (zerop(anum))
+ return zero;
+
if (fixnump(anum))
anum = bignum(c_num(anum));
@@ -1292,21 +1295,28 @@ val gcd(val anum, val bnum)
n = make_bignum();
if (mp_gcd(mp(anum), mp(bnum), mp(n)) != MP_OKAY)
- goto inval;
+ goto bad;
return n;
inval:
uw_throwf(error_s, lit("gcd: non-integral operands ~s ~s"),
anum, bnum, nao);
+bad:
+ uw_throwf(error_s, lit("gcd: operation failed on ~s ~s"),
+ anum, bnum, nao);
}
val floorf(val num)
{
+ if (integerp(num))
+ return num;
return flo(floor(c_flo(to_float(lit("floor"), num))));
}
val ceili(val num)
{
+ if (integerp(num))
+ return num;
return flo(ceil(c_flo(to_float(lit("ceil"), num))));
}
@@ -1320,6 +1330,21 @@ val cosi(val num)
return flo(cos(c_flo(to_float(lit("cos"), num))));
}
+val tang(val num)
+{
+ return flo(tan(c_flo(to_float(lit("tan"), num))));
+}
+
+val asine(val num)
+{
+ return flo(asin(c_flo(to_float(lit("asin"), num))));
+}
+
+val acosi(val num)
+{
+ return flo(acos(c_flo(to_float(lit("acos"), num))));
+}
+
val atang(val num)
{
return flo(atan(c_flo(to_float(lit("atan"), num))));