Thread: linking error
View Single Post
  #3   Spotlight this post!  
Unread 27-01-2007, 19:01
ace123's Avatar
ace123 ace123 is offline
Registered User
AKA: Patrick Horn
FRC #0008 (Paly Robotics - http://robotics.paly.net/)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Palo Alto, CA
Posts: 50
ace123 has a spectacular aura aboutace123 has a spectacular aura about
Send a message via AIM to ace123
Re: linking error

If you are only using the sqrt function, you might like to see the implementation of InvSqrt():
http://www.beyond3d.com/articles/fastinvsqrt/

here is an implementation that I compiled on my first controller (the scary constant is a standard IEEE754 floating point number, so it will work on every microprocessor the same way).

I would definitely extensively test this method before putting it to use (i.e. don't hook up motors until you are sure it gives the expected answers), but I believe that it is just a first-order Newton's method approximation, with the constant being a first guess I believe.

I'm pretty sure it will take up less space than the included math library.

Code:
float invSqrt(float magnitudeSquared) {
    float xhalf;
    float temp;
    long i;
    
    // magic follows:
    temp = magnitudeSquared;
    xhalf = 0.5f*temp;
    i = *(long*)&temp;
    i = 0x5f3759df - (i>>1);
    temp = *(float*)&i;
    temp = temp*(1.5f - xhalf*temp*temp);
    
    // temp now contains the 1/sqrt(magnitudeSquared)
    return temp;
}
Definitely works on the computer:
Code:
5629.000:     InvSqrt 0.013318; 1/sqrt 0.013329
281.0000:     InvSqrt 0.059639; 1/sqrt 0.059655
28.00000:     InvSqrt 0.188722; 1/sqrt 0.188982
6.000000:     InvSqrt 0.407681; 1/sqrt 0.408248
4.000000:     InvSqrt 0.499154; 1/sqrt 0.500000
2.017857:     InvSqrt 0.703756; 1/sqrt 0.703971
0.250000:     InvSqrt 1.996614; 1/sqrt 2.000000
0.166667:     InvSqrt 2.445322; 1/sqrt 2.449490
0.000000:     InvSqrt 19817753709685768192; 1/sqrt inf
__________________
-Patrick Horn, Paly Robotics

Check out the space simulator called Vega Strike, modelled after the space simulator games Elite and Wing Commander. It's Open Source too!
If you have ever played Wing Commander, or especially Privateer, and had a feeling of nostalga derived from the you will enjoy these two Vega Strike mods: Privateer Gemini Gold and Privateer Remake!
I'm working on adding multiplayer support this year...