ROBOTC.net forumshttp://www.robotc.net/forums/ Math calculation errorhttp://www.robotc.net/forums/viewtopic.php?f=63&t=5444 Page 1 of 1

Author:  fxlj007 [ Fri Feb 01, 2013 4:52 pm ]
Post subject:  Math calculation error

I have a simple sentence of arithmetic in my code

 Code:   vx = (2.0/3)*a - (1.0/3)*(b+c);vy = (1.0/(2.0*Sin60))*(c-b);

Nothing goes wrong except at certain data points:
When
a = 0, b = -87, c = 87,
it comes up with a strange result:
vx=0.000000 vy=20184.000000 (<- this is wrong)

Can you suggest any reason?

P.S. "Sin60" is just a constant float variable
 Code:static const float Sin60 = sinDegrees(60);

 Author: mightor [ Sun Feb 03, 2013 3:23 pm ] Post subject: Re: Math calculation error Moved to this sub forum for better visibility.= Xander

 Author: Coder A [ Mon Feb 11, 2013 2:34 pm ] Post subject: Re: Math calculation error Well, the vx variable works fine. The vy is the problem. I guess you knew that, but I'm not exactly sure why that would happen. Sometimes, robotc treats assignment statements as being calculated as shorts unless otherwise specified. The way to specify is to put the data type in front of the information inside parentheses, like (float) or (char) or (long). I don't know where the type statements have to be placed, so first put them in front of everything like:vy = (float) (1.0/ (float) (2.0* (float) Sin60))*(c-b)and then get rid of unnecessary (float)'s. Possibly, that may not work at all. could you tell me the types of a,b,c,vx,and vy? That might help. Keep us updated on how to help!-Coder A

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/