+static int perform_decimal(int *a, int *b, int *output)
+{
+ int p10;
+
+ /*
+ * Add a decimal digit to the front of a number;
+ * fail if it's not an integer.
+ * So, 1 --> 0.1, 15 --> 0.15,
+ * or, rather, 1 --> 1/10, 15 --> 15/100,
+ * x --> x / (smallest power of 10 > than x)
+ *
+ */
+ if (a[1] != 1) return FALSE;
+
+ if (!max_p10(a[0], &p10)) return FALSE;
+
+ OUT(output, a[0], p10);
+ return TRUE;
+}
+
+static int perform_recur(int *a, int *b, int *output)
+{
+ int p10, tn, bn;
+
+ /*
+ * This converts a number like .4 to .44444..., or .45 to .45454...
+ * The input number must be -1 < a < 1.
+ *
+ * Calculate the smallest power of 10 that divides the denominator exactly,
+ * returning if no such power of 10 exists. Then multiply the numerator
+ * up accordingly, and the new denominator becomes that power of 10 - 1.
+ */
+ if (abs(a[0]) >= abs(a[1])) return FALSE; /* -1 < a < 1 */
+
+ p10 = 10;
+ while (p10 <= (INT_MAX/10)) {
+ if ((a[1] <= p10) && (p10 % a[1]) == 0) goto found;
+ p10 *= 10;
+ }
+ return FALSE;
+found:
+ tn = a[0] * (p10 / a[1]);
+ bn = p10 - 1;
+
+ OUT(output, tn, bn);
+ return TRUE;
+}
+
+static int perform_root(int *a, int *b, int *output)
+{
+ /*
+ * A root B is: 1 iff a == 0
+ * B ^ (1/A) otherwise
+ */
+ int ainv[2], res;
+
+ if (a[0] == 0) {
+ OUT(output, 1, 1);
+ return TRUE;
+ }
+
+ OUT(ainv, a[1], a[0]);
+ res = perform_exp(b, ainv, output);
+ return res;
+}
+
+static int perform_perc(int *a, int *b, int *output)
+{
+ if (a[0] == 0) return FALSE; /* 0% = 0, uninteresting. */
+ if (a[1] > (INT_MAX/100)) return FALSE;
+
+ OUT(output, a[0], a[1]*100);
+ return TRUE;
+}
+
+static int perform_gamma(int *a, int *b, int *output)
+{
+ int asub1[2];
+
+ /*
+ * gamma(a) = (a-1)!
+ *
+ * special case not caught by perform_fact: gamma(1) is 1 so
+ * don't bother.
+ */
+ if (a[0] == 1 && a[1] == 1) return FALSE;
+
+ OUT(asub1, a[0]-a[1], a[1]);
+ return perform_factorial(asub1, b, output);
+}
+
+static int perform_sqrt(int *a, int *b, int *output)
+{
+ int half[2] = { 1, 2 };
+
+ /*
+ * sqrt(0) == 0, sqrt(1) == 1: don't perform unary noops.
+ */
+ if (a[0] == 0 || (a[0] == 1 && a[1] == 1)) return FALSE;
+
+ return perform_exp(a, half, output);
+}
+