Project

General

Profile

Actions

Bug #12249

closed

Math.gamma(-0.0) should return -Infinity

Added by Eregon (Benoit Daloze) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
[ruby-core:74817]

Description

On Windows, Math.gamma(-0.0) returns +Infinity instead of -Infinity,
which is the correct result according to tgamma(3) and the behavior on other platforms.

Is this OK to fix in Ruby?
There is already a similar fix for #10642.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #10642: 2.2: TestMath#test_gamma test failure (MinGW)Third Party's Issuenaruse (Yui NARUSE)Actions
Actions #1

Updated by usa (Usaku NAKAMURA) over 8 years ago

  • Related to Bug #10642: 2.2: TestMath#test_gamma test failure (MinGW) added
Actions #2

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Status changed from Open to Closed

Applied in changeset r54492.


math.c: fix tgamma

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED

Also Math.lgamma(-0.0).

Updated by Eregon (Benoit Daloze) over 8 years ago

Nobuyoshi Nakada wrote:

Applied in changeset r54492.


math.c: fix tgamma

Thanks nobu!

Updated by cremno (cremno phobia) over 8 years ago

Regarding Math.lgamma(-0.0) (r54494,r54495):

It's actually caused by the lgamma_r() fallback implementation. A non-invasive fix (I don't think adding if(x==0) would be worthwhile):

diff --git a/missing/lgamma_r.c b/missing/lgamma_r.c
index 6d2f38f..01066d2 100644
--- a/missing/lgamma_r.c
+++ b/missing/lgamma_r.c
@@ -66,7 +66,7 @@ lgamma_r(double x, int *signp)
         double i, f, s;
         f = modf(-x, &i);
         if (f == 0.0) { /* pole error */
-            *signp = 1;
+            *signp = signbit(x) ? -1 : 1;
             errno = ERANGE;
             return HUGE_VAL;
         }

Updated by nagachika (Tomoyuki Chikanaga) over 8 years ago

  • Backport changed from 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE

ruby_2_3 r54643 merged revision(s) 54492,54494,54495,54496,54499,54503.

Updated by usa (Usaku NAKAMURA) over 8 years ago

  • Backport changed from 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE to 2.1: REQUIRED, 2.2: DONE, 2.3: DONE

ruby_2_2 r54687 merged revision(s) 49913,54492,54494,54495,54496,54499,54503.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0