2.2.3.19.1 vectorbase::Abs

Description

Set each value in the vector to it's absolute value.

Syntax

int Abs( )

Parameters

Return

If the method succeeds, the return value is zero.

If the method fails, the return value is nonzero.

Examples

EX1

void vectorbase_Abs_Ex1()
{
    vector values(10);
    double distribution = 1.0;
    double variance = 2.5;

    // Fill the vector with random values. 
    if( normrnd(values, values.GetSize(), distribution, variance) )
    {
        out_str("Error generating random numbers.");
        return;
    }

    int i;

    // Output the values before calling the Abs method.
    out_str("Values before calling Abs:");
    for( i = 0; i < values.GetSize(); i++ )
        printf("  %2d == %f\n", i, values[i]);

    values.Abs();
 
    // Output the values after calling the Abs method.
    out_str("Values after calling Abs:");
    for( i = 0; i < values.GetSize(); i++ )
        printf("  %2d == %f\n", i, values[i]);
}

Remark

See Also

normrnd

Header to Include

origin.h