Patch from David Meggy to make the swap default to the new version if no
[oweals/busybox.git] / miscutils / dc.c
index 5e367fe6889a3ebbb0f8b67b632b77226833a6b3..f574ae4a0f6c16c8105dc9311b7d37fbf8c204d6 100644 (file)
@@ -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},
@@ -168,7 +188,7 @@ static char *get_token(char **buffer)
        while (isspace(*current)) { current++; }
        if (*current != 0) {
                start = current;
-               while (!isspace(*current) && current != 0) { current++; }
+               while (!isspace(*current) && *current != 0) { current++; }
                *buffer = current;
        }
        return start;