Actions
Bug #12249
closedMath.gamma(-0.0) should return -Infinity
    Bug #12249:
    Math.gamma(-0.0) should return -Infinity
  
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
Backport:
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.
        
          
          Updated by usa (Usaku NAKAMURA) over 9 years ago
          
          
        
        
      
      - Related to Bug #10642: 2.2: TestMath#test_gamma test failure (MinGW) added
 
        
          
          Updated by nobu (Nobuyoshi Nakada) over 9 years ago
          
          
        
        
      
      - Status changed from Open to Closed
 
Applied in changeset r54492.
math.c: fix tgamma
- math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
[ruby-core:74817] [Bug #12249] 
        
          
          Updated by nobu (Nobuyoshi Nakada) over 9 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 9 years ago
          
          
        
        
      
      Nobuyoshi Nakada wrote:
Applied in changeset r54492.
math.c: fix tgamma
- math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
 
[ruby-core:74817] [Bug #12249]
Thanks nobu!
        
          
          Updated by cremno (cremno phobia) over 9 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 9 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 9 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