Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 10, 2010, 11:28 PM   #1
mac2x
macrumors 65816
 
Join Date: Sep 2009
Issue calculating an angle (C)

I'll be up front and tell you guys that this is part of an assignment, but I'm only asking about this one thing that has been giving me fits for the past hour.

Basically, in the context of a larger problem, I need to calculate an angle; specifically by taking the arcsine of 2/3:

Code:
theta = asin (2/3);
That is what I am attempting to use, but it is evidently incorrect in some way because the output claims theta is 0.000000 (theta is of type double). FWIW, I have initialized the variable theta to 0 on the suggestion of my instructor.

[edit] I checked the syntax and it seems right, but surely I am missing something. Let me know if you want the entire program.

Thanks for helping a novice programmer who is feeling like a noob!
__________________
Retina MBP | 2.6 GHz i7 | 16 GB RAM

Gaming Rig | Core i7-2600K | 16 GB RAM | 160 GB OCZ Agility 2 | EVGA GTX 770 SC | Windows 7 Pro x64 | ASUS VG248QE

Last edited by mac2x; Sep 10, 2010 at 11:46 PM.
mac2x is offline   0 Reply With Quote
Old Sep 11, 2010, 12:27 AM   #2
mac2x
Thread Starter
macrumors 65816
 
Join Date: Sep 2009
Figured it out!

Boy do I ever feel dumb.

I did this problem on paper before translating it into C...and I got a little too gung-ho on copying. That 2/3 is SUPPOSED to be the quotient of two variables of type double that have been previously calculated by the program.

I have a feeling this will work better once I correct that issue.
__________________
Retina MBP | 2.6 GHz i7 | 16 GB RAM

Gaming Rig | Core i7-2600K | 16 GB RAM | 160 GB OCZ Agility 2 | EVGA GTX 770 SC | Windows 7 Pro x64 | ASUS VG248QE
mac2x is offline   0 Reply With Quote
Old Sep 11, 2010, 02:57 AM   #3
SidBala
macrumors 6502a
 
Join Date: Jun 2010
Yes, you are right.

2/3 = 0

arcsin(0) = 0
SidBala is offline   0 Reply With Quote
Old Sep 11, 2010, 05:13 AM   #4
timbos
macrumors member
 
Join Date: Jan 2009
Teddy Bear Debugging

One of my colleagues has a teddy bear on his desk. Whenever he gets stuck at something that seems simple (and correct) to him, he explains it to the bear rather than bug one of us. 9 times out of 10, having to explain the problem out loud makes it clear what the solution is.
timbos is offline   0 Reply With Quote
Old Sep 11, 2010, 11:48 AM   #5
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
Also, don't forget that the C math functions take arguments in radians, not degrees

radians = degrees * (180/pi)
robvas is offline   0 Reply With Quote
Old Sep 11, 2010, 12:11 PM   #6
LPZ
macrumors 65816
 
Join Date: Jul 2006
Quote:
Originally Posted by robvas View Post
Also, don't forget that the C math functions take arguments in radians, not degrees

radians = degrees * (180/pi)
Maybe that should be (pi/180)?
LPZ is offline   0 Reply With Quote
Old Sep 11, 2010, 01:40 PM   #7
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Quote:
Originally Posted by LPZ View Post
Maybe that should be (pi/180)?
Probably best to use the builtin constants for these things; M_PI for π, M_1_PI for 1/π, and so on.
Catfish_Man is offline   0 Reply With Quote
Old Sep 11, 2010, 02:11 PM   #8
mac2x
Thread Starter
macrumors 65816
 
Join Date: Sep 2009
Quote:
Originally Posted by timbos View Post
One of my colleagues has a teddy bear on his desk. Whenever he gets stuck at something that seems simple (and correct) to him, he explains it to the bear rather than bug one of us. 9 times out of 10, having to explain the problem out loud makes it clear what the solution is.
Haha, I don't have a teddy bear, but I can sometimes find someone on skype to bug in a similar fashion.

Quote:
Originally Posted by robvas View Post
Also, don't forget that the C math functions take arguments in radians, not degrees

radians = degrees * (180/pi)
Quote:
Originally Posted by LPZ View Post
Maybe that should be (pi/180)?
Yes, the conversion is degrees * (π/180). And yes, I am aware that it needs radians.
__________________
Retina MBP | 2.6 GHz i7 | 16 GB RAM

Gaming Rig | Core i7-2600K | 16 GB RAM | 160 GB OCZ Agility 2 | EVGA GTX 770 SC | Windows 7 Pro x64 | ASUS VG248QE
mac2x is offline   0 Reply With Quote
Old Sep 11, 2010, 02:13 PM   #9
mac2x
Thread Starter
macrumors 65816
 
