mirror of https://github.com/mirror/busybox.git
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.1_00_stable_10817
parent
a48b0a3af7
commit
a92877403a
|
@ -280,8 +280,10 @@
|
||||||
"expression ..."
|
"expression ..."
|
||||||
#define dc_full_usage \
|
#define dc_full_usage \
|
||||||
"This is a Tiny RPN calculator that understands the\n" \
|
"This is a Tiny RPN calculator that understands the\n" \
|
||||||
"following operations: +, -, /, *, and, or, not, eor.\n" \
|
"following operations: +, add, -, sub, *, mul, /, div, %, mod, "\
|
||||||
"i.e., 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16" \
|
"**, 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" \
|
"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" \
|
"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" \
|
"o - Pops the value off the top of the stack and uses it to set the output radix.\n" \
|
||||||
|
|
|
@ -44,6 +44,13 @@ static void mul(void)
|
||||||
push(pop() * pop());
|
push(pop() * pop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void power(void)
|
||||||
|
{
|
||||||
|
double topower = pop();
|
||||||
|
|
||||||
|
push(pow(pop(), topower));
|
||||||
|
}
|
||||||
|
|
||||||
static void divide(void)
|
static void divide(void)
|
||||||
{
|
{
|
||||||
double divisor = pop();
|
double divisor = pop();
|
||||||
|
@ -51,6 +58,13 @@ static void divide(void)
|
||||||
push(pop() / divisor);
|
push(pop() / divisor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mod(void)
|
||||||
|
{
|
||||||
|
unsigned int d = pop();
|
||||||
|
|
||||||
|
push((unsigned int) pop() % d);
|
||||||
|
}
|
||||||
|
|
||||||
static void and(void)
|
static void and(void)
|
||||||
{
|
{
|
||||||
push((unsigned int) pop() & (unsigned int) pop());
|
push((unsigned int) pop() & (unsigned int) pop());
|
||||||
|
@ -119,10 +133,16 @@ static const struct op operators[] = {
|
||||||
{"mul", mul},
|
{"mul", mul},
|
||||||
{"/", divide},
|
{"/", divide},
|
||||||
{"div", divide},
|
{"div", divide},
|
||||||
|
{"**", power},
|
||||||
|
{"exp", power},
|
||||||
|
{"pow", power},
|
||||||
|
{"%", mod},
|
||||||
|
{"mod", mod},
|
||||||
{"and", and},
|
{"and", and},
|
||||||
{"or", or},
|
{"or", or},
|
||||||
{"not", not},
|
{"not", not},
|
||||||
{"eor", eor},
|
{"eor", eor},
|
||||||
|
{"xor", eor},
|
||||||
{"p", print_no_pop},
|
{"p", print_no_pop},
|
||||||
{"f", print_stack_no_pop},
|
{"f", print_stack_no_pop},
|
||||||
{"o", set_output_base},
|
{"o", set_output_base},
|
||||||
|
|
Loading…
Reference in New Issue