IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41991


Ignore:
Timestamp:
Jan 19, 2022, 6:39:42 AM (4 years ago)
Author:
eugene
Message:

add unary string-valued scalar functions (isflt, isnan, isword, isnum)

Location:
branches/eam_branches/ipp-20211108/Ohana/src/opihi
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20211108/Ohana/src/opihi/include/dvomath.h

    r41363 r41991  
    124124int           V_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
    125125int           M_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
     126int           W_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
    126127
    127128/* variable handling */
  • branches/eam_branches/ipp-20211108/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r41341 r41991  
    7171    if (!strcmp (argv[i], "isnan"))  { type = ST_UNARY; goto gotit; }
    7272
     73    /* string-valid unary operations */
     74    if (!strcmp (argv[i], "isword")) { type = ST_UNARY; goto gotit; }
     75    if (!strcmp (argv[i], "isnum"))  { type = ST_UNARY; goto gotit; }
     76    if (!strcmp (argv[i], "isint"))  { type = ST_UNARY; goto gotit; }
     77    if (!strcmp (argv[i], "isflt"))  { type = ST_UNARY; goto gotit; }
     78    if (!strcmp (argv[i], "length")) { type = ST_UNARY; goto gotit; }
     79
    7380    /* binary operations */
     81    // NOTE: I archically use the first character of the function name in a switch to identify the operation
     82    // I should re-work this with an enum which defines the operatino
    7483    if (!strcmp (argv[i], "^"))      { type = ST_POWER; goto gotit; }
    7584
  • branches/eam_branches/ipp-20211108/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r41363 r41991  
    124124        THREE_OP (ST_SCALAR_INT,SSS_trinary);
    125125
    126         /* there are no valid unary string operators */
     126        /* there are no valid trinary string operators */
    127127        snprintf (line, 512, "invalid operands for trinary operator %s (mismatch types?)\n(Note that the : in a trinary operation must be protected by spaces)", stack[i].name);
    128128        push_error (line);
     
    260260        ONE_OP (ST_SCALAR_FLT, S_unary);
    261261
    262         /* there are no valid unary string operators */
     262        ONE_OP (ST_STRING, W_unary);
     263
    263264        snprintf (line, 512, "invalid operand for unary operator %s (undefined value?)", stack[i].name);
    264265        push_error (line);
  • branches/eam_branches/ipp-20211108/Ohana/src/opihi/lib.shell/stack_math.c

    r41363 r41991  
    15001500    if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {      \
    15011501      opihi_int M1  = V1[0].IntValue;                                   \
     1502      OUT[0].type = ST_SCALAR_INT;                                      \
     1503      OUT[0].IntValue = OP;                                             \
     1504      clear_stack (V1);                                                 \
     1505      return (TRUE);                                                    \
     1506    }                                                                   \
     1507  }
     1508
     1509# define W_FUNC(OP,FTYPE) {                                             \
     1510    if (V1->type == ST_SCALAR_FLT) {                                    \
     1511      OUT[0].type = ST_SCALAR_FLT;                                      \
     1512      OUT[0].FltValue = OP;                                             \
     1513      clear_stack (V1);                                                 \
     1514      return (TRUE);                                                    \
     1515    }                                                                   \
     1516    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) {      \
     1517      OUT[0].type = ST_SCALAR_FLT;                                      \
     1518      OUT[0].FltValue = OP;                                             \
     1519      clear_stack (V1);                                                 \
     1520      return (TRUE);                                                    \
     1521    }                                                                   \
     1522    if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {      \
    15021523      OUT[0].type = ST_SCALAR_INT;                                      \
    15031524      OUT[0].IntValue = OP;                                             \
     
    15361557  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT);
    15371558  if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT);
    1538   if (!strcmp (op, "rnd"))    S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
    1539   if (!strcmp (op, "drnd"))   S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
    1540   if (!strcmp (op, "lrnd"))   S_FUNC(0*M1 + lrand48(), ST_SCALAR_INT);
    1541   if (!strcmp (op, "mrnd"))   S_FUNC(0*M1 + mrand48(), ST_SCALAR_INT);
    15421559  if (!strcmp (op, "not"))    S_FUNC(!(M1), ST_SCALAR_INT);
    15431560  if (!strcmp (op, "--"))     S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed,
     
    15451562  if (!strcmp (op, "isnan"))  S_FUNC(isnan((opihi_flt)(M1)), ST_SCALAR_FLT); // XXX modify in future   
    15461563
     1564  // these ops do not use the V1 value (W_FUNC does define a temp variable M1)
     1565  if (!strcmp (op, "rnd"))    W_FUNC(drand48(), ST_SCALAR_FLT);
     1566  if (!strcmp (op, "drnd"))   W_FUNC(drand48(), ST_SCALAR_FLT);
     1567  if (!strcmp (op, "lrnd"))   W_FUNC(lrand48(), ST_SCALAR_INT);
     1568  if (!strcmp (op, "mrnd"))   W_FUNC(mrand48(), ST_SCALAR_INT);
     1569
     1570  // these are also valid for string values
     1571  if (!strcmp (op, "isword")) W_FUNC(FALSE, ST_SCALAR_INT);
     1572  if (!strcmp (op, "isnum"))  W_FUNC(TRUE,  ST_SCALAR_INT);
     1573  if (!strcmp (op, "isint"))  W_FUNC((V1->type == ST_SCALAR_INT), ST_SCALAR_INT);
     1574  if (!strcmp (op, "isflt"))  W_FUNC((V1->type == ST_SCALAR_FLT), ST_SCALAR_INT);
     1575
    15471576# undef S_FUNC
    1548 
    1549   clear_stack (V1);
    1550 
    1551   char line[512]; // this is only used to report an error
    1552   snprintf (line, 512, "error: op %s not defined as unary scalar op!", op);
     1577# undef W_FUNC
     1578
     1579  clear_stack (V1);
     1580
     1581  char line[512]; // this is only used to report an error
     1582  snprintf (line, 512, "error: op %s not defined as unary scalar op for a numerical value!", op);
     1583  push_error (line);
     1584  return (FALSE);
     1585}
     1586
     1587int W_unary (StackVar *OUT, StackVar *V1, char *op) {
     1588
     1589# define W_FUNC(VALUE) {                                                \
     1590    OUT[0].type = ST_SCALAR_INT;                                        \
     1591    OUT[0].IntValue = VALUE;                                            \
     1592    clear_stack (V1);                                                   \
     1593    return (TRUE);                                                      \
     1594  }
     1595
     1596  // string unary functions (all result in int output values)
     1597  if (!strcmp (op, "isword")) W_FUNC(TRUE);
     1598  if (!strcmp (op, "isnum"))  W_FUNC(FALSE);
     1599  if (!strcmp (op, "isint"))  W_FUNC(FALSE);
     1600  if (!strcmp (op, "isflt"))  W_FUNC(FALSE);
     1601  if (!strcmp (op, "length")) W_FUNC(strlen(V1[0].name));
     1602
     1603# undef W_FUNC
     1604
     1605  clear_stack (V1);
     1606
     1607  char line[512]; // this is only used to report an error
     1608  snprintf (line, 512, "error: op %s not defined as unary scalar op for a string value!", op);
    15531609  push_error (line);
    15541610  return (FALSE);
Note: See TracChangeset for help on using the changeset viewer.