0

My Math:

double CosAngle = Math.Cos(radians);
double result = ((v * i) * CosAngle);

I have an issue with the radians if my input is 90 Degrees.

I get "6.12303176911189E-17" for the CosAngle which seems to not take into account that this number is 0.00000000000000000612303176911189!

What is it that I am missing? How can I force this calculation to work, taking into account the E-17 part of the double?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Rusty Nail
  • 2,692
  • 3
  • 34
  • 55
  • 1
    There are some comments explaining at http://stackoverflow.com/questions/6082632/math-cos-math-sin-in-c-sharp. – MatthewG Jan 19 '15 at 02:24
  • Would you mind to show input value and expected output so it is clear what you are unhappy about. – Alexei Levenkov Jan 19 '15 at 02:24
  • @MatthewG - Yes I have read this! Problem it explains why but has no solution! Not unless I convert to a string. – Rusty Nail Jan 19 '15 at 02:35
  • @AlexeiLevenkov - Input is 90 degrees. Converted to Radians: 1.57079633 - Math.Cos(1.57079633) = 6.12303176911189E-17 - I get 10.5 * 6.12303176911189 = 64.291833575674845 Which is wrong. – Rusty Nail Jan 19 '15 at 02:38

1 Answers1

1

How many decimal places you want to show/see, just round it up. The small error arises because of limited number of decimal places of pi are used in calculation.

Bhaskar
  • 1,028
  • 12
  • 16