Join Date: Sep 2009
Quote:
Originally Posted by Catfish_Man View Post
Probably best to use the builtin constants for these things; M_PI for π, M_1_PI for 1/π, and so on.
That sounds interesting, but we haven't covered that yet in class so I'd be nervous about using it. Could you explain further? Thanks.
__________________
Retina MBP | 2.6 GHz i7 | 16 GB RAM

Gaming Rig | Core i7-2600K | 16 GB RAM | 160 GB OCZ Agility 2 | EVGA GTX 770 SC | Windows 7 Pro x64 | ASUS VG248QE
mac2x is offline   0 Reply With Quote
Old Sep 11, 2010, 07:39 PM   #10
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
Quote:
Originally Posted by mac2x View Post
That sounds interesting, but we haven't covered that yet in class so I'd be nervous about using it. Could you explain further? Thanks.
http://www.cs.cf.ac.uk/Dave/C/node17.html

The math.h library defines many (often neglected) constants. It is always advisable to use these definitions:

HUGE -- The maximum value of a single-precision floating-point number.
M_E -- The base of natural logarithms (e).

M_LOG2E -- The base-2 logarithm of e.

M_LOG10E - The base-10 logarithm of e.

M_LN2 -- The natural logarithm of 2.

M_LN10 -- The natural logarithm of 10.

M_PI -- $\pi$.

M_PI_2 -- $\pi$/2.

M_PI_4 -- $\pi$/4.
M_1_PI -- 1/$\pi$.

M_2_PI -- 2/$\pi$.

M_2_SQRTPI -- 2/$\sqrt{\pi}$.

M_SQRT2 -- The positive square root of 2.

M_SQRT1_2 -- The positive square root of 1/2.

MAXFLOAT -- The maximum value of a non-infinite single- precision floating point number.

HUGE_VAL -- positive infinity.
robvas is offline   0 Reply With Quote
Old Sep 11, 2010, 07:55 PM   #11
chrono1081
macrumors 604
 
chrono1081's Avatar
 
Join Date: Jan 2008
Location: Isla Nublar
Quote:
Originally Posted by timbos View Post
One of my colleagues has a teddy bear on his desk. Whenever he gets stuck at something that seems simple (and correct) to him, he explains it to the bear rather than bug one of us. 9 times out of 10, having to explain the problem out loud makes it clear what the solution is.
This works! I've told problems to co-workers who hear me yelling at the computer (and they ask why) and by explaining something (that I know they don't understand) just by saying it outloud I solve it myself.

There is also the famous "Solved it in a dream" that happens to almost every programmer, where you think of a problem so long you end up dreaming about it and solve it.
__________________
Mac Pro (2010): 3.33Ghz Intel Xeon (6 core) - 24 GB RAM - NVidia Quadro k5000
Macbook Air (2010): 2.13 Ghz Intel Core 2 Duo - 4GB RAM
chrono1081 is offline   0 Reply With Quote
Old Sep 11, 2010, 08:18 PM   #12
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Quote:
Originally Posted by chrono1081 View Post
This works! I've told problems to co-workers who hear me yelling at the computer (and they ask why) and by explaining something (that I know they don't understand) just by saying it outloud I solve it myself.

There is also the famous "Solved it in a dream" that happens to almost every programmer, where you think of a problem so long you end up dreaming about it and solve it.
Or the shower, or in the car, or playing a game, etc. Sometimes letting something simmer under the surface instead of pounding your head against it is what your brain needs.

-Lee
lee1210 is offline   0 Reply With Quote
Old Sep 11, 2010, 11:06 PM   #13
mac2x
Thread Starter
macrumors 65816
 
Join Date: Sep 2009
Thank you robvas!
__________________
Retina MBP | 2.6 GHz i7 | 16 GB RAM

Gaming Rig | Core i7-2600K | 16 GB RAM | 160 GB OCZ Agility 2 | EVGA GTX 770 SC | Windows 7 Pro x64 | ASUS VG248QE
mac2x is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Stuck on 'calculating time remaining' glasstrap OS X 10.8 Mountain Lion 2 Jul 26, 2014 12:21 AM
Calculating Volume Of sphere abcdefg12345 Mac Programming 6 Mar 20, 2014 07:04 AM
iCloud backup storage calculating incorrectly karansaraf iCloud and Apple Services 2 Dec 22, 2013 10:17 AM
Calculating nearest path moonman239 iPhone/iPad Programming 6 Aug 3, 2013 05:51 AM
Retina MBP 13 with display issue? black looks green from R angle maccuser MacBook Pro 1 Feb 28, 2013 08:18 PM

Forum Jump

All times are GMT -5. The time now is 04:10 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC