Skip to content

Commit

Permalink
Merge pull request #28 from basilaljamal/master
Browse files Browse the repository at this point in the history
new operator INTZ(IF NEGATIVE THEN ZERO)
  • Loading branch information
keenanlang authored Sep 18, 2024
2 parents 145393a + 39e9e01 commit f6a016c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
44 changes: 44 additions & 0 deletions calcApp/Db/aneg_apos_test.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
record(waveform, "$(P):test_array")
{
field(NELM, "10")
field(FTVL, "LONG")
field(INP, "[0, -1, 2, -3, 4, -5, 6, -7, 8, -9]")
}

record(ao, "$(P):test_number")
{
field(PINI, "YES")
field(VAL, "-10")
}

record(acalcout, "$(P):calc_aneg_array")
{
field(NELM, "10")
field(NUSE, "10")
field(INAA, "$(P):test_array CP NMA")
field(CALC, "ANEG(AA)")
}

record(acalcout, "$(P):calc_aneg")
{
field(NELM, "10")
field(NUSE, "10")
field(INPA, "$(P):test_number CP NMA")
field(CALC, "ANEG(A)")
}

record(acalcout, "$(P):calc_apos_array")
{
field(NELM, "10")
field(NUSE, "10")
field(INAA, "$(P):test_array CP NMA")
field(CALC, "APOS(AA)")
}

record(acalcout, "$(P):calc_apos")
{
field(NELM, "10")
field(NUSE, "10")
field(INPA, "$(P):test_number CP NMA")
field(CALC, "APOS(A)")
}
6 changes: 6 additions & 0 deletions calcApp/src/aCalcPerform.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ long aCalcPerform(double *p_dArg, int num_dArgs, double **pp_aArg,
case NINT:
case AMAX:
case AMIN:
case ANEG_VAL:
case APOS_VAL:
case IXMAX:
case IXMIN:
case IXZ:
Expand All @@ -762,6 +764,8 @@ long aCalcPerform(double *p_dArg, int num_dArgs, double **pp_aArg,
if (isArray(ps)) {
switch (op) {
case ABS_VAL: for (i=0; i<arraySize; i++) {if (ps->a[i] < 0) ps->a[i] *= -1;} break;
case ANEG_VAL: for (i=0; i<arraySize; i++) {if (ps->a[i] < 0) ps->a[i] = 0;} break;
case APOS_VAL: for (i=0; i<arraySize; i++) {if (ps->a[i] > 0) ps->a[i] = 0;} break;
case UNARY_NEG: for (i=0; i<arraySize; i++) {ps->a[i] *= -1;} break;
case SQU_RT:
status = 0;
Expand Down Expand Up @@ -1029,6 +1033,8 @@ long aCalcPerform(double *p_dArg, int num_dArgs, double **pp_aArg,
} else { /* if (isArray(ps)) */
switch (op) {
case ABS_VAL: if (ps->d < 0) {ps->d *= -1;} break;
case ANEG_VAL: if (ps->d < 0) {ps->d = 0;} break;
case APOS_VAL: if (ps->d > 0) {ps->d = 0;} break;
case UNARY_NEG: ps->d *= -1; break;
case SQU_RT:
if (ps->d < 0) {
Expand Down
4 changes: 4 additions & 0 deletions calcApp/src/aCalcPostfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ static const ELEMENT operands[] = {
{"I", 0, 0, 1, OPERAND, FETCH_I},
{"II", 0, 0, 1, OPERAND, FETCH_II},
{"INT", 9, 10, 0, UNARY_OPERATOR, NINT},
{"ANEG", 9, 10, 0, UNARY_OPERATOR, ANEG_VAL},
{"APOS", 9, 10, 0, UNARY_OPERATOR, APOS_VAL},
{"ISINF", 9, 10, 0, UNARY_OPERATOR, ISINF},
{"ISNAN", 9, 10, 0, VARARG_OPERATOR, ISNAN},
{"IX", 0, 0, 1, OPERAND, CONST_IX},
Expand Down Expand Up @@ -305,6 +307,8 @@ static const char *opcodes[] = {
/* Algebraic */
"ABS_VAL",
"EXP",
"ANEG_VAL",
"APOS_VAL",
"LOG_10",
"LOG_E",
"MAX",
Expand Down
2 changes: 2 additions & 0 deletions calcApp/src/aCalcPostfixPvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ typedef enum {
/* Algebraic */
ABS_VAL,
EXP,
ANEG_VAL,
APOS_VAL,
LOG_10,
LOG_E,
MAX,
Expand Down

0 comments on commit f6a016c

Please sign in to comment.