]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/fplot.c
aux/realemu: run cpuproc in same fd group as fileserver
[plan9front.git] / sys / src / cmd / fplot.c
index d09c19efc1bf9473af8907357bbdd1efc77ae066..8fba63a282ac741f3434188d062d028325b46f99 100644 (file)
@@ -45,6 +45,8 @@ struct Token {
 };
 
 double *stack, *sp;
+void omax(void) { sp--; if(sp[1]>*sp) *sp = sp[1]; }
+void omin(void) { sp--; if(sp[1]<*sp) *sp = sp[1]; }
 void add(void) { sp--; *sp += *(sp+1); }
 void sub(void) { sp--; *sp -= *(sp+1); }
 void mul(void) { sp--; *sp *= *(sp+1); }
@@ -69,22 +71,24 @@ struct Operator {
        short prec;
        void (*f)(void);
 } ops[] = {
-       "+",    OBINARY,        0,      0,      add,
-       "-",    OBINARY,        0,      0,      sub,
-       "*",    OBINARY,        0,      100,    mul,
-       "/",    OBINARY,        0,      100,    div,
-       "%",    OBINARY,        0,      100,    mod,
-       "^",    OBINARY,        1,      200,    pot,
-       "sin",  OUNARY,         0,      300,    osin,
-       "cos",  OUNARY,         0,      300,    ocos,
-       "tan",  OUNARY,         0,      300,    otan,
-       "asin", OUNARY,         0,      300,    oasin,
-       "acos", OUNARY,         0,      300,    oacos,
-       "atan", OUNARY,         0,      300,    oatan,
-       "sqrt", OUNARY,         0,      300,    osqrt,
-       "exp",  OUNARY,         0,      300,    oexp,
-       "log",  OUNARY,         0,      300,    olog,
-       "ln",   OUNARY,         0,      300,    oln,
+       "max",  OBINARY,        0,      0,      omax,
+       "min",  OBINARY,        0,      0,      omax,
+       "+",    OBINARY,        0,      100,    add,
+       "-",    OBINARY,        0,      100,    sub,
+       "*",    OBINARY,        0,      200,    mul,
+       "/",    OBINARY,        0,      200,    div,
+       "%",    OBINARY,        0,      200,    mod,
+       "^",    OBINARY,        1,      300,    pot,
+       "sin",  OUNARY,         0,      400,    osin,
+       "cos",  OUNARY,         0,      400,    ocos,
+       "tan",  OUNARY,         0,      400,    otan,
+       "asin", OUNARY,         0,      400,    oasin,
+       "acos", OUNARY,         0,      400,    oacos,
+       "atan", OUNARY,         0,      400,    oatan,
+       "sqrt", OUNARY,         0,      400,    osqrt,
+       "exp",  OUNARY,         0,      400,    oexp,
+       "log",  OUNARY,         0,      400,    olog,
+       "ln",   OUNARY,         0,      400,    oln,
 };
 
 struct Constant {
@@ -260,7 +264,7 @@ parse(Code *c, char *s)
                        if(t->op->type == OBINARY)
                                while(opstackbot != nil && opstackbot->type == TOP &&
                                        (opstackbot->op->prec > t->op->prec ||
-                                       t->op->rassoc && opstackbot->op->prec == t->op->prec))
+                                       !t->op->rassoc && opstackbot->op->prec == t->op->prec))
                                        pop(c);
                        push(t);
                        break;