- Timestamp:
- Jan 19, 2022, 6:39:42 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20211108/Ohana/src/opihi/lib.shell/stack_math.c
r41363 r41991 1500 1500 if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) { \ 1501 1501 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)) { \ 1502 1523 OUT[0].type = ST_SCALAR_INT; \ 1503 1524 OUT[0].IntValue = OP; \ … … 1536 1557 if (!strcmp (op, "datan")) S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT); 1537 1558 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);1542 1559 if (!strcmp (op, "not")) S_FUNC(!(M1), ST_SCALAR_INT); 1543 1560 if (!strcmp (op, "--")) S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed, … … 1545 1562 if (!strcmp (op, "isnan")) S_FUNC(isnan((opihi_flt)(M1)), ST_SCALAR_FLT); // XXX modify in future 1546 1563 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 1547 1576 # 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 1587 int 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); 1553 1609 push_error (line); 1554 1610 return (FALSE);
Note:
See TracChangeset
for help on using the changeset viewer.
