go_away

### Author Topic: C++ Division == 0??  (Read 3147 times)

0 Members and 1 Guest are viewing this topic.

#### Ratfink • Jr. Member
•  • Posts: 27 ##### C++ Division == 0??
« 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

#### Ratfink • Jr. Member
•  • Posts: 27 ##### Re: C++ Division == 0??
« Reply #1 on: May 22, 2007, 02:16:11 PM »
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!

#### Nyx

• Robot Overlord
•    • Posts: 204 ##### Re: C++ Division == 0??
« Reply #2 on: May 24, 2007, 11:25:44 AM »
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;   }
« Last Edit: May 24, 2007, 11:27:10 AM by Nyx »