what is it and why does it occur in programs performing floating point
calculations ? Is it harmful? if yes, then what are the possible
solutions. Btw here was my input to the program:
input
*******
Enter theta, phi, r
0
0
0
output
********
-0.000000 0.000000 -1.000000
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159
#endif
#define deg2radian(x) ((M_PI/180) * (x))
int main(void)
{
double theta, phi;
double thetahat[3], phihat[3];
double r;
double rhat[3];
printf("Enter theta, phi, r\n");
scanf("%lf %lf %lf", &theta, &phi, &r);
theta = deg2radian(theta);
phi = deg2radian(phi);
thetahat[0] = -sin(theta);
thetahat[1] = cos(theta);
thetahat[2] = 0;
phihat[0] = cos(theta) * cos(phi);
phihat[1] = sin(theta) * cos(phi);
phihat[2] = -sin(phi);
rhat[0] = thetahat[1] * phihat[2] - thetahat[2] * phihat[1];
rhat[1] = thetahat[2] * phihat[0] - thetahat[0] * phihat[2];
rhat[2] = thetahat[0] * phihat[1] - thetahat[1] * phihat[0];
printf("%f %f %f\n ", rhat[0], rhat[1] , rhat[2]);
return 0;
}