Click or drag to resize
mpfr_lib.mpfr_atan2 Method
Set rop to the arc-tangent2 of y and x rounded in the direction rnd.

Namespace:  Math.Mpfr.Native
Assembly:  Math.Mpfr.Native (in Math.Mpfr.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static int mpfr_atan2(
	mpfr_t rop,
	mpfr_t y,
	mpfr_t x,
	mpfr_rnd_t rnd
)

Parameters

rop
Type: Math.Mpfr.Native.mpfr_t
The result floating-point number.
y
Type: Math.Mpfr.Native.mpfr_t
The ordinate floating-point value.
x
Type: Math.Mpfr.Native.mpfr_t
The abscissa floating-point value.
rnd
Type: Math.Mpfr.Native.mpfr_rnd_t
The rounding direction.

Return Value

Type: Int32
Return zero, a positive, or a negative value if rop is respectively equal to, greater than, or lower than the exact result. See GNU MPFR - Rounding Modes for details.
Remarks

If x > 0, atan2(y, x) = atan(y/x); if x < 0, atan2(y, x) = sign(y) * (Pi - atan(abs(y/x))), thus a number from -Pi to Pi. As for atan, in case the exact mathematical result is +Pi or -Pi, its rounded result might be outside the function output range.

atan2(y, 0) does not raise any floating-point exception. Special values are handled as described in the ISO C99 and IEEE 754-2008 standards for the atan2 function:

  • atan2(+0, -0) returns +Pi.
  • atan2(-0, -0) returns -Pi.
  • atan2(+0, +0) returns +0.
  • atan2(-0, +0) returns -0.
  • atan2(+0, x) returns +Pi for x < 0.
  • atan2(-0, x) returns -Pi for x < 0.
  • atan2(+0, x) returns +0 for x > 0.
  • atan2(-0, x) returns -0 for x > 0.
  • atan2(y, 0) returns -Pi/2 for y < 0.
  • atan2(y, 0) returns +Pi/2 for y > 0.
  • atan2(+Inf, -Inf) returns +3 * Pi/4.
  • atan2(-Inf, -Inf) returns -3 * Pi/4.
  • atan2(+Inf, +Inf) returns +Pi/4.
  • atan2(-Inf, +Inf) returns -Pi/4.
  • atan2(+Inf, x) returns +Pi/2 for finite x.
  • atan2(-Inf, x) returns -Pi/2 for finite x.
  • atan2(y, -Inf) returns +Pi for finite y > 0.
  • atan2(y, -Inf) returns -Pi for finite y < 0.
  • atan2(y, +Inf) returns +0 for finite y > 0.
  • atan2(y, +Inf) returns -0 for finite y < 0.
Examples
// Create, initialize, and set a new floating-point number x to -1.
mpfr_t x = new mpfr_t();
mpfr_lib.mpfr_init2(x, 64U);
Assert.IsTrue(mpfr_lib.mpfr_set_si(x, -1, mpfr_rnd_t.MPFR_RNDN) == 0);

// Create, initialize, and set a new floating-point number y to 0.
mpfr_t y = new mpfr_t();
mpfr_lib.mpfr_init2(y, 64U);
Assert.IsTrue(mpfr_lib.mpfr_set_si(y, 0, mpfr_rnd_t.MPFR_RNDN) == 0);

// Create and initialize a new floating-point number rop.
mpfr_t rop = new mpfr_t();
mpfr_lib.mpfr_init2(rop, 64U);

// Set rop = atan2(y, x).
Assert.IsTrue(mpfr_lib.mpfr_atan2(rop, y, x, mpfr_rnd_t.MPFR_RNDN) == 1);

// Assert that the value of rop is PI.
Assert.IsTrue(mpfr_lib.mpfr_const_pi(x, mpfr_rnd_t.MPFR_RNDN) == 1);
Assert.IsTrue(mpfr_lib.mpfr_cmp(rop, x) == 0);

// Release unmanaged memory allocated for x, y, and rop.
mpfr_lib.mpfr_clears(x, y, rop, null);
See Also