Hi, I have the following code sample:

t = sqrt(discrim);

where discrim is equal 4. However, instead of returning 2 it will return an
incredibly large number or -1.n#IND00000000...

Any help would be greatly appreciated.

Sincerley,

Keith La Force

Re: sqrt() not working by Igor

Igor
Wed Sep 29 10:06:41 CDT 2004

"Keith La Force" <Keith La Force@discussions.microsoft.com> wrote in
message news:88954537-6A24-44A2-A298-551C0E677814@microsoft.com
> Hi, I have the following code sample:
>
> t = sqrt(discrim);
>
> where discrim is equal 4. However, instead of returning 2 it will
> return an incredibly large number or -1.n#IND00000000...

This most likely means that discrim is not 4 after all. Show some code.
This program compiles, runs and prints expected result:

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

int main()
{
double discrim = 4;
double t = sqrt(discrim);
printf("%g\n", t);
return 0;
}

--
With best wishes,
Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage



Re: sqrt() not working by Barry

Barry
Thu Sep 30 00:33:24 CDT 2004

On Wed, 29 Sep 2004 07:53:02 -0700, "Keith La Force" <Keith La
Force@discussions.microsoft.com> wrote:

>Hi, I have the following code sample:
>
>t = sqrt(discrim);
>
>where discrim is equal 4. However, instead of returning 2 it will return an
>incredibly large number or -1.n#IND00000000...
>
Did you remember to include the proper headers?


<<Remove the del for email>>

Re: sqrt() not working by Tim

Tim
Sat Oct 02 15:38:43 CDT 2004

Barry Schwarz <schwarzb@deloz.net> wrote:
>
>"Keith La Force" wrote:
>
>>Hi, I have the following code sample:
>>
>>t = sqrt(discrim);
>>
>>where discrim is equal 4. However, instead of returning 2 it will return an
>>incredibly large number or -1.n#IND00000000...
>
>Did you remember to include the proper headers?

That is almost certainly Keith's problem. Observe:

C:\tmp>cat x.c
#include <stdio.h>

int main()
{
double t = sqrt(4.0);
printf("%g\n", t);
}

C:\tmp>cl x.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

x.c
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:x.exe
x.obj

C:\tmp>x
1.07479e+009

This, by the way, is an EXCELLENT justification for always running with
/W4, which would have pinpointed the problem immediately:

C:\tmp>cl /W4 x.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

x.c
x.c(5) : warning C4013: 'sqrt' undefined; assuming extern returning int
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:x.exe
x.obj

C:\tmp>

--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc