libflame  12600
Functions
FLA_Pythag2.c File Reference

(r12600)

Functions

FLA_Error FLA_Pythag2 (FLA_Obj chi, FLA_Obj psi, FLA_Obj rho)
FLA_Error FLA_Pythag2_ops (float *chi, float *psi, float *rho)
FLA_Error FLA_Pythag2_opd (double *chi, double *psi, double *rho)

Function Documentation

FLA_Error FLA_Pythag2 ( FLA_Obj  chi,
FLA_Obj  psi,
FLA_Obj  rho 
)

References FLA_Obj_datatype(), FLA_Pythag2_opd(), and FLA_Pythag2_ops().

{
    FLA_Datatype datatype;

    datatype = FLA_Obj_datatype( chi );

    switch ( datatype )
    {
        case FLA_FLOAT:
        {
            float*  buff_chi = FLA_FLOAT_PTR( chi );
            float*  buff_psi = FLA_FLOAT_PTR( psi );
            float*  buff_rho = FLA_FLOAT_PTR( rho );

            FLA_Pythag2_ops( buff_chi,
                             buff_psi,
                             buff_rho );

            break;
        }

        case FLA_DOUBLE:
        {
            double* buff_chi = FLA_DOUBLE_PTR( chi );
            double* buff_psi = FLA_DOUBLE_PTR( psi );
            double* buff_rho = FLA_DOUBLE_PTR( rho );

            FLA_Pythag2_opd( buff_chi,
                             buff_psi,
                             buff_rho );

            break;
        }

        case FLA_COMPLEX:
        {
            FLA_Check_error_code( FLA_OBJECT_NOT_REAL );

            break;
        }

        case FLA_DOUBLE_COMPLEX:
        {
            FLA_Check_error_code( FLA_OBJECT_NOT_REAL );

            break;
        }
    }

    return FLA_SUCCESS;
}
FLA_Error FLA_Pythag2_opd ( double *  chi,
double *  psi,
double *  rho 
)

References bl1_d0(), and bl1_d1().

Referenced by FLA_Pythag2().

{
    double zero = bl1_d0();
    double one  = bl1_d1();

    double xabs, yabs;
    double w, z;
    double zdivw;

    xabs = fabs( *chi );
    yabs = fabs( *psi );
    w    = max( xabs, yabs );
    z    = min( xabs, yabs );

    if ( z == zero )
    {
        *rho = w;
    }
    else
    {
        zdivw = z / w;

        *rho = w * sqrt( one + zdivw * zdivw );
    }

    return FLA_SUCCESS;
}
FLA_Error FLA_Pythag2_ops ( float *  chi,
float *  psi,
float *  rho 
)

References bl1_s0(), and bl1_s1().

Referenced by FLA_Pythag2().

{
    float  zero = bl1_s0();
    float  one  = bl1_s1();

    float  xabs, yabs;
    float  w, z;
    float  zdivw;

    xabs = fabsf( *chi );
    yabs = fabsf( *psi );
    w    = max( xabs, yabs );
    z    = min( xabs, yabs );

    if ( z == zero )
    {
        *rho = w;
    }
    else
    {
        zdivw = z / w;

        *rho = w * sqrt( one + zdivw * zdivw );
    }

    return FLA_SUCCESS;
}