[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sqrt C function



R1nso13@aol.com wrote:

when i try to use the sqrt function in gcc 3.0, and the gcc that's standard with 2.2r3 ( i forget the version) i get errors. here's some example code:

#include <math.h>
#include <stdio.h>

double num;
double num_root;

int main ()
{
    num = 4;
    num_root = sqrt(num);
    return (0);
}

fails to compile. i've tried using double as well as float variables. i'm sure this is due to poor coding, but i'm looked at the man page and linuxdoc.org and cannot find any example implementations of sqrt(). I'm running i386 arch, and have math.h (as well as the complete gcc 3.0) installed.


I doubt if this is your problem but on most compilers:

    double num;

    num = 4;

is inefficient; It normally causes an integer constant 4 to be stored somewhere. Then when num = 4; is executed the integer 4 is converted to double every you execute the code.

    num = 4.;

is the normal way but you could even do use num = 4.L; in this case to cause all of the conversion to occur at compile time.

Paul Scott






Reply to: