Project

General

Profile

Bug #12249

Math.gamma(-0.0) should return -Infinity

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

Status:
Closed
Priority:
Normal
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

Related to Ruby master - Bug #10642: 2.2: TestMath#test_gamma test failure (MinGW)Third Party's IssueActions

Associated revisions

Revision 41c53344
Added by nobu (Nobuyoshi Nakada) over 3 years ago

math.c: fix tgamma

  • math.c (ruby_tgamma): fix tgamma(-0.0) on mingw. [ruby-core:74817] [Bug #12249]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54492
Added by nobu (Nobuyoshi Nakada) over 3 years ago

math.c: fix tgamma

  • math.c (ruby_tgamma): fix tgamma(-0.0) on mingw. [ruby-core:74817] [Bug #12249]

Revision 54492
Added by nobu (Nobuyoshi Nakada) over 3 years ago

math.c: fix tgamma

  • math.c (ruby_tgamma): fix tgamma(-0.0) on mingw. [ruby-core:74817] [Bug #12249]

Revision 54492
Added by nobu (Nobuyoshi Nakada) over 3 years ago

math.c: fix tgamma

  • math.c (ruby_tgamma): fix tgamma(-0.0) on mingw. [ruby-core:74817] [Bug #12249]

Revision 54492
Added by nobu (Nobuyoshi Nakada) over 3 years ago

math.c: fix tgamma

  • math.c (ruby_tgamma): fix tgamma(-0.0) on mingw. [ruby-core:74817] [Bug #12249]

Revision bb7a4c2a
Added by usa (Usaku NAKAMURA) over 3 years ago

  • math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong. cf. [Bug #12249]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54495
Added by usa (Usaku NAKAMURA) over 3 years ago

  • math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong. cf. [Bug #12249]

Revision 54495
Added by usa (Usaku NAKAMURA) over 3 years ago

  • math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong. cf. [Bug #12249]

Revision 54495
Added by usa (Usaku NAKAMURA) over 3 years ago

  • math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong. cf. [Bug #12249]

Revision 54495
Added by usa (Usaku NAKAMURA) over 3 years ago

  • math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong. cf. [Bug #12249]

Revision 39330d6b
Added by nobu (Nobuyoshi Nakada) over 3 years ago

lgamma_r.c: fix at -0.0

  • math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows, since msvcrt does not provide it.
  • missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0). [ruby-core:74823] [Bug #12249]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54496
Added by nobu (Nobuyoshi Nakada) over 3 years ago

lgamma_r.c: fix at -0.0

  • math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows, since msvcrt does not provide it.
  • missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0). [ruby-core:74823] [Bug #12249]

Revision 54496
Added by nobu (Nobuyoshi Nakada) over 3 years ago

lgamma_r.c: fix at -0.0

  • math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows, since msvcrt does not provide it.
  • missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0). [ruby-core:74823] [Bug #12249]

Revision 54496
Added by nobu (Nobuyoshi Nakada) over 3 years ago

lgamma_r.c: fix at -0.0

  • math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows, since msvcrt does not provide it.
  • missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0). [ruby-core:74823] [Bug #12249]

Revision 54496
Added by nobu (Nobuyoshi Nakada) over 3 years ago

lgamma_r.c: fix at -0.0

  • math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows, since msvcrt does not provide it.
  • missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0). [ruby-core:74823] [Bug #12249]

Revision ea736d55
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: check lgamma_r(-0.0)

  • configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0) returns negative infinity. [Bug #12249]
  • math.c (ruby_lgamma_r): define by the configured result.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54499
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: check lgamma_r(-0.0)

  • configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0) returns negative infinity. [Bug #12249]
  • math.c (ruby_lgamma_r): define by the configured result.

Revision 54499
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: check lgamma_r(-0.0)

  • configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0) returns negative infinity. [Bug #12249]
  • math.c (ruby_lgamma_r): define by the configured result.

Revision 54499
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: check lgamma_r(-0.0)

  • configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0) returns negative infinity. [Bug #12249]
  • math.c (ruby_lgamma_r): define by the configured result.

Revision 54499
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: check lgamma_r(-0.0)

  • configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0) returns negative infinity. [Bug #12249]
  • math.c (ruby_lgamma_r): define by the configured result.

Revision 6a79276e
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: fix lgamma_r condition

  • configure.in (rb_cv_lgamma_r_m0): fix the condition for lgamma_r(-0.0). [Bug #12249]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54503
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: fix lgamma_r condition

  • configure.in (rb_cv_lgamma_r_m0): fix the condition for lgamma_r(-0.0). [Bug #12249]

Revision 54503
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: fix lgamma_r condition

  • configure.in (rb_cv_lgamma_r_m0): fix the condition for lgamma_r(-0.0). [Bug #12249]

Revision 54503
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: fix lgamma_r condition

  • configure.in (rb_cv_lgamma_r_m0): fix the condition for lgamma_r(-0.0). [Bug #12249]

Revision 54503
Added by nobu (Nobuyoshi Nakada) over 3 years ago

configure.in: fix lgamma_r condition

  • configure.in (rb_cv_lgamma_r_m0): fix the condition for lgamma_r(-0.0). [Bug #12249]

Revision e824b05b
Added by nagachika (Tomoyuki Chikanaga) over 3 years ago

merge revision(s) 54492,54494,54495,54496,54499,54503: [Backport #12249]

    * math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
      [ruby-core:74817] [Bug #12249]

    * math.c (ruby_lgamma_r): fix lgamma(-0.0) on mingw and OSX.

    * math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong.
      cf. [Bug #12249]

    * math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows,
      since msvcrt does not provide it.

    * missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0).
      [ruby-core:74823] [Bug #12249]

    * configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0)
      returns negative infinity.  [Bug #12249]

    * math.c (ruby_lgamma_r): define by the configured result.

    * configure.in (rb_cv_lgamma_r_m0): fix the condition for
      lgamma_r(-0.0).  [Bug #12249]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@54643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54643
Added by nagachika (Tomoyuki Chikanaga) over 3 years ago

merge revision(s) 54492,54494,54495,54496,54499,54503: [Backport #12249]

* math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
  [ruby-core:74817] [Bug #12249]

* math.c (ruby_lgamma_r): fix lgamma(-0.0) on mingw and OSX.

* math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong.
  cf. [Bug #12249]

* math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows,
  since msvcrt does not provide it.

* missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0).
  [ruby-core:74823] [Bug #12249]

* configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0)
  returns negative infinity.  [Bug #12249]

* math.c (ruby_lgamma_r): define by the configured result.

* configure.in (rb_cv_lgamma_r_m0): fix the condition for
  lgamma_r(-0.0).  [Bug #12249]

Revision 4eba3445
Added by usa (Usaku NAKAMURA) over 3 years ago

merge revision(s) 49913,54492,54494,54495,54496,54499,54503: [Backport #12249]

    math.c: fix tgamma on mingw

    * math.c (mingw_tgamma): tgamma(3) on mingw returns a NaN for a

big number, not infinity.
* math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
[ruby-core:74817] [Bug #12249]

    * math.c (ruby_lgamma_r): fix lgamma(-0.0) on mingw and OSX.

    * math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong.
      cf. [Bug #12249]

    * math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows,
      since msvcrt does not provide it.

    * missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0).
      [ruby-core:74823] [Bug #12249]

    * configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0)
      returns negative infinity.  [Bug #12249]

    * math.c (ruby_lgamma_r): define by the configured result.

    * configure.in (rb_cv_lgamma_r_m0): fix the condition for
      lgamma_r(-0.0).  [Bug #12249]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54687
Added by usa (Usaku NAKAMURA) over 3 years ago

merge revision(s) 49913,54492,54494,54495,54496,54499,54503: [Backport #12249]

math.c: fix tgamma on mingw

* math.c (mingw_tgamma): tgamma(3) on mingw returns a NaN for a

big number, not infinity.
* math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
[ruby-core:74817] [Bug #12249]

* math.c (ruby_lgamma_r): fix lgamma(-0.0) on mingw and OSX.

* math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong.
  cf. [Bug #12249]

* math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows,
  since msvcrt does not provide it.

* missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0).
  [ruby-core:74823] [Bug #12249]

* configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0)
  returns negative infinity.  [Bug #12249]

* math.c (ruby_lgamma_r): define by the configured result.

* configure.in (rb_cv_lgamma_r_m0): fix the condition for
  lgamma_r(-0.0).  [Bug #12249]

History

#1

Updated by usa (Usaku NAKAMURA) over 3 years ago

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

Updated by nobu (Nobuyoshi Nakada) over 3 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 3 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 3 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 3 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 3 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 3 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.

Also available in: Atom PDF