View Single Post
  #1   Spotlight this post!  
Unread 08-02-2007, 17:14
flippo flippo is offline
Registered User
FRC #1701
 
Join Date: Nov 2006
Location: Detroit, MI
Posts: 2
flippo is an unknown quantity at this point
Question Floating point math zero

I searched through the forum and could not find a similar topic, so:

I have timed my code and determined that I can use floating point math, however when I attempt to use the standard library:

float sqrt(float);

function it returns "zero" (the actual zero value not random numbers) randomly when my input is at a constant value. I am also recieving similar problems from other floating point trig functions. Can anyone help, or has anyone experienced similar problems?

Here is the actual function that is calling the sqrt function.

Quote:
void handleDriveJoystick(void) {
unsigned int radius;
signed int prettyJoyX, prettyJoyY;

//take care of the joysticks
prettyJoyX = (signed int)DRIVER_JOY_X - 127;
prettyJoyY = (signed int)DRIVER_JOY_Y - 127;

if (DRIVER_JOY_X == 127 && DRIVER_JOY_Y == 127)
theta = 0.;

else
theta = atan2((float)prettyJoyX, (float)prettyJoyY);

radius = (int) (10.0 * sqrt((float)(prettyJoyX*prettyJoyX + prettyJoyY*prettyJoyY)));

[...]

printf("Joy_Y: %u Radius %u ", p1_y, radius);
The omitted code does not reference radius at any point.

Thank you for any and all help.