|
-
Nov 8th, 2004, 09:35 AM
#1
Thread Starter
Addicted Member
C++ automatically rounding off values
how to resolve the case of c++ rounding off values, for example:
cos(6.2832) i get 1 instead of .99999
and
0.1 being only 0... what should i do
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
Nov 8th, 2004, 09:35 AM
#2
Thread Starter
Addicted Member
forgot to say thannk you!
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
Nov 8th, 2004, 10:30 AM
#3
It's only rounding on output, the variable contains a better value. Use the setprecision modifier from <iomanip> to select how many places after the comma are displayed.
On a side note, the Windows calculator claims that the result of cos(6.2832) is 0.99399308850723265435071042275478
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 14th, 2004, 03:22 AM
#4
Thread Starter
Addicted Member
thanks... but sometimes it still prints 0 if it is 0.000001. what could be the problem? Thank you for your reply.
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
Nov 14th, 2004, 05:24 AM
#5
Floating values only store a specific precision. I don't know the details, as they differ from compiler to compiler.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 14th, 2004, 09:15 AM
#6
I think that varies from OS too OS too, at least we had that problem in Java at school, on some versions of NT/2000 it wrote 1, and on som e 1.000000000001
-
Nov 14th, 2004, 10:51 AM
#7
Thread Starter
Addicted Member
shocks... there are still inconsitencies... anyways.... thanks! at least im able to use <iomanip> even though it doesnt work as always. thanks
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
Nov 14th, 2004, 11:13 AM
#8
PowerPoster
What about in DirectX
D3DVECTOR struct has a float x,y,z.
Seeing a vector represents character posistion I need to store movement variables as floats.
To eliminate warning of double to float, I have to make everything a float which is part of a units movement system.
Speed, TimeDelta, Velocity, Weight.....the list goes on.
So you are saying that float precision is different from machine to machine...
I need integral values, but I also need a definite precision on any CPU, how do I go about that?
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Nov 14th, 2004, 11:14 AM
#9
Use a decimal number libray like Gnu MPL.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 14th, 2004, 12:20 PM
#10
Originally posted by Halsafar
What about in DirectX
D3DVECTOR struct has a float x,y,z.
Seeing a vector represents character posistion I need to store movement variables as floats.
To eliminate warning of double to float, I have to make everything a float which is part of a units movement system.
Speed, TimeDelta, Velocity, Weight.....the list goes on.
So you are saying that float precision is different from machine to machine...
I need integral values, but I also need a definite precision on any CPU, how do I go about that?
Floats in DX is pretty much the same. It is a DX standard. Even tho some HW vendors like to try to change that. So don't worry to much about vectors and matrix math in DX. Your GPU is handeling most of that...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|