From owner-freebsd-questions Mon Aug 19 8:52:37 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ABE0737B400 for ; Mon, 19 Aug 2002 08:52:30 -0700 (PDT) Received: from mailc.telia.com (mailc.telia.com [194.22.190.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3F06743E65 for ; Mon, 19 Aug 2002 08:52:24 -0700 (PDT) (envelope-from erikt@midgard.homeip.net) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by mailc.telia.com (8.12.5/8.12.5) with ESMTP id g7JFqM4G013203 for ; Mon, 19 Aug 2002 17:52:22 +0200 (CEST) X-Original-Recipient: Received: from falcon.midgard.homeip.net (h62n2fls20o913.telia.com [212.181.163.62]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id RAA28059 for ; Mon, 19 Aug 2002 17:52:20 +0200 (CEST) Received: (qmail 25172 invoked by uid 1001); 19 Aug 2002 15:52:18 -0000 Date: Mon, 19 Aug 2002 17:52:18 +0200 From: Erik Trulsson To: Mikhail Teterin Cc: Dan Nelson , Matthew Seaman , questions@FreeBSD.ORG Subject: Re: pow(3) on FreeBSD Message-ID: <20020819155217.GA25028@falcon.midgard.homeip.net> Mail-Followup-To: Mikhail Teterin , Dan Nelson , Matthew Seaman , questions@FreeBSD.ORG References: <200208190413.g7J4DEcw051123@corbulon.video-collage.com> <20020819043012.GN74231@dan.emsphone.com> <200208191124.35129.mi+mx@aldan.algebra.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200208191124.35129.mi+mx@aldan.algebra.com> User-Agent: Mutt/1.5.1i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, Aug 19, 2002 at 11:24:35AM -0400, Mikhail Teterin wrote: > On Monday 19 August 2002 12:30 am, Dan Nelson wrote: > = In the last episode (Aug 19), Mikhail Teterin said: > = > In accordance with its man-page entry, pow(3) will return 0 if its > = > second argument is not an integer. Why is that? What's the reasoning > = > and what is a workaround -- I'm trying to port an application from > = > Solaris, which uses pow(3) quite heavily... > > = Seems to work fine for me. Where in the manpage does it say that? All > = I can see is that if x<0, y must be an integer. > > = My Solaris manpage says the same thing. > > No, it does not have the requirement of y being an integer. Only that x > is positive. > > You are right, the FreeBSD's man-page does not specify the return value > in case of a non-integer y. I just know it from experiment to be zero Correction: It does not specify the return value for negative non-integers. > (and not NaN as Matthew claimed). > > = $ cat > test.c > = #include > = #include > = main() > = { > = printf("%f\n", pow(2, 1.5)); > = } > = ^D > = $ gcc test.c -lm > = $ ./a.out > = 2.828427 > > The test above was, obviously, done on Solaris. On FreeBSD, this same > program outputs zero: > > mteterin@misha:~ (257) uname -a > FreeBSD misha 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Wed Jul 31 13:27:39 EDT > 2002 mteterin@misha [...] > mteterin@misha:~ (258) ./a.out > 0.000000 > mteterin@attila:~ (515) uname -a > SunOS attila 5.8 Generic_108528-13 sun4u sparc SUNW,Sun-Fire-280R > mteterin@attila:~ (516) ./a.out > 2.828427 For me that program prints 2.828427 just as it is supposed to do. This is using FreeBSD 4.6-STABLE. It might be that something has changed in -current (unlikely but possible) or it might be your setup that is faulty. [snip] > > = Even Solaris cannot return a complex value as a double. > > There is nothing complex (pun intended) about, say, 1^2.5. It is still > 1. -- unless you are running FreeBSD (Linux?)... There is nothing > complex about Dan's's example (2^1.5) above either -- the correct value > is 2.828427, but it is 0 on FreeBSD -- in accordance with the man-page > and in disagreement with Dan... That comment about complex refers to the case when the second argument to pow() is a negative non-integer, in which case the result should indeed be complex which cannot be represented as a double. The manpage does not say anything about pow() returning 0 for positive non-integer arguments, nor does pow() return 0 in that case as far as I can determine. > > Now, can someone, please, offer the REAL reasons for the FreeBSD's > apparent defficiency? May be, even a double-precision workaround -- > unlike powf(3), which operates on float-precision numbers?.. I can't duplicate the behaviour you see here on my system so I suspect it is your setup that is faulty somehow. -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message