summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorEric Andersen2003-10-22 11:24:39 +0000
committerEric Andersen2003-10-22 11:24:39 +0000
commita92877403ac522d17602ae24782b44a99a268539 (patch)
treeb0c182fed4a45640f50a725d8e248aad7effb4b8 /miscutils
parenta48b0a3af71958c1cea6389893371664a47b1a39 (diff)
downloadbusybox-a92877403ac522d17602ae24782b44a99a268539.zip
busybox-a92877403ac522d17602ae24782b44a99a268539.tar.gz
Goetz Bock writes:
Dear list, during my quest do pack busybox into an RPM, I've fixed a small bug (missing \n) in dc's usage. And added two additional operations: mod and exp/power. Feel free to drop them.
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/dc.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c
index 451423c..f574ae4 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -44,6 +44,13 @@ static void mul(void)
push(pop() * pop());
}
+static void power(void)
+{
+ double topower = pop();
+
+ push(pow(pop(), topower));
+}
+
static void divide(void)
{
double divisor = pop();
@@ -51,6 +58,13 @@ static void divide(void)
push(pop() / divisor);
}
+static void mod(void)
+{
+ unsigned int d = pop();
+
+ push((unsigned int) pop() % d);
+}
+
static void and(void)
{
push((unsigned int) pop() & (unsigned int) pop());
@@ -119,10 +133,16 @@ static const struct op operators[] = {
{"mul", mul},
{"/", divide},
{"div", divide},
+ {"**", power},
+ {"exp", power},
+ {"pow", power},
+ {"%", mod},
+ {"mod", mod},
{"and", and},
{"or", or},
{"not", not},
{"eor", eor},
+ {"xor", eor},
{"p", print_no_pop},
{"f", print_stack_no_pop},
{"o", set_output_base},