Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- FlexFile Reference Guide - <b>a_plus()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 A_PLUS()
 Add all elements of an array by a value or an array of values
-------------------------------------------------------------------------------

 Syntax

    A_PLUS(  <aTarget>,
             [<nValue> | <aValues>],
             [<aSource>] )

 Arguments

    <aTarget> is the array to be modified.  If <aSource> is not
    specified then each element of <aTarget> will be added to <nValue>
    or element by element by <aValue>.

    <nValue> or <aValue> is either a value or an array of values to be
    added.

    <aSource> is an optional array of values.  If specified, then each
    element of <aTarget> will be filled with the corresponding value
    in <aSource> added to <aValue> or <nValue>.

 Returns

    Although there is no return value, the <aTarget> array is
    modified.

 Description

    A_PLUS() provides a means to perform an addition of every element
    in the <aSource> array if specified or the <aTarget> array if not.
    Each element of the <aSource> or <aTarget> array will be added to
    <nValue> or <aValue>.  The result of the addition is placed in the
    <aTarget> array.

    A_PLUS() can be performed on any integer or floating point type
    array. These include the (T)iny, (I)integer, (L)ong, (F)loat and
    (D)ouble (both signed and unsigned integers, of course).  Mixing
    of these types is allowed, however, if the <aTarget> array is of
    integer type, decimals will be truncated.

 Notes

    If the <aTarget> and the <aSource> arrays are not the same
    dimensions, the results will be an addition element for element as
    the arrays are aligned in memory.  See chapter two for how arrays
    are aligned in memory.

 Examples

    // Declare three double type arrays for this function.
    LOCAL rows, cols

    rows = 10
    cols = 20
    aSource = A_DECLARE( "D", rows, cols )
    aTarget = A_DECLARE( "D", rows, cols )
    aAddMe  = A_DECLARE( "D", rows, cols )

    // Fill the target array with 10's
    A_FILL( aTarget, 10, A_(1, 1), rows * cols )

    // Add 2 to every element in the target array
    A_ADD( aTarget, 2 )
    ? A_RETRIEVE( aTarget, A_( 4, 5 ) )    // Result: 12.0


    // Fill the source array with 10's
    A_FILL( aSource, 10, A_(1, 1), rows * cols )

    // Add five to every element in the source array and
    // put the result in the target array.
    A_ADD( aTarget, 5, aSource )
    ? A_RETRIEVE( aTarget, A_( 4, 5 ) )    // Result: 15.0


    // Fill the "add me" array with 4's
    // Remember the source array still has all 10's
    A_FILL( aAddMe, 4, A_(1, 1), rows * cols )

    // Add to every element in the source array the
    // value in every matching element of the "add me"
    // array and put the result in the target array.
    A_ADD( aTarget, aAddMe, aSource )
    ? A_RETRIEVE( aTarget, A_( 4, 5 ) )    // Result: 14.0


See Also: A_DIVIDE() A_MULTIPLY() A_MINUS()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson