IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4305


Ignore:
Timestamp:
Jun 17, 2005, 12:20:48 PM (21 years ago)
Author:
eugene
Message:

added erf to stack_math, fixed up precedence order

Location:
trunk/Ohana/src/opihi
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r3414 r4305  
    2323    type = 0;
    2424    /* unary operations */
    25     if (!strcmp (argv[i], "abs"))   { type = 7; goto gotit; }
    26     if (!strcmp (argv[i], "int"))   { type = 7; goto gotit; }
    27     if (!strcmp (argv[i], "exp"))   { type = 7; goto gotit; }
    28     if (!strcmp (argv[i], "ten"))   { type = 7; goto gotit; }
    29     if (!strcmp (argv[i], "log"))   { type = 7; goto gotit; }
    30     if (!strcmp (argv[i], "ln"))    { type = 7; goto gotit; }
    31     if (!strcmp (argv[i], "sqrt"))  { type = 7; goto gotit; }
     25    if (!strcmp (argv[i], "abs"))    { type = 7; goto gotit; }
     26    if (!strcmp (argv[i], "int"))    { type = 7; goto gotit; }
     27    if (!strcmp (argv[i], "exp"))    { type = 7; goto gotit; }
     28    if (!strcmp (argv[i], "ten"))    { type = 7; goto gotit; }
     29    if (!strcmp (argv[i], "log"))    { type = 7; goto gotit; }
     30    if (!strcmp (argv[i], "ln"))     { type = 7; goto gotit; }
     31    if (!strcmp (argv[i], "sqrt"))   { type = 7; goto gotit; }
     32    if (!strcmp (argv[i], "erf"))    { type = 7; goto gotit; }
    3233
    3334    if (!strcmp (argv[i], "sinh"))   { type = 7; goto gotit; }
     
    3637    if (!strcmp (argv[i], "acosh"))  { type = 7; goto gotit; }
    3738
    38     if (!strcmp (argv[i], "sin"))   { type = 7; goto gotit; }
    39     if (!strcmp (argv[i], "cos"))   { type = 7; goto gotit; }
    40     if (!strcmp (argv[i], "tan"))   { type = 7; goto gotit; }
    41     if (!strcmp (argv[i], "dsin"))  { type = 7; goto gotit; }
    42     if (!strcmp (argv[i], "dcos"))  { type = 7; goto gotit; }
    43     if (!strcmp (argv[i], "dtan"))  { type = 7; goto gotit; }
    44     if (!strcmp (argv[i], "asin"))  { type = 7; goto gotit; }
    45     if (!strcmp (argv[i], "acos"))  { type = 7; goto gotit; }
    46     if (!strcmp (argv[i], "atan"))  { type = 7; goto gotit; }
    47     if (!strcmp (argv[i], "dasin")) { type = 7; goto gotit; }
    48     if (!strcmp (argv[i], "dacos")) { type = 7; goto gotit; }
    49     if (!strcmp (argv[i], "datan")) { type = 7; goto gotit; }
     39    if (!strcmp (argv[i], "sin"))    { type = 7; goto gotit; }
     40    if (!strcmp (argv[i], "cos"))    { type = 7; goto gotit; }
     41    if (!strcmp (argv[i], "tan"))    { type = 7; goto gotit; }
     42    if (!strcmp (argv[i], "dsin"))   { type = 7; goto gotit; }
     43    if (!strcmp (argv[i], "dcos"))   { type = 7; goto gotit; }
     44    if (!strcmp (argv[i], "dtan"))   { type = 7; goto gotit; }
     45    if (!strcmp (argv[i], "asin"))   { type = 7; goto gotit; }
     46    if (!strcmp (argv[i], "acos"))   { type = 7; goto gotit; }
     47    if (!strcmp (argv[i], "atan"))   { type = 7; goto gotit; }
     48    if (!strcmp (argv[i], "dasin"))  { type = 7; goto gotit; }
     49    if (!strcmp (argv[i], "dacos"))  { type = 7; goto gotit; }
     50    if (!strcmp (argv[i], "datan"))  { type = 7; goto gotit; }
    5051
    5152    if (!strcmp (argv[i], "lgamma")) { type = 7; goto gotit; }
    5253
    53     if (!strcmp (argv[i], "rnd"))   { type = 7; goto gotit; }
    54     if (!strcmp (argv[i], "xramp")) { type = 7; goto gotit; }
    55     if (!strcmp (argv[i], "yramp")) { type = 7; goto gotit; }
    56     if (!strcmp (argv[i], "ramp"))  { type = 7; goto gotit; }
    57     if (!strcmp (argv[i], "zero"))  { type = 7; goto gotit; }
    58     if (!strcmp (argv[i], "--"))    { type = 7; goto gotit; }
    59     if (!strcmp (argv[i], "not"))   { type = 7; goto gotit; }
    60     if (!strcmp (argv[i], "isinf")) { type = 7; goto gotit; }
    61     if (!strcmp (argv[i], "isnan")) { type = 7; goto gotit; }
     54    if (!strcmp (argv[i], "rnd"))    { type = 7; goto gotit; }
     55    if (!strcmp (argv[i], "xramp"))  { type = 7; goto gotit; }
     56    if (!strcmp (argv[i], "yramp"))  { type = 7; goto gotit; }
     57    if (!strcmp (argv[i], "ramp"))   { type = 7; goto gotit; }
     58    if (!strcmp (argv[i], "zero"))   { type = 7; goto gotit; }
     59    if (!strcmp (argv[i], "--"))     { type = 7; goto gotit; }
     60    if (!strcmp (argv[i], "not"))    { type = 7; goto gotit; }
     61    if (!strcmp (argv[i], "isinf"))  { type = 7; goto gotit; }
     62    if (!strcmp (argv[i], "isnan"))  { type = 7; goto gotit; }
    6263
    6364    /* binary operations */
    64     if (!strcmp (argv[i], "^"))     { type = 6; goto gotit; }
    65     if (!strcmp (argv[i], "@"))     { type = 5; goto gotit; }
    66 
    67     if (!strcmp (argv[i], "<"))     { type = 5; goto gotit; }
    68     if (!strcmp (argv[i], ">"))     { type = 5; goto gotit; }
    69     if (!strcmp (argv[i], "&&"))    { type = 5; strcpy (argv[i], "A"); goto gotit; }
    70     if (!strcmp (argv[i], "||"))    { type = 5; strcpy (argv[i], "O"); goto gotit; }
    71     if (!strcmp (argv[i], "=="))    { type = 5; strcpy (argv[i], "E"); goto gotit; }
    72     if (!strcmp (argv[i], "!="))    { type = 5; strcpy (argv[i], "N"); goto gotit; }
    73     if (!strcmp (argv[i], "<="))    { type = 5; strcpy (argv[i], "L"); goto gotit; }
    74     if (!strcmp (argv[i], ">="))    { type = 5; strcpy (argv[i], "G"); goto gotit; }
    75     if (!strcmp (argv[i], ">>"))    { type = 5; strcpy (argv[i], "U"); goto gotit; }
    76     if (!strcmp (argv[i], "<<"))    { type = 5; strcpy (argv[i], "D"); goto gotit; }
    77 
    78     if (!strcmp (argv[i], "&"))     { type = 5; goto gotit; }
    79     if (!strcmp (argv[i], "|"))     { type = 5; goto gotit; }
    80 
    81     if (!strcmp (argv[i], "/"))     { type = 4; goto gotit; }
    82     if (!strcmp (argv[i], "*"))     { type = 4; goto gotit; }
    83 
    84     if (!strcmp (argv[i], "+"))     { type = 3; goto gotit; }
    85     if (!strcmp (argv[i], "-"))     { type = 3; goto gotit; }
     65    if (!strcmp (argv[i], "^"))      { type = 6; goto gotit; }
     66
     67    if (!strcmp (argv[i], "@"))      { type = 5; goto gotit; }
     68    if (!strcmp (argv[i], "/"))      { type = 5; goto gotit; }
     69    if (!strcmp (argv[i], "*"))      { type = 5; goto gotit; }
     70
     71    if (!strcmp (argv[i], "+"))      { type = 4; goto gotit; }
     72    if (!strcmp (argv[i], "-"))      { type = 4; goto gotit; }
    8673       
    87     if (!strcmp (argv[i], "("))     { type = 2; goto gotit; }
    88     if (!strcmp (argv[i], ")"))     { type = 1; goto gotit; }
     74    if (!strcmp (argv[i], "<"))      { type = 3; goto gotit; }
     75    if (!strcmp (argv[i], ">"))      { type = 3; goto gotit; }
     76    if (!strcmp (argv[i], "&&"))     { type = 3; strcpy (argv[i], "A"); goto gotit; }
     77    if (!strcmp (argv[i], "||"))     { type = 3; strcpy (argv[i], "O"); goto gotit; }
     78    if (!strcmp (argv[i], "=="))     { type = 3; strcpy (argv[i], "E"); goto gotit; }
     79    if (!strcmp (argv[i], "!="))     { type = 3; strcpy (argv[i], "N"); goto gotit; }
     80    if (!strcmp (argv[i], "<="))     { type = 3; strcpy (argv[i], "L"); goto gotit; }
     81    if (!strcmp (argv[i], ">="))     { type = 3; strcpy (argv[i], "G"); goto gotit; }
     82    if (!strcmp (argv[i], ">>"))     { type = 3; strcpy (argv[i], "U"); goto gotit; }
     83    if (!strcmp (argv[i], "<<"))     { type = 3; strcpy (argv[i], "D"); goto gotit; }
     84    if (!strcmp (argv[i], "&"))      { type = 3; goto gotit; }
     85    if (!strcmp (argv[i], "|"))      { type = 3; goto gotit; }
     86
     87    if (!strcmp (argv[i], "("))      { type = 2; goto gotit; }
     88    if (!strcmp (argv[i], ")"))      { type = 1; goto gotit; }
    8989
    9090  gotit:
    9191    /* choose how to deal with object */
    9292    switch (type) {
    93     case 6:  /* unary OPs */
     93    case 6:  /* exponentiation */
    9494      /* pop previous, higher operators from OP stack to stack */
    9595      for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) {
     
    104104      Nop_stack ++;
    105105      break;
    106     case 7: /* binary OPs */
     106    case 7: /* unary OPs */
    107107    case 5: /* binary OPs */
    108108    case 4:
  • trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r3318 r4305  
    7575      TWO_OP ("S","W",WW_binary);     
    7676     
    77       /*
    78       if (!strncasecmp (&stack[i - 2].type, "V", 1) && !strncasecmp (&stack[i - 1].type, "V", 1))
    79         status = VV_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    80       if (!strncasecmp (&stack[i - 2].type, "V", 1) && !strncasecmp (&stack[i - 1].type, "S", 1))
    81         status = VS_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    82       if (!strncasecmp (&stack[i - 2].type, "S", 1) && !strncasecmp (&stack[i - 1].type, "V", 1))
    83         status = SV_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    84       if (!strncasecmp (&stack[i - 2].type, "M", 1) && !strncasecmp (&stack[i - 1].type, "V", 1))
    85         status = MV_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    86       if (!strncasecmp (&stack[i - 2].type, "V", 1) && !strncasecmp (&stack[i - 1].type, "M", 1))
    87         status = VM_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    88       if (!strncasecmp (&stack[i - 2].type, "M", 1) && !strncasecmp (&stack[i - 1].type, "M", 1))
    89         status = MM_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    90       if (!strncasecmp (&stack[i - 2].type, "M", 1) && !strncasecmp (&stack[i - 1].type, "S", 1))
    91         status = MS_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    92       if (!strncasecmp (&stack[i - 2].type, "S", 1) && !strncasecmp (&stack[i - 1].type, "M", 1))
    93         status = SM_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    94       if (!strncasecmp (&stack[i - 2].type, "S", 1) && !strncasecmp (&stack[i - 1].type, "S", 1))
    95         status = SS_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    96       if (!strncasecmp (&stack[i - 2].type, "X", 1) && !strncasecmp (&stack[i - 1].type, "X", 1))
    97         status = XX_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    98       */
    99 
    100       /* string op number is not valid
    101       if (!strncasecmp (&stack[i - 2].type, "W", 1) && strncasecmp (&stack[i - 1].type, "W", 1)) {
    102         free (tmp_stack.name);
    103         return (FALSE);
    104       }
    105       if (strncasecmp (&stack[i - 2].type, "W", 1) && !strncasecmp (&stack[i - 1].type, "W", 1)) {
    106         free (tmp_stack.name);
    107         return (FALSE);
    108       } */
    109 
    11077      if (!status) {
    11178        free (tmp_stack.name);
  • trunk/Ohana/src/opihi/lib.shell/stack_math.c

    r3318 r4305  
    11661166  if (!strcmp (op, "ln"))    {    *out = log (*M1);           }
    11671167  if (!strcmp (op, "sqrt"))  {    *out = sqrt (*M1);          }
     1168  if (!strcmp (op, "erf"))   {    *out = erf (*M1);           }
    11681169
    11691170  if (!strcmp (op, "sinh"))  {    *out = sinh (*M1);          }
     
    12231224  if (!strcmp (op, "ln"))    { for (i = 0; i < Nx; i++, out++, M1++) { *out = log(*M1);          }}
    12241225  if (!strcmp (op, "sqrt"))  { for (i = 0; i < Nx; i++, out++, M1++) { *out = sqrt(*M1);         }}
     1226  if (!strcmp (op, "erf"))   { for (i = 0; i < Nx; i++, out++, M1++) { *out = erf(*M1);          }}
    12251227
    12261228  if (!strcmp (op, "sinh"))   { for (i = 0; i < Nx; i++, out++, M1++) { *out = sinh(*M1);        }}
     
    12891291  if (!strcmp (op, "ln"))    { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = log(*M1);          }}
    12901292  if (!strcmp (op, "sqrt"))  { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = sqrt(*M1);         }}
     1293  if (!strcmp (op, "erf"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = erf(*M1);          }}
    12911294
    12921295  if (!strcmp (op, "sinh"))  { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = sinh(*M1);         }}
  • trunk/Ohana/src/opihi/scripts/test.pro

    r3689 r4305  
     1
     2macro testgauss
     3 create x -20 20 0.1
     4 set dy = zero(x) + 0.03
     5 set X = x - $1
     6 set y = $3*exp(-0.5*(X^2/$2^2)) + $4 + 0.1*(rnd(X) - 0.5)
     7# set y = $3*exp(-0.5*(X^2/$2^2)) + $4
     8 lim x y; clear; box; plot x y -dy dy -x 2 -pt 2
     9
     10 $C0 = $1+5
     11 $C1 = $2-10
     12 $C2 = $3
     13 $C3 = $4
     14
     15 vgauss x y dy yf
     16end
     17
     18macro testpoor
     19 create x -20 20 0.1
     20 set dy = zero(x) + 0.03
     21 set X = x - $1
     22 set y = 3 + zero(x) + 0.1*(rnd(X) - 0.5)
     23# set y = (x + 20)/10 + $4 + 0.1*(rnd(X) - 0.5)
     24# set y = $3*exp(-0.5*(X^2/$2^2)) + $4
     25 lim x y; clear; box; plot x y -dy dy -x 2 -pt 2
     26
     27 $C0 = $1
     28 $C1 = $2
     29 $C2 = $3
     30 $C3 = $4
     31
     32 vgauss x y dy yf
     33end
    134
    235macro testfit
Note: See TracChangeset for help on using the changeset viewer.