Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Re: gamma() and lgamma() functions - Mailing list pgsql-hackers

From Dmitry Koval
Subject Re: gamma() and lgamma() functions
Date
Msg-id ab47e6b1-95f9-4de2-9224-f7750e7b2373@postgrespro.ru
Whole thread Raw
In response to gamma() and lgamma() functions  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: gamma() and lgamma() functions
List pgsql-hackers
Hi!

I think having gamma() and lgamma() functions in PostgreSQL would be 
useful for some users, this is asked [1].

I have a question regarding the current implementation of gamma() 
function. Code block:

+    if (errno == ERANGE && arg1 != 0)
+    {
+        if (result != 0.0)
+            float_overflow_error();
+        else
+            float_underflow_error();
+    }
+    else if (isinf(result) && arg1 != 0 && !isinf(arg1))
+        float_overflow_error();
+    else if (result == 0.0)
+        float_underflow_error();

Why in some cases (if arg1 is close to 0, but not 0) an error 
(float_overflow_error) will be returned, but in the case of "arg1 = 0" 
the value 'Infinity' will be returned?
For example:

 >SELECT gamma(float8 '1e-320');
ERROR:  value out of range: overflow

 >SELECT gamma(float8 '0');
   gamma
----------
  Infinity
(1 row)

Perhaps it would be logical if the behavior in these cases was the same 
(either ERROR or 'Infinity')?

Links:
[1] 
https://stackoverflow.com/questions/58884066/how-can-i-run-the-equivalent-of-excels-gammaln-function-in-postgres

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Potential ABI breakage in upcoming minor releases
Next
From: Christoph Berg
Date:
Subject: Re: Potential ABI breakage in upcoming minor releases