Working out vector heading based on angle, giving an undesirable result

I've been gathering how to do this, and from what I see, it's exactly how people explained it to do. But when I try this, it's gives me horrific results.

Code:
1
2
3
float angle = 90;
float radians = angle * M_PI / 180;
cout << "x: " << cos(radians) << " y: " << sin(radians) << endl;


Output:
x: -4.37114e-008 y: 1

Desired Output:
x: 0 y: 1

I'm uncertain what I've done wrong.
So your 1m stick is not vertical, but inclined 44nm. That's a calamity.

If you don't understand, -4.37-e-008 is quite close to 0.
It is not exactly 0 because of errors in the algorithm used (the approximation of cosine) and the machine representation of the numbers (M_PI is not exactly \pi)

Also, ¿do you have a good reason to use float instead of double?
I see, some of the precision when converting degrees to radians must be off by that 44nm, wonder if it's possible to correct or whether I should just go ahead with this as it is.

What it's implemented in would be better using float, as I don't require that much precision and 8 bytes of memory and extended precision in a 32-bit program is undesirable.

I tried with everything as double's, same kind of thing. Should this slight variance of 44nm be of concern to me?
Topic archived. No new replies allowed.