Message-ID: <3AB314CE.F5DAD6A3@earthlink.net> From: Martin Ambuhl X-Mailer: Mozilla 4.76 [en] (Win95; U) X-Accept-Language: en,zh-CN,fr,de-CH,ru MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Whats up with sqrt? References: <5BF60CD649EDD411A04600B0D049F53A09257B AT hydmail02 DOT hyd DOT wilco-int DOT com> <8ugkfne00UjFETbF0i AT andrew DOT cmu DOT edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 59 Date: Sat, 17 Mar 2001 07:37:11 GMT NNTP-Posting-Host: 63.210.208.97 X-Complaints-To: abuse AT earthlink DOT net X-Trace: newsread1.prod.itd.earthlink.net 984814631 63.210.208.97 (Fri, 16 Mar 2001 23:37:11 PST) NNTP-Posting-Date: Fri, 16 Mar 2001 23:37:11 PST Organization: EarthLink Inc. -- http://www.EarthLink.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com James W Sager Iii wrote: > > Excerpts from netnews.comp.os.msdos.djgpp: 17-Mar-101 RE: Whats up with > sqrt? by Prashant Ramachandra AT wil > > > > On Saturday, March 17, 2001 10:49 AM, James W Sager Iii > > [SMTP:sager+@andrew.cmu.edu] wrote: > > | For me, the function sqrt() which obviously returns a square root > > | is > > | messing up for me on moderately large numbers. > > | > > | anything below 10,000 and it gives me about the right answer, but at > > | like: > > | > > | range = sqrt(300,000) > > | > > | I get a 0 as a return value? I tried doing: > > > > Don't use commas while sending parameters. It's giving you the square root > > of the second parameter, i.e. 0. > > > > range = sqrt (300000.0); > > > > is the right way to do it. > > I'm sorry, I wasn't using commas... but at the same time I wasn't using > 0. so perhaps it was being type casted wrong. > > but I tested it > a=sqrt(10001.0); > > returns 100516 > > Ok, that makes no sense what so ever > well at least I have my own function to do it no biggie Frankly, I don't believe you about the behavior you claim. Since you don't post the misbehaving code, we can only guess what you are doing wrong. (My guess is failure to include appropriate headers and failure to enable reasonable warnings.) Notice the following: #include int main(void) { double a; a = sqrt(300000); printf("sqrt(300000) returned as %g;\n" " %g*%g=%g\n", a, a, a, a * a); a = sqrt(10001); printf("sqrt(10001) returned as %g;\n" " %g*%g=%g\n", a, a, a, a * a); return 0; } sqrt(300000) returned as 547.723; 547.723*547.723=300000 sqrt(10001) returned as 100.005; 100.005*100.005=10001