From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <david.rowley@2ndquadrant.com>
Cc: Huong Dangminh <huo-dangminh@ys.jp.nec.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: Akio Iwaasa <aki-iwaasa@vt.jp.nec.com>
Subject: Re: power() function in Windows: "value out of range: underflow"
Date: Sun, 29 Apr 2018 17:19:00 -0400
Message-ID: <28607.1525036740@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKJS1f9y5RqPps4i+13k9ry9pHZ2p_pCtZrOke0-4Nkz3POqbg@mail.gmail.com>
References: <75DB81BEEA95B445AE6D576A0A5C9E936A73E741@BPXM05GP.gisp.nec.co.jp>
<CAKJS1f9y5RqPps4i+13k9ry9pHZ2p_pCtZrOke0-4Nkz3POqbg@mail.gmail.com>
David Rowley <david.rowley@2ndquadrant.com> writes:
> You patch fixes the problem for me, and importantly the two following
> cases still work:
> postgres=# select power(1,'NaN');
> power
> -------
> 1
> (1 row)
> postgres=# select power('NaN', 0);
> power
> -------
> 1
> (1 row)
> There's no mention in the SQL standard about NaN handling in the above
> two cases, but I wonder if it's worth also adding a couple of tests
> for the above two cases to ensure all platforms are doing the same
> thing... ?
So the early returns from the buildfarm say "no, they aren't". It looks
like older BSDen know the NaN^0 = 1 rule, but they return NaN for 1^NaN.
Aside from the failure buildfarm member nightjar is showing, I've
confirmed this behavior on a NetBSD 5.2 installation I had laying around,
and there's also evidence in the related man page:
http://netbsd.gw.com/cgi-bin/man-cgi?pow+3+NetBSD-5.2.3
which goes to great lengths to justify NaN^0 = 1 while saying nothing
to suggest that 1^NaN might not yield NaN.
I'm not sure if we should add more special-case code for that, or just
remove that test case again. Historically we've not really felt that it
was our job to mask oddities of the platform's math library, so the fact
that power() is worrying about this seems like unjustified scope creep.
On the other hand, we do have a bunch of special cases there already,
so refusing to handle older BSD would be a tad inconsistent.
And, while we're on the subject ... some of my machines give
postgres=# select power(-1,'NaN');
ERROR: a negative number raised to a non-integer power yields a complex result
POSIX says this should return NaN, not an error (and my old NetBSD
installation does that, as does numeric_power). Should we change it?
I'm a bit inclined to handle all the NaN-input cases with explicit
code before we do anything that relies on libc's behavior.
BTW, numeric_power just emits NaN for NaN input, without either of
these special cases. But that's platform-independent, so I'm hesitant
to consider back-patching a change there; if we change that, I'd vote
for doing so only in HEAD.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.rowley@2ndquadrant.com, huo-dangminh@ys.jp.nec.com, pgsql-hackers@postgresql.org, aki-iwaasa@vt.jp.nec.com
Subject: Re: power() function in Windows: "value out of range: underflow"
In-Reply-To: <28607.1525036740@sss.pgh.pa.us>
References: <75DB81BEEA95B445AE6D576A0A5C9E936A73E741@BPXM05GP.gisp.nec.co.jp> <CAKJS1f9y5RqPps4i+13k9ry9pHZ2p_pCtZrOke0-4Nkz3POqbg@mail.gmail.com> <28607.1525036740@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox