IMG

 
IMG
IMG   IMG
  Welcome to GTAForums! Be sure to check out the Grand Theft Auto V Forum.

You are not registered! (If you are, click here to login) Registering is fast, free and easy and allows you to instantly reply to any topic on GTAForums.
Why wait? Click here to register your own unique username and become part of the ever-growing community!


( Log In | Register | Revalidate Validation E-mail )
Quick Log-In:
  IMG
       
>
  Reply to this topicStart new topicStart Poll

 About floating point

 
Swoorup  
Posted: Tuesday, Apr 3 2012, 17:53
Quote Post


innovator
Group Icon
Group: Members
Joined: Oct 28, 2008

au.gif

XXXXX



Floating point has more values than a unsigned int. But are there any precision losses in it? If so, then how much is the limitation?

Can this limitation be overcomed by using a double data type?
PMMSNYahoo
  Top
 

 
K^2  
Posted: Tuesday, Apr 3 2012, 19:14
Quote Post


Vidi Vici Veni
Group Icon
Group: Zaibatsu
Joined: Apr 14, 2004

us.gif

Member Award




Of course there is a precision loss. You have 1 bit for sign, which is effectively same as int, though it works differently. There are 8 bits for exponent, which is what lets you increase the range. And that only leaves 23 bits for mantissa, which provides you with precision. This translates to roughly 10^-8 of precision. But unlike integer, where precision is fixed, floating point precision is relative. So it's 10^-8 of whatever value you are working with.

Double precision does, in fact, double precision. It's good to about 10^-16. Problem is, not all compilers and not all hardware supports double precision natively, so using double can come at cost of performance. Furthermore, graphics hardware runs with single precision floats, so if you are making a game engine, you'd almost always try to make it work without using double. For scientific work, double is often necessary, and is in fact the default precision in Fortran, Matlab, Mathematica, etc.
PMMSN
  Top
 

 
Swoorup  
Posted: Wednesday, Apr 4 2012, 04:22
Quote Post


innovator
Group Icon
Group: Members
Joined: Oct 28, 2008

au.gif

XXXXX



I have to work out with game units. Its bounds are:

East -10,000 units
West 4000 units

North 8000 units
South -4000 units

In between these bounds, the numbers must be able to have at least 2 decimal in places.
Furthermore the numbers must be multiplied by 16.
I am worried if floating point will be able to take this into consideration
PMMSNYahoo
  Top
 

 
K^2  
Posted: Wednesday, Apr 4 2012, 09:05
Quote Post


Vidi Vici Veni
Group Icon
Group: Zaibatsu
Joined: Apr 14, 2004

us.gif

Member Award




Sure. Your largest value by magnitude is 10^4. Plus two decimal places for precision is 10^6. And you need to multiply by 16. That's a little over 10^7. You have a little more than 10^8. So you have almost an order of magnitude to spare. Not a whole lot of breathing room, but sufficient for your needs as described.
PMMSN
  Top
 

 
Swoorup  
Posted: Wednesday, Apr 4 2012, 13:59
Quote Post


innovator
Group Icon
Group: Members
Joined: Oct 28, 2008

au.gif

XXXXX



Thanks K^2, thank you a whole lot for every information. Wish I could somehow, reward you for the share of wisedom. tounge.gif
PMMSNYahoo
  Top
 

 

0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)

0 Members:

Topic Options Reply to this topicStart new topicStart Poll
Search topic for posted by (exact match)



 
IMG IMG