Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Xeee

Reducing floating point precision !

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m working with a good camera engine , so i want to decrease the precision of a floating point variable , so that 0.00000001 appears as 0.0 only , so how to do it ? thanks for your help ...Xeee

Share this post


Link to post
Share on other sites
Advertisement
I doubt you''re doing anything that''s so precise that it won''t be happy with 0.00000001 instead of 0. If you really do need it consider a threshold instead of 0. E.g. if you''re doing something like if (value == 0) then change that to if (value < 0.001) so everything smaller than 0.001 will be considered, and if value == 0.00000001 then it will be treated as 0 in your program flow.

------------
- outRider -

Share this post


Link to post
Share on other sites
i may have mis-explained my problem , you idea(outrider) is good , but i really need to set this value to zero .
the problem in more details is the when i convert 90 degrees to radians by multiplying by PI/180 , where pi is defined by an 8 digits value , and i give the resulting value to cos(); the answer is not 0 , it is -4.4896592167739e-011 , it is an extremely small value , which is later checked for being zero and multiplied by something , so this is my problem .
if i can get a more precise value for PI (something like 16 or more digits) so that cos(toradians(90))== 0 , that may solve my problem coz as far as i know that PI has as infinite number of digits.
sorry for bad english .
thanks for paying attention .

...Xeee

[edited by - xeee on April 17, 2002 7:55:17 PM]

Share this post


Link to post
Share on other sites
palidine : i thought about this but i think it''s costy , cos that''s done 3 times every frame , or may b i''m under-estimating the speed of the CPU .

...Xeee

Share this post


Link to post
Share on other sites
quote:
which is later checked for being zero and multiplied by something


well then, where you check the above check like someone above suggested:

if (variable < 0.001)....

if you want it to be exactly zero you''re gona have to conver it somewhere. also i don''t think is a big load on the processor, maybe 3-5 cycles....dunno...

-me

Share this post


Link to post
Share on other sites
ok thanks palidine , i think that''s the only solution , but i tried to keep my game as fast as possible so i thought there''d b another solution , thanks anyway .

gotta continue my game .....

...Xeee

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you have a significant design flaw if your program is converting degrees to radian, well unless you are reading data from a file. Get rid of the degrees and work completely in radians. As for pi you can get a good value using trig. I don''t remember, maybe 4*atan(.5) or something like that. Ideally it would be a constant in math.h, that''s what java does.

Share this post


Link to post
Share on other sites
do you mean as in displaying the number on the screen or in a text file?

if so, if you are using something like sprintf, try this

%.3f

this is 3 decimal places for example

others are used for significant figures instead. Look in the help file.

If you actually mean the engine, then only thing I can say is why bother, but you can ignore that comment.



Beer - the love catalyst
good ol'' homepage

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!