Re: factorial of negative numbers

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Ashutosh Bapat <ashutosh(dot)bapat(at)2ndquadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: factorial of negative numbers
Date: 2020-06-18 11:57:49
Message-ID: e2738962-037a-4403-8071-735f8341de8a@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020-06-18 09:43, Juan José Santamaría Flecha wrote:
>
> On Thu, Jun 18, 2020 at 9:13 AM Peter Eisentraut
> <peter(dot)eisentraut(at)2ndquadrant(dot)com
> <mailto:peter(dot)eisentraut(at)2ndquadrant(dot)com>> wrote:
>
> On 2020-06-16 14:17, Dean Rasheed wrote:
> > I think you're probably right though. Raising an out-of-range error
> > seems like the best option.
>
> committed as proposed then
>
>
> The gamma function from math.h returns a NaN for negative integer
> values, the postgres factorial function returns a numeric, which allows
> NaN. Raising an out-of-range error seems only reasonable for an integer
> output.

But this is not the gamma function. The gamma function is undefined at
zero, but factorial(0) returns 1. So this is similar but not the same.

Moreover, functions such as log() also error out on unsupportable input
values, so it's consistent with the spec.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Juan José Santamaría Flecha 2020-06-18 12:19:10 Re: factorial of negative numbers
Previous Message Fujii Masao 2020-06-18 11:57:13 Re: POC and rebased patch for CSN based snapshots