7 Replies - 566 Views - Last Post: 20 September 2013 - 07:49 AM Rate Topic: -----

#1 Fuuyutsuki  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 01-September 13

Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 03:09 AM

Hello DreamInCode Members,

I have made a Windows Form Application Calculator and have been testing as I go along with the actual Windows Calculator, but when I finished the "Sin" button, the results were always different than the regular Windows Calculator's results. Not sure why they are different, was hoping someone here could offer me some guidance.

Thank you in advance,
Fuuyutsuki

For example, with my calculator "Sin(25)" comes out to -0.132351750097773
But with the Windows Scientific Calculator "Sin(25)" comes out to .4226182617406......

        private void SinButton_Click(object sender, EventArgs e)
        {
            FirstNumber = Convert.ToDouble(DisplayTextBox.Text);
            FirstNumber = Math.Sin(FirstNumber);
            DisplayTextBox.Text = FirstNumber.ToString();
        }


Is This A Good Question/Topic? 0
  • +

Replies To: Math.Sin is returning different values than the Windows Calculator

#2 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,524
  • Joined: 08-April 09

Re: Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 04:32 AM

I tried google calculator and it gives me sin(25) = -0.13235175009, tried windows calculator it gives me 0.42261826174069943618697848964773
Was This Post Helpful? 1
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,233
  • Joined: 21-June 11

Re: Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 04:33 AM

You probably have the Windows calculator set to degrees. The Math.Sin method takes its input in radians.

This post has been edited by sepp2k: 20 September 2013 - 04:37 AM

Was This Post Helpful? 2
  • +
  • -

#4 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,524
  • Joined: 08-April 09

Re: Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 04:34 AM

Yes, that is correct -0.13235175009777302890200509388361 is correct result.
Was This Post Helpful? 1
  • +
  • -

#5 Fuuyutsuki  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 01-September 13

Re: Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 04:56 AM

Oh wow, thank you everyone. I didn't even think of that :-/

I appreciate the responses.
Was This Post Helpful? 0
  • +
  • -

#6 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 06:41 AM

If you want your answer in degrees as well, then just shove your input angle into this method and then pass the result into Math.Sin.

public double ConvertToRadians(double angle)
{
    return (Math.PI / 180) * angle;
}

Was This Post Helpful? 1
  • +
  • -

#7 Fuuyutsuki  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 01-September 13

Re: Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 07:07 AM

View PostRyano121, on 20 September 2013 - 06:41 AM, said:

If you want your answer in degrees as well, then just shove your input angle into this method and then pass the result into Math.Sin.

public double ConvertToRadians(double angle)
{
    return (Math.PI / 180) * angle;
}



Thanks again, I will do this
Was This Post Helpful? 0
  • +
  • -

#8 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,524
  • Joined: 08-April 09

Re: Math.Sin is returning different values than the Windows Calculator

Posted 20 September 2013 - 07:49 AM

Ryano121 you could have just post link to Math.Sin Method
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1