w3resource

C atan2() function

C atan2() function - Calculate Arctangent

Syntax:

double atan2(double y, double x)

The atan2() function is used to calculate the arctangent of y/x.

Parameters:

Name Description Required /Optional
x Represent x-coordinate. Required
y Represent y-coordinate. Required

Return value from atan2()

  • Returns a value in the range -π to π radians.
  • Returns a value of 0 if both arguments of the atan2() function are zero.

Example: atan2() function

The following example shows the usage of atan2() function.

#include <stdio.h>
#include <math.h> 
int main(void)
{
    double x, y, z;
    x = 0.45;
    y = 0.23;
    z = atan2(x,y);    
    printf("atan2( %lf, %lf ) = %lf", x, y, z); 
}

Output:

atan2( 0.450000, 0.230000 ) = 1.098299

C Programming Code Editor:

Previous C Programming: C atan()
Next C Programming: C cos()



Follow us on Facebook and Twitter for latest update.

C Programming: Tips of the Day

What's the point of const pointers?

const is a tool which you should use in pursuit of a very important C++ concept:

Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.

Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:

void foo(int* ptr)
{
    ptr = 0;// oops, I meant *ptr = 0
}

If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.

Ref : https://bit.ly/33Cdn3Q