ruby-changes:46575
From: nobu <ko1@a...>
Date: Sat, 13 May 2017 01:12:53 +0900 (JST)
Subject: [ruby-changes:46575] nobu:r58691 (trunk): fix tgamma for inifity
nobu 2017-05-13 01:12:46 +0900 (Sat, 13 May 2017) New Revision: 58691 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58691 Log: fix tgamma for inifity * configure.in: do not use buggy tgamma() of mingw. * missing/tgamma.c (tgamma): merge fix for inifity from ruby_tgamma. since msvcr120.dll and later have tgamma, this implementation will not be used. Modified files: trunk/configure.in trunk/math.c trunk/missing/tgamma.c Index: math.c =================================================================== --- math.c (revision 58690) +++ math.c (revision 58691) @@ -778,22 +778,6 @@ math_erfc(VALUE unused_obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L778 return DBL2NUM(erfc(Get_Double(x))); } -#if defined _WIN32 -static inline double -ruby_tgamma(const double d) -{ - const double g = tgamma(d); - if (isinf(g)) { - if (d == 0.0 && signbit(d)) return -INFINITY; - } - if (isnan(g)) { - if (!signbit(d)) return INFINITY; - } - return g; -} -#define tgamma(d) ruby_tgamma(d) -#endif - #if defined LGAMMA_R_PM0_FIX static inline double ruby_lgamma_r(const double d, int *sign) Index: missing/tgamma.c =================================================================== --- missing/tgamma.c (revision 58690) +++ missing/tgamma.c (revision 58691) @@ -10,9 +10,25 @@ reference - Haruhiko Okumura: C-gengo ni https://github.com/ruby/ruby/blob/trunk/missing/tgamma.c#L10 gamma.c -- Gamma function ***********************************************************/ #include "ruby/config.h" +#include "ruby/missing.h" #include <math.h> #include <errno.h> +#ifdef _WIN32 +# include <float.h> +# if !defined __MINGW32__ || defined __NO_ISOCEXT +# ifndef isnan +# define isnan(x) _isnan(x) +# endif +# ifndef isinf +# define isinf(x) (!_finite(x) && !_isnan(x)) +# endif +# ifndef finite +# define finite(x) _finite(x) +# endif +# endif +#endif + #ifndef HAVE_LGAMMA_R #include <errno.h> @@ -54,11 +70,16 @@ double tgamma(double x) /* Gamma functi https://github.com/ruby/ruby/blob/trunk/missing/tgamma.c#L70 errno = ERANGE; return 1/x < 0 ? -HUGE_VAL : HUGE_VAL; } + if (isinf(x)) { + if (x < 0) goto domain_error; + return x; + } if (x < 0) { static double zero = 0.0; double i, f; f = modf(-x, &i); if (f == 0.0) { /* Domain Error */ + domain_error: errno = EDOM; return zero/zero; } Index: configure.in =================================================================== --- configure.in (revision 58690) +++ configure.in (revision 58691) @@ -1317,6 +1317,7 @@ main() https://github.com/ruby/ruby/blob/trunk/configure.in#L1317 ac_cv_func___builtin_setjmp=no ac_cv_func_round=no ]) + ac_cv_func_tgamma=no AC_CHECK_TYPE([NET_LUID], [], [], [@%:@include <winsock2.h> @%:@include <iphlpapi.h>]) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/