Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Aug 2002 18:05:09 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Mikhail Teterin <mi+mx@aldan.algebra.com>
Cc:        Dan Nelson <dnelson@allantgroup.com>, Matthew Seaman <m.seaman@infracaninophile.co.uk>, questions@FreeBSD.ORG
Subject:   Re: pow(3) on FreeBSD
Message-ID:  <20020819170509.GA10906@happy-idiot-talk.infracaninophi>
In-Reply-To: <200208191124.35129.mi%2Bmx@aldan.algebra.com>
References:  <200208190413.g7J4DEcw051123@corbulon.video-collage.com> <20020819043012.GN74231@dan.emsphone.com> <200208191124.35129.mi%2Bmx@aldan.algebra.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Aug 19, 2002 at 11:24:35AM -0400, Mikhail Teterin wrote:

> 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).

That was a non-integer power of a *negative* number... Anyhow, the
claim that NaN was returned was based on empirical evidence:

happy-idiot-talk:~/misc:% cat xpow.c 
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>

int
main(int argc, char *argv[])
{
        double          x;
        double          y;
        double          res;

        if (argc < 3) {
                fprintf(stderr, "%s", "Usage: pow x y\n");
                exit(-1);
        }
        x = strtod(argv[1], NULL);
        y = strtod(argv[2], NULL);

        errno = 0;
        res = pow(x, y);
        if (errno) {
                perror("pow() error: ");
        }
        printf("%g ^ %g = %g\n", x, y, res);
        exit(0);
}

/* Compile: cc -o xpow xpow.c -lm */
happy-idiot-talk:~/misc:% cc -o xpow xpow.c -lm 
happy-idiot-talk:~/misc:% ./xpow -1 0.5 
-1 ^ 0.5 = NaN

Mind you, there's also the mysterious case of the errno that didn't
bark in the night.  This is:

happy-idiot-talk:~/misc:% uname -v
FreeBSD 4.6-STABLE #3: Sat Aug 17 20:32:01 BST 2002     matthew@happy-idiot-talk.infracaninophile.co.uk:/usr/obj/usr/src/sys/HAPPY-IDIOT-TALK 

running on:

happy-idiot-talk:~/misc:% grep CPU /var/run/dmesg.boot 
CPU: AMD Athlon(TM) XP1600+ (1400.06-MHz 686-class CPU)

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
Tel: +44 1628 476614                                  Marlow
Fax: +44 0870 0522645                                 Bucks., SL7 1TH UK

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?20020819170509.GA10906>