From: | Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com> |
---|---|
To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
Cc: | Bruce Momjian <bruce(at)momjian(dot)us>, Ashutosh Bapat <ashutosh(dot)bapat(at)2ndquadrant(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: factorial of negative numbers |
Date: | 2020-06-16 10:30:16 |
Message-ID: | CAC+AXB1bgOU8VQRYushaYiC0r-0u+=tR1if3sRjLRhNzxkGvOw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Jun 16, 2020 at 11:50 AM Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
wrote:
> On Tue, 16 Jun 2020 at 10:09, Juan José Santamaría Flecha
> <juanjo(dot)santamaria(at)gmail(dot)com> wrote:
> >
> > It is defined as NaN (or undefined), which is not in the realm of
> integer numbers. You might get a clear idea of the logic from [1], where
> they also make a case for the error being ERRCODE_DIVISION_BY_ZERO.
> >
> > [1] http://mathforum.org/library/drmath/view/60851.html
> >
>
> Hmm, I think ERRCODE_DIVISION_BY_ZERO should probably be reserved for
> actual division functions.
>
> With [1], we could return 'Infinity', which would be more correct from
> a mathematical point of view, and might be preferable to erroring-out
> in some contexts.
>
> [1]
> https://www.postgresql.org/message-id/606717.1591924582%40sss.pgh.pa.us
Returning division-by-zero would be confusing for the user.
I think that out-of-range would be a reasonable solution for "FUNCTION
factorial(integer) RETURNS integer", because it could only return an
integer when the input is a positive integer, but for "FUNCTION
factorial(integer) RETURNS numeric" the returned value should be 'NaN'
without error.
Regards,
Juan José Santamaría Flecha
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2020-06-16 10:57:26 | Re: Parallel Seq Scan vs kernel read ahead |
Previous Message | Bruce Momjian | 2020-06-16 10:10:54 | Re: create database with template doesn't copy database ACL |