fix lgtm alert - variable pi

This commit is contained in:
Krishna Vedala 2020-07-10 22:40:46 -04:00
parent 81f4428569
commit df25df3236
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
1 changed files with 11 additions and 8 deletions

View File

@ -1,8 +1,11 @@
/**
* @file
* @brief Function to convert a Cartesian co-ordinate to polar form.
*/
#define _USE_MATH_DEFINES /**< required for MS Visual C */
#include <math.h>
#include <stdio.h>
const double pi = 3.141592653589793238462643383279502884;
/**
give as arguments to the executable two x and y coordinates
outputs a polar coordinate
@ -24,15 +27,15 @@ int main()
}
else if (x < 0 && y > 0)
{ // Q2
thetaFinal = theta + pi;
thetaFinal = theta + M_PI;
}
else if (x < 0 && y < 0)
{ // Q3
thetaFinal = theta - pi;
thetaFinal = theta - M_PI;
}
else if (x > 0 && y < 0)
{ // Q4
thetaFinal = 2 * pi - theta;
thetaFinal = 2 * M_PI - theta;
}
}
}
@ -40,11 +43,11 @@ int main()
{ // exceptions when no actual angle is present
if (y > 0)
{
thetaFinal = pi / 2;
thetaFinal = M_PI / 2;
}
else
{
thetaFinal = -(pi / 2);
thetaFinal = -(M_PI / 2);
}
}
if (y == 0)
@ -55,7 +58,7 @@ int main()
}
else
{
thetaFinal = -pi;
thetaFinal = -M_PI;
}
}
printf("%.2f %.2f\n", r, atan2(y, x));