コード例 #1
0
ファイル: ifcdlog.c プロジェクト: kendallb/scitech-mgl
_WMRTLINK dcomplex _IF_CDLOG( double rp, double ip ) {
//===================================================

// Return the logarithm (base e) of arg.
// ln(x + iy) = u + iv  =>  x + iy = exp(u) * cis(v)
// Thus x*x + y*y = exp(2u) or u = 0.5 ln(x*x + y*y)
// Also y/x = tan(v)  so  v = atan2(y,x)

    dcomplex    result;

    result.realpart = 0.5 * DLOG( rp*rp + ip*ip );
    result.imagpart = DATAN2( ip, rp );
    return( result );
}
コード例 #2
0
ファイル: powc16.c プロジェクト: ABratovic/open-watcom-v2
dcomplex C16Pow( double a, double b, double c, double d ) {
//=========================================================

// Return the real part of the result of taking one double precision
// complex number to the power of another.
// ( a, b ) ** ( c, d ) = exp( ( c,d ) * log( a,b ) )

    double      u;
    double      v;
    dcomplex    arg1;
    dcomplex    arg2;
    dcomplex    res;

    if( ( a == 0 ) && ( b == 0 ) ) {
        if( d == 0 ) {
            if( c > 0 ) {
                res.realpart = 0;
                res.imagpart = 0;
                return( res );
            }
        }
        arg1.realpart = a;
        arg1.imagpart = b;
        arg2.realpart = c;
        arg2.imagpart = d;
        return( __qmath2err( FP_FUNC_POW | M_DOMAIN | V_ZERO, &arg1, &arg2 ) );
    } else {
        u = DLOG( a*a + b*b ) / 2;
        v = DATAN2( b, a );
        res.realpart = DEXP( u*c - v*d );
        res.imagpart = res.realpart;
        u = u*d + v*c;
        res.realpart *= DCOS( u );
        res.imagpart *= DSIN( u );
        return( res );
    }
}