diff --git a/src/boot/actions.r b/src/boot/actions.r index d6cb6daffa..1cad650bf5 100644 --- a/src/boot/actions.r +++ b/src/boot/actions.r @@ -21,26 +21,26 @@ REBOL [ add: action [ {Returns the addition of two values.} - value1 [scalar! date!] - value2 + value1 [scalar! date! vector!] + value2 [scalar! date! vector!] ] subtract: action [ {Returns the second value subtracted from the first.} - value1 [scalar! date!] - value2 [scalar! date!] + value1 [scalar! date! vector!] + value2 [scalar! date! vector!] ] multiply: action [ {Returns the first value multiplied by the second.} - value1 [scalar!] - value2 [scalar!] + value1 [scalar! vector!] + value2 [scalar! vector!] ] divide: action [ {Returns the first value divided by the second.} - value1 [scalar!] - value2 [scalar!] + value1 [scalar! vector!] + value2 [scalar! vector!] ] remainder: action [ @@ -421,7 +421,7 @@ open?: action [ ] query: action [ - {Returns information about value if possible.} + {Returns information about target if possible.} target [port! file! url! block! vector!] /mode "Get mode information" field [word! block! none!] "NONE will return valid modes for target type" diff --git a/src/core/f-series.c b/src/core/f-series.c index 172f4a40b8..bc77bb84cf 100644 --- a/src/core/f-series.c +++ b/src/core/f-series.c @@ -124,6 +124,8 @@ case A_SUBTRACT: // "test this" - 10 case A_MULTIPLY: // "t" * 4 = "tttt" case A_DIVIDE: + if (IS_VECTOR(value)) return -1; // allow vector for actions above + //continue... case A_REMAINDER: case A_POWER: case A_ODDQ: diff --git a/src/core/t-decimal.c b/src/core/t-decimal.c index 478b7d0bbd..07c031987a 100644 --- a/src/core/t-decimal.c +++ b/src/core/t-decimal.c @@ -238,7 +238,8 @@ REBOOL almost_equal(REBDEC a, REBDEC b, REBCNT max_diff) { type == REB_PAIR || type == REB_TUPLE || type == REB_MONEY || - type == REB_TIME + type == REB_TIME || + type == REB_VECTOR ) && ( action == A_ADD || action == A_MULTIPLY diff --git a/src/core/t-vector.c b/src/core/t-vector.c index f8e65b5b72..f024579e10 100644 --- a/src/core/t-vector.c +++ b/src/core/t-vector.c @@ -226,6 +226,122 @@ void Set_Vector_Row(REBSER *ser, REBVAL *blk) } +/*********************************************************************** +** +*/ REBVAL* Math_Op_Vector(REBVAL *v1, REBVAL *v2, REBCNT action) +/* +** Do basic math operation on a vector +** +***********************************************************************/ +{ + REBSER *vect = NULL; + REBYTE *data; + REBCNT bits; + REBCNT len; + + REBVAL *left; + REBVAL *right; + + REBI64 i = 0; + REBDEC f = 0; + REBCNT n = 0; + + if (IS_VECTOR(v1) && IS_NUMBER(v2)) { + left = v1; + right = v2; + } else if (IS_VECTOR(v2) && IS_NUMBER(v1)) { + left = v2; + right = v1; + } else { + Trap_Action(VAL_TYPE(v1), action); + return NULL; + } + vect = VAL_SERIES(left); + len = VAL_LEN(left); + bits = VECT_TYPE(vect); + data = vect->data; + + if (IS_INTEGER(right)) { + i = VAL_INT64(right); + f = (REBDEC)i; + } else { + f = VAL_DECIMAL(right); + i = (REBI64)f; + } + + n = VAL_INDEX(left); + + switch (action) { + case A_ADD: + switch (bits) { + case VTSI08: for (; n