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

atan2pi

Compute the arctangent of y/x and divide the arctangent by π.

Interface Definition

C interface:

float atan2pif(float y, float x);

double atan2pi(double y, double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For atan2df, x is of single-precision floating-point type.
  • For atan2d, x is of double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For atan2df, y is of single-precision floating-point type.
  • For atan2d, y is of double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • Normal range: The result of atan(y/x)/π is returned. res ∈ [-1, +1]
  • Special values: See the following table.

    Input Value (y)

    Input Value (x)

    Output Value (result)

    +0

    +0

    +0

    +0

    -0

    +1

    +0

    inf

    +0

    +0

    -inf

    +1

    +0

    NaN

    NaN

    -0

    +0

    -0

    -0

    -0

    -1

    -0

    inf

    -0

    -0

    -inf

    -1

    -0

    NaN

    NaN

    inf

    +0

    0.5

    inf

    -0

    0.5

    inf

    inf

    0.25

    inf

    -inf

    0.75

    inf

    NaN

    NaN

    -inf

    +0

    -0.5

    -inf

    -0

    -0.5

    -inf

    inf

    -0.25

    -inf

    -inf

    -0.75

    -inf

    NaN

    NaN

    NaN

    +0

    NaN

    NaN

    -0

    NaN

    NaN

    inf

    NaN

    NaN

    -inf

    NaN

    NaN

    NaN

    NaN

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    float x1 = -1.0, x2 = 1.0, x3 = 0.5, x4 = -0.5;
    // special handling
    float a = 0.0, b = INFINITY, c = -INFINITY, d = NAN;
    // print result
    printf("atan2pi(1.0, 1.0) = %.15f\n", atan2pi(x1, x1));
    printf("atan2pi(-1.0, -1.0) = %.15f\n", atan2pi(x2, x2));
    printf("atan2pi(0.5, 0.5) = %.15f\n", atan2pi(x3, x3));
    printf("atan2pi(-0.5, -0.5) = %.15f\n", atan2pi(x4, x4));
    printf("atan2pi(0.0, 0.0) = %.15f\n", atan2pi(a, a));
    printf("atan2pi(-0.0, -0.0) = %.15f\n", atan2pi(-a, -a));
    printf("atan2pi(INFINITY, INFINITY) = %.15f\n", atan2pi(b, b));
    printf("atan2pi(-INFINITY, -INFINITY) = %.15f\n", atan2pi(c, c));
    printf("atan2pi(NAN, NAN) = %.15f\n", atan2pi(d, d));
    /*
     *  atan2pi(1.0, 1.0) = -0.750000000000000
     *  atan2pi(-1.0, -1.0) = 0.250000000000000
     *  atan2pi(0.5, 0.5) = 0.250000000000000
     *  atan2pi(-0.5, -0.5) = -0.750000000000000
     *  atan2pi(0.0, 0.0) = 0.000000000000000
     *  atan2pi(-0.0, -0.0) = -1.000000000000000
     *  atan2pi(INFINITY, INFINITY) = 0.250000000000000
     *  atan2pi(-INFINITY, -INFINITY) = -0.750000000000000
     *  atan2pi(NAN, NAN) = nan
     *
     * */