Sign in to follow this  

Computing Unit position with Float or Int value

This topic is 3592 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

Hi all I got a question about computing and displaying a unit's position on a 2D map. Currently I am doing all position computations as well as movement with Float values, I have read somewhere that it is not good to use float values too much for calculations as it will be more expensive when compared to int values, but float values offer much better precision that int values cannot offer. So should I change my calculations to int values or just use float values for the precision it offers?

Share this post


Link to post
Share on other sites
I think you should still be able to achieve a reasonable degree of accuracy with integers. It depends on how spaced out these integers are on your map. In addition, you could always generate a 'random' offset from the integer point at the point a unit stops to remove any grid effect.

Share this post


Link to post
Share on other sites
Is the program too slow? If it's not, don't bother. If it is, then profile to identify the parts which are slow, and optimize these parts.

Don't attempt to optimize your program before you determine how it can be optimized.

Share this post


Link to post
Share on other sites
On modern hardware floating point calculations are very fast, and even if they weren't, I doubt unit movement calculations on a map would be a performance bottleneck... So i think you should just go with floats due to ease of use and cleaner code, and if their precision turns out to be inadequate (if you have really huge maps), then use double precision floats.

Share this post


Link to post
Share on other sites
Quote:
Original post by Si Hao
float values offer much better precision that int values cannot offer.

In which universe? float has a precision of 24 significant bits whereas float has 32.

Share this post


Link to post
Share on other sites
Quote:
Original post by DevFred
Quote:
Original post by dmatter
Quote:
Original post by DevFred
float has a precision of 24 significant bits

Uhm ok, but in which language, standard or hardware?

Uhm, IEEE 754?

That's better [smile]

Although the OP is possibly more interested in an actual practical language; C/C++ standards don't adhere to the IEEE 754 standard, although perhaps they're coding in Java which I think does. Hardware of course doesn't necessarily have to be stringent on this standard either like the Sony Playstation.

Share this post


Link to post
Share on other sites
The code is in Java.

The reason why I am considering this early on is because, a change in using int or Float can mean a change in the design of a variety of things in my game. Pathfinding, display, collision, etc. so to avoid the pain of doing a late change, I would prefer to change it early on.

Share this post


Link to post
Share on other sites

This topic is 3592 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this