Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trigonometry, float or double?  (Read 4308 times)

0 Members and 1 Guest are viewing this topic.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Trigonometry, float or double?
« on: July 06, 2009, 04:22:50 pm »
Which type is the most commonly used when dealing with trigonometry? If I define PI as a float and use the float versions of sin, cos etc. will I get enough precision? I'm using floats atm and it seems enough.

I know the SFML methods take float parameters but my math teachers always said I should use as many decimals as possible while calculating and then round off in the end.

The thing I'm working on is not gonna be sent up in space, I'm just curious :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Trigonometry, float or double?
« Reply #1 on: July 06, 2009, 04:40:35 pm »
It depends on the context. Usually single precision is enough, but there are some situations where you need double precision.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Trigonometry, float or double?
« Reply #2 on: July 06, 2009, 06:18:05 pm »
Ok, I'm just maneuvering a car.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Trigonometry, float or double?
« Reply #3 on: July 06, 2009, 11:47:25 pm »
You're safe to use floats probably.

But either way if you're using floats or doubles...
usually you shouldn't compare to a specific value (ie: if(velocity==0.f)), instead you should use some epsilon value depending on the context, because it's not fixed-point, maybe if you're handling houndreds, epsilon could be 0.1f, but if you're handling microns, it should be 0.0000001.

You should know that floats have 6 digit significant value.
Code: [Select]
1000000.f + 1.f = 1000000.f  :shock:

Sometimes deceleration doesn't affect velocity, and the object can keep moving. It's almost never noticeable on the position, but rather as the animation continues to walk instead of standing still.

So, my recomendation, check for real numbers with an inequation like
Code: [Select]
if(-EPSILON <= velocity && velocity <=EPSILON) { stop(); }

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Trigonometry, float or double?
« Reply #4 on: July 07, 2009, 12:46:36 am »
thanks for the tip, I have read about it but I will check my code again.

 

anything