aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usage.h6
-rw-r--r--miscutils/dc.c20
2 files changed, 24 insertions, 2 deletions
diff --git a/include/usage.h b/include/usage.h
index 851023ea5..268c23cac 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -280,8 +280,10 @@
"expression ..."
#define dc_full_usage \
"This is a Tiny RPN calculator that understands the\n" \
- "following operations: +, -, /, *, and, or, not, eor.\n" \
- "i.e., 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16" \
+ "following operations: +, add, -, sub, *, mul, /, div, %, mod, "\
+ "**, exp, and, or, not, eor.\n" \
+ "For example: 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16.\n" \
+ "\nOptions:\n" \
"p - Prints the value on the top of the stack, without altering the stack.\n" \
"f - Prints the entire contents of the stack without altering anything.\n" \
"o - Pops the value off the top of the stack and uses it to set the output radix.\n" \
diff --git a/miscutils/dc.c b/miscutils/dc.c
index 451423c62..f574ae4a0 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},