ruby-changes:42420
From: nobu <ko1@a...>
Date: Tue, 5 Apr 2016 23:56:55 +0900 (JST)
Subject: [ruby-changes:42420] nobu:r54494 (trunk): math.c: fix lgamma
nobu 2016-04-06 00:53:32 +0900 (Wed, 06 Apr 2016) New Revision: 54494 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54494 Log: math.c: fix lgamma * math.c (ruby_lgamma_r): fix lgamma(-0.0) on mingw and OSX. Modified files: trunk/ChangeLog trunk/math.c trunk/test/ruby/test_math.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 54493) +++ ChangeLog (revision 54494) @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Wed Apr 6 00:52:00 2016 Nobuyoshi Nakada <nobu@r...> +Wed Apr 6 00:53:31 2016 Nobuyoshi Nakada <nobu@r...> + + * math.c (ruby_lgamma_r): fix lgamma(-0.0) on mingw and OSX. * math.c (ruby_tgamma): fix tgamma(-0.0) on mingw. [ruby-core:74817] [Bug #12249] Index: math.c =================================================================== --- math.c (revision 54493) +++ math.c (revision 54494) @@ -750,6 +750,22 @@ ruby_tgamma(const double d) https://github.com/ruby/ruby/blob/trunk/math.c#L750 #define tgamma(d) ruby_tgamma(d) #endif +#if defined __MINGW32__ || defined __APPLE__ +static inline double +ruby_lgamma_r(const double d, int *sign) +{ + const double g = lgamma_r(d, sign); + if (isinf(g)) { + if (d == 0.0 && signbit(d)) { + *sign = -1; + return INFINITY; + } + } + return g; +} +#define lgamma_r(d, sign) ruby_lgamma_r(d, sign) +#endif + /* * call-seq: * Math.gamma(x) -> Float Index: test/ruby/test_math.rb =================================================================== --- test/ruby/test_math.rb (revision 54493) +++ test/ruby/test_math.rb (revision 54494) @@ -275,6 +275,11 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L275 assert_float_and_int([Math.log(6), 1], Math.lgamma(4)) assert_raise(Math::DomainError) { Math.lgamma(-Float::INFINITY) } + x, sign = Math.lgamma(-0.0) + mesg = "Math.lgamma(-0.0) should be [INF, -1]" + assert_infinity(x, mesg) + assert_predicate(x, :positive?, mesg) + assert_equal(-1, sign, mesg) end def test_fixnum_to_f -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/