Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Crio Square Roots (http://www.chiefdelphi.com/forums/showthread.php?t=74532)

tekman1001 15-02-2009 10:15

Crio Square Roots
 
Hi our crio is giving us errors when we try to do square roots using sqrt(variable)
Where variable is obviously a variable. any help would be usefully and appreciated.

EricVanWyk 15-02-2009 10:18

Re: Crio Square Roots
 
Quote:

Originally Posted by tekman1001 (Post 821202)
Hi our crio is giving us errors when we try to do square roots using sqrt(variable)
Where variable is obviously a variable. any help would be usefully and appreciated.

We're going to need a bit more info to help you out here.

What errors are you getting? What does your code look like?

tekman1001 15-02-2009 10:23

Re: Crio Square Roots
 
When we try to download to the crio it tells us it cannot find the function. The code looks like this "Kvar = Dvar / sqrt(PrecentVar);"

Sentient 15-02-2009 11:18

Re: Crio Square Roots
 
It may be that WPILib doesn't have a sqrt function. I honestly don't know what WPILib has implemented, but sqrt() is usually in "math.h", which is a Windows Library (or whatever OS you are using).

tdlrali 15-02-2009 11:32

Re: Crio Square Roots
 
Second sentinel, make sure you #include <cmath>

bronxbomber92 15-02-2009 12:40

Re: Crio Square Roots
 
If for some reason you're having problems beyond #included <cmath> (in which case, you should probably fix anyways :-P) here's a nice implementation of sqrt for floats taken from quake:

Code:

float SquareRootFloat(float number) {
    long i;
    float x, y;
    const float f = 1.5F;

    x = number * 0.5F;
    y  = number;
    i  = * ( long * ) &y;
    i  = 0x5f3759df - ( i >> 1 );
    y  = * ( float * ) &i;
    y  = y * ( f - ( x * y * y ) );
    y  = y * ( f - ( x * y * y ) );
    return number * y;
}



All times are GMT -5. The time now is 01:09.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi