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_divide()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 A_DIVIDE()
 Divide all elements of an array by a value or an array of values
-------------------------------------------------------------------------------

 Syntax

    A_DIVIDE(    <aTarget>,
                 <nDenominator> | <aDenominators>,
                 [<aSource>] )

 Arguments

    <aTarget> is the array to be modified. If <aSource> is not
    specified then each element of <aTarget> is the numerator of the
    division.

    <nDenominator> or <aDenominators> is either a value or an array of
    values used as the denominator in the division.

    <aSource> is an optional array of numerators. If not specified,
    then each element of <aTarget> will be used as the numerator of
    the division.

 Returns

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

 Description

    A_DIVIDE() provides a means to perform a division of every element
    in the <aSource> array if specified or the <aTarget> array if not.
    Each element of the <aSource> or <aTarget> array is divided by the
    <nDenominator> or element for element by <aDenominator>. The
    result of the division replaces the value in the <aTarget> array.

    A_DIVIDE() 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 the various numeric types is permitted, however, the source
    values are promoted or demoted to the targets type before the
    operation is executed.

    Division by zero is trapped and the element in error is replaced
    with zero.

 Notes

  . Division by zero is trapped and the element in error is
  replaced with zero.

 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 )
    aDenominator = A_DECLARE( "D", rows, cols )

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

    // Divide every element in the target array by 2
    A_DIVIDE( aTarget, 2 )
    ? A_RETRIEVE( aTarget, A_( 4, 5 ) )    // Result: 5.0

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

    // Divide every element in the source array by five and
    // put the result in the target array.
    A_DIVIDE( aTarget, 5, aSource )
    ? A_RETRIEVE( aTarget, A_( 4, 5 ) )    // Result: 2.0

    // Fill the denominator array with 4's
    // Remember the source array still has all 10's
    A_FILL( aDenominator, 4, A_(1, 1), rows * cols )

    // Divide every element in the source array by every element
    // in the denominator array and put the result in the target
    // array.
    A_DIVIDE( aTarget, aDenominator, aSource )
    ? A_RETRIEVE( aTarget, A_( 4, 5 ) )    // Result: 2.5

See Also: A_MULTIPLY() A_PLUS() A_MINUS()

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