### Author Topic: Is it my fault, or the computer's?  (Read 3938 times)

0 Members and 1 Guest are viewing this topic.

#### BlakPilar

• LV8 Addict (Next: 1000)
• Posts: 734
• Rating: +44/-1
##### Is it my fault, or the computer's?
« on: October 08, 2011, 05:42:13 pm »
First off, I wasn't sure whether to put this in Math and Science or here, but I'm putting it here.

In .NET, Math.Tan returns the tangent of some number in radians. However, I need the tangent of that number in degrees. I wrote myself a little method, but for some reason, it's not producing the correct number. I take the degrees in radians, multiply them by pi, then divide by 180.

When I put in 30.0, I should get 0.577350269... (according to the calculator) but I'm getting 0.523598775... Am I doing something wrong, or is it an error by the computer?

Full method:
Code: [Select]
public double RadToDeg(double rad) {    double deg = ((rad * Math.PI) / (double)180);    return deg;}
EDIT: I also tried moving around the parenthesis so it was "rad * (Math.PI / (double)180)," but there was no change.
« Last Edit: October 08, 2011, 05:44:14 pm by BlakPilar »

#### parserp

• Hero Extraordinaire
• LV10 31337 u53r (Next: 2000)
• Posts: 1455
• Rating: +88/-7
• The King Has Returned
##### Re: Is it my fault, or the computer's?
« Reply #1 on: October 08, 2011, 05:56:04 pm »
is this c++?
ticalc.org | Cemetech | TI-Freakware | casiocalc.org

Spoiler For inactive:
Serving an LDS (Mormon) mission from Dec 2014 - Dec 2016

#### BlakPilar

• LV8 Addict (Next: 1000)
• Posts: 734
• Rating: +44/-1
##### Re: Is it my fault, or the computer's?
« Reply #2 on: October 08, 2011, 06:00:48 pm »
C#

#### parserp

• Hero Extraordinaire
• LV10 31337 u53r (Next: 2000)
• Posts: 1455
• Rating: +88/-7
• The King Has Returned
##### Re: Is it my fault, or the computer's?
« Reply #3 on: October 08, 2011, 06:02:09 pm »
I don't know much about c#, so the only suggestion I could give you is maybe to float the numbers?
probably won't do anything, but I guess it's worth a try.
ticalc.org | Cemetech | TI-Freakware | casiocalc.org

Spoiler For inactive:
Serving an LDS (Mormon) mission from Dec 2014 - Dec 2016

#### BlakPilar

• LV8 Addict (Next: 1000)
• Posts: 734
• Rating: +44/-1
##### Re: Is it my fault, or the computer's?
« Reply #4 on: October 08, 2011, 06:04:32 pm »
Doubles are more precise floating-point numbers (doubles = 15 sig digs, floats = 7 sig digs), so not sure if that would help.

Edit: Nope, doesn't change it.
« Last Edit: October 08, 2011, 06:05:57 pm by BlakPilar »

#### Runer112

• Moderator
• LV11 Super Veteran (Next: 3000)
• Posts: 2289
• Rating: +639/-31
##### Re: Is it my fault, or the computer's?
« Reply #5 on: October 08, 2011, 06:05:36 pm »
I'm pretty sure the problem is that your conversion factor is inverted. Degrees = radians * 180 / pi.

#### BlakPilar

• LV8 Addict (Next: 1000)
• Posts: 734
• Rating: +44/-1
##### Re: Is it my fault, or the computer's?
« Reply #6 on: October 08, 2011, 06:07:16 pm »
Yeah, but when I do that I get 1718.873385...

#### parserp

• Hero Extraordinaire
• LV10 31337 u53r (Next: 2000)
• Posts: 1455
• Rating: +88/-7
• The King Has Returned
##### Re: Is it my fault, or the computer's?
« Reply #7 on: October 08, 2011, 06:08:50 pm »
is your calc in the right mode?
(just a guess)
ticalc.org | Cemetech | TI-Freakware | casiocalc.org

Spoiler For inactive:
Serving an LDS (Mormon) mission from Dec 2014 - Dec 2016

#### Deep Toaster

• So much to do, so much time, so little motivation
• Administrator
• LV13 Extreme Addict (Next: 9001)
• Posts: 8206
• Rating: +758/-15
##### Re: Is it my fault, or the computer's?
« Reply #8 on: October 08, 2011, 06:10:09 pm »
I'm pretty sure the problem is that your conversion factor is inverted. Degrees = radians * 180 / pi.
Actually, he seems to be converting from degrees to radians (30 to π/6). I'm guessing his routine is just marked wrong.

#### BlakPilar

• LV8 Addict (Next: 1000)
• Posts: 734
• Rating: +44/-1
##### Re: Is it my fault, or the computer's?
« Reply #9 on: October 08, 2011, 06:11:56 pm »
@parser, check the category this is computer languages help.

@Deep, no, I want radians to degrees, but the result is over 1000 when I do it the right way.
« Last Edit: October 08, 2011, 06:25:23 pm by BlakPilar »

#### Deep Toaster

• So much to do, so much time, so little motivation
• Administrator
• LV13 Extreme Addict (Next: 9001)
• Posts: 8206
• Rating: +758/-15
##### Re: Is it my fault, or the computer's?
« Reply #10 on: October 08, 2011, 06:13:04 pm »
But you're saying you want to type in 30 and get 0.577, which is degrees. You want to convert degrees to radians, then put it in Math.Tan.

#### parserp

• Hero Extraordinaire
• LV10 31337 u53r (Next: 2000)
• Posts: 1455
• Rating: +88/-7
• The King Has Returned
##### Re: Is it my fault, or the computer's?
« Reply #11 on: October 08, 2011, 06:13:15 pm »
@parser, check the category this is computer languages help.
yeah but you said that your answer on calc differed from your comp.
ticalc.org | Cemetech | TI-Freakware | casiocalc.org

Spoiler For inactive:
Serving an LDS (Mormon) mission from Dec 2014 - Dec 2016

#### Deep Toaster

• So much to do, so much time, so little motivation
• Administrator
• LV13 Extreme Addict (Next: 9001)
• Posts: 8206
• Rating: +758/-15
##### Re: Is it my fault, or the computer's?
« Reply #12 on: October 08, 2011, 06:18:54 pm »
@parser, check the category this is computer languages help.
yeah but you said that your answer on calc differed from your comp.
The calculator is probably right. He's having trouble writing a math function in C#.
« Last Edit: October 08, 2011, 06:19:15 pm by Deep Thought »

#### parserp

• Hero Extraordinaire
• LV10 31337 u53r (Next: 2000)
• Posts: 1455
• Rating: +88/-7
• The King Has Returned
##### Re: Is it my fault, or the computer's?
« Reply #13 on: October 08, 2011, 06:20:01 pm »
@parser, check the category this is computer languages help.
yeah but you said that your answer on calc differed from your comp.
The calculator is probably right. He's having trouble writing a math function in C#.
sorry my bad.
ticalc.org | Cemetech | TI-Freakware | casiocalc.org

Spoiler For inactive:
Serving an LDS (Mormon) mission from Dec 2014 - Dec 2016

#### BlakPilar

• LV8 Addict (Next: 1000)
• Posts: 734
• Rating: +44/-1
##### Re: Is it my fault, or the computer's?
« Reply #14 on: October 08, 2011, 06:23:04 pm »
@parser, check the category this is computer languages help.
yeah but you said that your answer on calc differed from your comp.
Like Deep said lol. I did tan(30(degree symbol)) to be sure

But I got it now.
« Last Edit: October 08, 2011, 06:25:12 pm by BlakPilar »