Society of Robots - Robot Forum
Software => Software => Topic started by: Ratfink on May 22, 2007, 12:59:03 PM
-
Im trying to do some simple division such as
double val = 40;
val = 40/60;
cout.precision(10);
cout << val;
the value i get is 0
Im aiming for a 16bit platform, any help given will be appreciated
-
double checkAngle()
{
long double degrees=180;
long double angle=40;
long double convert=0;
degrees /= (double)PI;
angle /= (double)60;
angle = (double)(acos((float)angle));
angle = degrees*angle;
angle = 40+angle;
angle = 90-angle;
return angle;
}
Ok solved the divison problem you need to explicity tell the complier your not working with integers else it will give you the result as remainder.
BUT... now when it gets to the line after acos it gives me the result of angle as 20550.0
should be 0.84
any help given is appreciated!
-
Horrible code :-\
You can just type 60.0 instead of 60 if you want the number to be a double... 60.0f if you want it to be a float. No need to cast everything everywhere... And as far as I know, acos takes doubles as input, so that float cast is useless as well.
As for acos, it obviously works in radians.... You might want to code two helper functions like these to make your code clearer:
float DegToRad(float a) { return a * 0.0174533f; }
float RadToDeg(float a) { return a * 57.2958f; }