我要评分
获取效率
正确性
完整性
易理解

clog2

Compute the base-2 logarithm of a complex number.

Interface Definition

C interface:

float complex clog2f(float complex x);

double complex clog2(double complex x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For clog2f, x is of complex single-precision floating-point type.
  • For clog2, x is of complex double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The base-2 logarithm y of x is returned.
  • The special values are listed in the following table.

    Real Part of the Input (x.real)

    Imaginary Part of the Input (x.imag)

    Real Part of the Output (y.real)

    Imaginary Part of the Output (y.imag)

    +0

    +0

    -inf

    +0

    +0

    -0

    -inf

    -0

    +0

    inf

    inf

    0x40022123045b5dec(pi/2ln2)

    +0

    -inf

    inf

    0xc0022123045b5dec(-pi/2ln2)

    +0

    SNaN

    NaN

    NaN

    +0

    –SNaN

    NaN

    NaN

    +0

    QNaN

    NaN

    NaN

    +0

    –QNaN

    NaN

    NaN

    -0

    +0

    -inf

    0x40122123045b5dec(pi/ln2)

    -0

    -0

    -inf

    0xc0122123045b5dec(-pi/ln2)

    -0

    inf

    inf

    0x40022123045b5dec(pi/2ln2)

    -0

    -inf

    inf

    0xc0022123045b5dec(-pi/2ln2)

    -0

    SNaN

    NaN

    NaN

    -0

    –SNaN

    NaN

    NaN

    -0

    QNaN

    NaN

    NaN

    -0

    –QNaN

    NaN

    NaN

    inf

    +0

    inf

    +0

    inf

    -0

    inf

    -0

    inf

    inf

    inf

    0x3ff22123045b5dec(pi/4ln2)

    inf

    -inf

    inf

    0xbff22123045b5dec(-pi/4ln2)

    inf

    SNaN

    inf

    NaN

    inf

    –SNaN

    inf

    NaN

    inf

    QNaN

    inf

    NaN

    inf

    –QNaN

    inf

    NaN

    -inf

    +0

    inf

    0x40122123045b5dec(pi/ln2)

    -inf

    -0

    inf

    0xc0122123045b5dec(-pi/ln2)

    -inf

    inf

    inf

    0x400b31b486890ce1(3*pi/4ln2)

    -inf

    -inf

    inf

    0xc00b31b486890ce1(-3*pi/4ln2)

    -inf

    SNaN

    inf

    NaN

    -inf

    –SNaN

    inf

    NaN

    -inf

    QNaN

    inf

    NaN

    -inf

    –QNaN

    inf

    NaN

    SNaN

    +0

    NaN

    NaN

    SNaN

    -0

    NaN

    NaN

    SNaN

    inf

    inf

    NaN

    SNaN

    -inf

    inf

    NaN

    SNaN

    SNaN

    NaN

    NaN

    SNaN

    –SNaN

    NaN

    NaN

    SNaN

    QNaN

    NaN

    NaN

    SNaN

    –QNaN

    NaN

    NaN

    –SNaN

    +0

    NaN

    NaN

    –SNaN

    -0

    NaN

    NaN

    –SNaN

    inf

    inf

    NaN

    –SNaN

    -inf

    inf

    NaN

    –SNaN

    SNaN

    NaN

    NaN

    –SNaN

    –SNaN

    NaN

    NaN

    –SNaN

    QNaN

    NaN

    NaN

    –SNaN

    –QNaN

    NaN

    NaN

    QNaN

    +0

    NaN

    NaN

    QNaN

    -0

    NaN

    NaN

    QNaN

    inf

    inf

    NaN

    QNaN

    -inf

    inf

    NaN

    QNaN

    SNaN

    NaN

    NaN

    QNaN

    –SNaN

    NaN

    NaN

    QNaN

    QNaN

    NaN

    NaN

    QNaN

    –QNaN

    NaN

    NaN

    –QNaN

    +0

    NaN

    NaN

    –QNaN

    -0

    NaN

    NaN

    –QNaN

    inf

    inf

    NaN

    –QNaN

    -inf

    inf

    NaN

    –QNaN

    SNaN

    NaN

    NaN

    –QNaN

    –SNaN

    NaN

    NaN

    –QNaN

    QNaN

    NaN

    NaN

    –QNaN

    –QNaN

    NaN

    NaN

Dependency

C: "kc.h"

Example

C interface:
    // typical usage
    double x1 = INFINITY, y1 = INFINITY;
    double x2 = 2.0, y2 = 3.0;
    double x3 = -2.5, y3 = -3.4;
    double x4 = NAN, y4 = NAN;
    double x5 = 0, y5 = 0;
    double complex z1 = clog2(__builtin_complex(x1, y1));
    double complex z2 = clog2(__builtin_complex(x2, y2));
    double complex z3 = clog2(__builtin_complex(x3, y3));
    double complex z4 = clog2(__builtin_complex(x4, y4));
    double complex z5 = clog2(__builtin_complex(x5, y5));
    // print result
    printf("/*\n");
    printf(" * clog2(%.2f + %.2f*I) = %.6f + %.6f*I\n", x1, y1, __real__(z1), __imag__(z1));
    printf(" * clog2(%.2f + %.2f*I) = %.6f + %.6f*I\n", x2, y2, __real__(z2), __imag__(z2));
    printf(" * clog2(%.2f + %.2f*I) = %.6f + %.6f*I\n", x3, y3, __real__(z3), __imag__(z3));
    printf(" * clog2(%.2f + %.2f*I) = %.6f + %.6f*I\n", x4, y4, __real__(z4), __imag__(z4));
    printf(" * clog2(%.2f + %.2f*I) = %.6f + %.6f*I\n", x5, y5, __real__(z5), __imag__(z5));
    printf(" **/\n");
   /*
    * clog2(inf + inf*I) = inf + 1.133090*I
    * clog2(2.00 + 3.00*I) = 1.850220 + 1.417872*I
    * clog2(-2.50 + -3.40*I) = 2.077308 + -3.180882*I
    * clog2(nan + nan*I) = nan + nan*I
    * clog2(0.00 + 0.00*I) = -inf + 0.000000*I
    **/