Date: Mon, 19 Aug 2002 11:24:35 -0400 From: Mikhail Teterin <mi+mx@aldan.algebra.com> To: Dan Nelson <dnelson@allantgroup.com>, Matthew Seaman <m.seaman@infracaninophile.co.uk> Cc: questions@FreeBSD.ORG Subject: Re: pow(3) on FreeBSD Message-ID: <200208191124.35129.mi%2Bmx@aldan.algebra.com> In-Reply-To: <20020819043012.GN74231@dan.emsphone.com> References: <200208190413.g7J4DEcw051123@corbulon.video-collage.com> <20020819043012.GN74231@dan.emsphone.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 (and not NaN as Matthew claimed). = $ cat > test.c = #include <math.h> = #include <stdio.h> = 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 On Monday 19 August 2002 03:10 am, Matthew Seaman wrote: = No --- read the manual page again more carefully. It says: = = The functions pow(x, y) checks to see if x < 0 and y is not an integer = Or in other words, pow() returns NaN and sets errno == EDOM in = situations where the result would be complex valued. This is just not true. I guess, questions@ needs a moderator :-/ to keep poor quality help out and angry insulting responses (such as this one by me) muted! The man-page does not mention NaN (Not-a-Number) at all: mteterin@misha:~ (265) man 3 pow | fgrep NaN | wc -l 0 = > Needless to say, Solaris' pow works properly for non-integer = > arguments... = 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... 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?.. Thank you! -mi To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208191124.35129.mi%2Bmx>