Re: factorial of negative numbers

From: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(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 12:19:10
Message-ID: CAC+AXB1CZveV6xtrquxijL8k4FeFLo6zTmpTsbgUWtFH4GnNiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jun 18, 2020 at 1:57 PM Peter Eisentraut <
peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:

> On 2020-06-18 09:43, Juan José Santamaría Flecha wrote:
> > 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.
>

factorial(n) = gamma(n + 1)

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

If factorial() ever gets extended to other input types it might get
inconsistent, should !(-1.0) also raise an error?

Logarithm is just different case:

https://en.wikipedia.org/wiki/Logarithm#/media/File:Log4.svg

Regards,

Juan José Santamaría Flecha

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Vyacheslav Makarov 2020-06-18 12:39:09 [PATCH] Allow to specify restart_lsn in pg_create_physical_replication_slot()
Previous Message Peter Eisentraut 2020-06-18 11:57:49 Re: factorial of negative numbers