From: | Darafei "Komяpa" Praliaskouski <me(at)komzpa(dot)net> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: exp() versus the POSIX standard |
Date: | 2020-06-12 00:36:26 |
Message-ID: | CAC8Q8tJ09umiQdpGpGqiYRb8JOmnLztD2rQNk+o5FOx0cFBvQw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
пт, 12 чэр 2020, 02:57 карыстальнік Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> напісаў:
> I wrote:
> > The POSIX standard says this about the exp(3) function:
> > If x is -Inf, +0 shall be returned.
> > At least on my Linux box, our version does no such thing:
> > regression=# select exp('-inf'::float8);
> > ERROR: value out of range: underflow
>
> Now that I look, power() has similar issues:
>
> regression=# select power('1.1'::float8, '-inf');
> ERROR: value out of range: underflow
> regression=# select power('0.1'::float8, 'inf');
> ERROR: value out of range: underflow
> regression=# select power('-inf'::float8, '-3');
> ERROR: value out of range: underflow
> regression=# select power('-inf'::float8, '-4');
> ERROR: value out of range: underflow
>
> contradicting POSIX which says
>
> For |x| > 1, if y is -Inf, +0 shall be returned.
>
> For |x| < 1, if y is +Inf, +0 shall be returned.
>
> For y an odd integer < 0, if x is -Inf, -0 shall be returned.
>
> For y < 0 and not an odd integer, if x is -Inf, +0 shall be returned.
>
I've had the same issue with multiplying two tiny numbers. Select
2e-300::float * 2e-300::float gives an underflow, and it is not a wanted
thing. This looks like handmade implementation of IEEE754's underflow
exception that should be an optional return flag in addition to well
defined number, but became a stop-the-world exception instead. Had to build
custom Postgres with that logic ripped off in the past to be able to
multiply numbers. Will be happy if that "underflow" (and overflow) thing is
removed.
If in doubt whether this exception should be removed, to follow the spec
fully in this way you have to also raise exception on any inexact result of
operations on floats.
> regards, tom lane
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2020-06-12 01:16:22 | Infinities in type numeric |
Previous Message | Tom Lane | 2020-06-11 23:56:49 | Re: exp() versus the POSIX standard |