Public Group

# cos gives strange results

This topic is 4503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi u->angle=90.0; float pop=-cos(32*12.3455*u->angle); float slope=-cos(u->angle* 3.1415926535897932384626433832795 / 180.0); --------------------- pop and slope becomes: -0.0641614 4.37114e-008 ------------------- Why is this? Is the value in slope corrupted? If i mult with 100 and cast to int slope is 0 while pop is -6. Thanks Erik

##### Share on other sites
Thos are the same values I get. What results were you expecting?

##### Share on other sites
Fist it was your “My awesome game” post and then your “About boring jokes (my awesome game)” post and now this. Obviously all results are correct. So why do you waste the time of people that are here to help?

##### Share on other sites
Quote:
 Original post by sulimanWhy is this?

Floating point numbers have limited precision.

Quote:
 Is the value in slope corrupted?

The difference between 4.4e-8 and 0 isn't that great.

Quote:
 If i mult with 100 and cast to int slope is 0 while pop is -6.

4.4e-8 is 0.000000044

##### Share on other sites
Quote:
 Original post by sulimanpop and slope becomes:-0.06416144.37114e-008-------------------If i mult with 100 and cast to int slope is 0 while pop is -6.

If you cast that float to int then it will equal 0. Going from float to int usually drops the decimals. :/ Also for future reference the "e" in a number like that usually means scientific notation.

##### Share on other sites
Ah i think i get it now. But it's a bit confusing that the compiler mix different modes of representation. Anyways thanks for clearing it out.

@Anonymous Poster
How is this in ANY way related to the "my awesome game" tread? Im sorry if i offended you with that atrocity but please inject some self-distance. Or at least stop posting as anonymous.

Erik

##### Share on other sites
i think i have never really dealt (conciensely) with those e-00X numbers. It all make sense when reading the stuff recommended by you guys. As often, these calculations failed becouse of another change i made earlier. Thats why i though it was corrupt.

##### Share on other sites
Quote:
 Original post by Anonymous PosterFist it was your “My awesome game” post and then your “About boring jokes (my awesome game)” post and now this. Obviously all results are correct. So why do you waste the time of people that are here to help?

This is the beginner's forum. People frequently ask questions with answers that are obvious to others. That is the purpose of this forum, so I wouldn't waste my time flaming people for it.

##### Share on other sites
Quote:
 Original post by JohnBoltonThis is the beginner's forum. People frequently ask questions with answers that are obvious to others.

And the poster responsible for this anonymous flame has been suspended. Such behaviour is not tolerated in For Beginners.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009836
• ### Who's Online (See full list)

There are no registered users currently online

×