# Trigonometry Sin rule calculation problem

• 02-05-2006
Harry
Trigonometry Sin rule calculation problem
Code:

```#define PI 3.14159265 #include <stdio.h> #include <math.h> void main(void){         double angleB = 180.00000000000;         double L1;         L1 = sin(angleB*PI/180);         printf("%f", L1); }```

in the console, printf, prints 0.000000 (as expected)
when I hover over L1 it reads, 3.5897934739268e-009
Which then screws up the rest of my calcuations. Can someone tell me why this is so?

Ta

Harry

(Visual C++ 6.0) - For those who don't know sin(180) should = 0 ..
• 02-06-2006
Richie T
i dont know what you mean by hover, this code works fine for
me on the same compiler. I assume that you want to be able
to enter in a number and get its sin, you'll need this code:

scanf ("%lf", &angleB);

i think that there's something about the %lf format specifier being
removed in the last standard, (it might just be for printf), but
scanning in using just %f doesnt work in visual.

by the way, whats with all the trailing 0's on angleB? NO NEED!
and use int main instead of void main, there's a discussion on this
section of the forum on the topic, check it out to see whats wrong
with void.

lastly, this is the C++ forum, printf implies that you're doing C,
not much of a difference in this code, just so you know to post
on the correct forum.
• 02-06-2006
Rashakil Fol
Quote:

Originally Posted by Harry
Can someone tell me why this is so?

3.14159265 is not the value of pi.
• 02-06-2006
Salem
> in the console, printf, prints 0.000000 (as expected)
> when I hover over L1 it reads, 3.5897934739268e-009
Note the e-009
That's 0.0000000035897934739268
Which if you only display the first 6 digits is 0.000000

> Which then screws up the rest of my calcuations. Can someone tell me why this is so?
Floats are inaccurate, your calculations need to take the fact that floats are approximations into account. This means not assuming for instance that any two floats will compare equal for example.