Commit fc914b17 authored by Juergen Nickelsen's avatar Juergen Nickelsen

Btruncate; isqrt now in Lisp

parent 40049148
......@@ -25,6 +25,11 @@ sub Bbindings_depth {
return bindings_depth();
}
sub Btruncate {
my ($number) = checkargs($_[0], 'n');
return int($number);
}
sub Bshell {
my ($command, $return_output) = checkargs($_[0], 'S:e');
my $result;
......@@ -58,11 +63,6 @@ sub Bsqrt {
return sqrt($arg);
}
sub Bisqrt {
my ($arg) = checkargs($_[0], 'n');
return int(sqrt($arg));
}
sub Bsplit_string {
my ($string, $sep, $nonulls) = checkargs($_[0], 'S:ee');
my $re;
......@@ -844,6 +844,8 @@ sub Btype_of {
my @builtins = # [name, func, is_special, doc]
(
["truncate", \&Btruncate, 0,
"return NUMBER truncated to integer towards zero"],
["div", \&Bdiv, 0, "integer divide the first arg by all others"],
["let*", \&Blet_star, 1,
"evaluate body with local bindings: (let* ((var value) ...) body)"],
......@@ -962,7 +964,6 @@ my @builtins = # [name, func, is_special, doc]
["split-string", \&Bsplit_string, 0,
"split STRING into parts SEPARATED by SEP and return the list"],
["sqrt", \&Bsqrt, 0, "return the square root of numeric ARG"],
["isqrt", \&Bsqrt, 0, "return the integer square root of numeric ARG"],
["random", \&Brandom, 0,
"return a random number a with 0 <= a < LIMIT (or 1)"],
["read", \&Bread, 0,
......
......@@ -6,6 +6,10 @@
(symbols))
#'string<))
(defun isqrt (num)
"return the integer square root of NUM ARG"
(truncate (sqrt num)))
(defun caar (pair)
"return the car of the car of PAIR"
(car (car pair)))
......
......@@ -6,6 +6,12 @@
* more of alists
* min, max; floor ceiling, round
+ "isqrt", "return the integer square root of numeric ARG"
+ truncate
+ do something sensible with (describe) for functions
+ 031 and read errors
......
(testcmp "truncate positive float" '(truncate (1+ 3.4)) 4)
(testcmp "truncate positive int" '(truncate 3) 3)
(testcmp "truncate negative float" '(truncate -3.4) -3)
(testcmp "truncate negative int" '(truncate -3) -3)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment