ruby-changes:45667
From: nobu <ko1@a...>
Date: Tue, 28 Feb 2017 11:58:20 +0900 (JST)
Subject: [ruby-changes:45667] nobu:r57740 (trunk): Makefile.sub: ULL_TO_DOUBLE
nobu 2017-02-28 11:58:12 +0900 (Tue, 28 Feb 2017) New Revision: 57740 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57740 Log: Makefile.sub: ULL_TO_DOUBLE * win32/Makefile.sub (config.h): define ULL_TO_DOUBLE for conversion from unsigned __int64 to double, which is not implemented in till Visual Studio.NET 2003, aka VC7.1. * bignum.c (estimate_initial_sqrt): use ULL_TO_DOUBLE if defined. * numeric.c (BDIGIT_DBL_TO_DOUBLE): ditto. Modified files: trunk/bignum.c trunk/numeric.c trunk/win32/Makefile.sub Index: numeric.c =================================================================== --- numeric.c (revision 57739) +++ numeric.c (revision 57740) @@ -5140,7 +5140,7 @@ prefix##_isqrt(argtype n) \ https://github.com/ruby/ruby/blob/trunk/numeric.c#L5140 while ((t = n/x) < (argtype)x) x = (rettype)((x + t) >> 1); \ return x; \ } \ - return (rettype)sqrt((double)n); \ + return (rettype)sqrt(argtype##_TO_DOUBLE(n)); \ } #if SIZEOF_LONG*CHAR_BIT > DBL_MANT_DIG @@ -5148,6 +5148,7 @@ prefix##_isqrt(argtype n) \ https://github.com/ruby/ruby/blob/trunk/numeric.c#L5148 #else # define RB_ULONG_IN_DOUBLE_P(n) 1 #endif +#define RB_ULONG_TO_DOUBLE(n) (double)(n) #define RB_ULONG unsigned long DEFINE_INT_SQRT(unsigned long, rb_ulong, RB_ULONG) @@ -5157,6 +5158,11 @@ DEFINE_INT_SQRT(unsigned long, rb_ulong, https://github.com/ruby/ruby/blob/trunk/numeric.c#L5158 # else # define BDIGIT_DBL_IN_DOUBLE_P(n) 1 # endif +# ifdef ULL_TO_DOUBLE +# define BDIGIT_DBL_TO_DOUBLE(n) ULL_TO_DOUBLE(n) +# else +# define BDIGIT_DBL_TO_DOUBLE(n) (double)(n) +# endif DEFINE_INT_SQRT(BDIGIT, rb_bdigit_dbl, BDIGIT_DBL) #endif Index: win32/Makefile.sub =================================================================== --- win32/Makefile.sub (revision 57739) +++ win32/Makefile.sub (revision 57740) @@ -550,6 +550,8 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/ https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L550 #define HAVE_MEMORY_H 1 !if $(MSC_VER) >= 1400 #define HAVE_LONG_LONG 1 +!else +#define ULL_TO_DOUBLE(n) ((double)(unsigned long)((n)>>32) * (1I64 << 32) + (unsigned long)(n)) !endif #define HAVE_OFF_T 1 #define SIZEOF_INT 4 Index: bignum.c =================================================================== --- bignum.c (revision 57739) +++ bignum.c (revision 57740) @@ -6765,9 +6765,15 @@ rb_big_even_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6765 unsigned long rb_ulong_isqrt(unsigned long); #if SIZEOF_BDIGIT*2 > SIZEOF_LONG BDIGIT rb_bdigit_dbl_isqrt(BDIGIT_DBL); +# ifdef ULL_TO_DOUBLE +# define BDIGIT_DBL_TO_DOUBLE(n) ULL_TO_DOUBLE(n) +# endif #else # define rb_bdigit_dbl_isqrt(x) (BDIGIT)rb_ulong_isqrt(x) #endif +#ifndef BDIGIT_DBL_TO_DOUBLE +# define BDIGIT_DBL_TO_DOUBLE(n) (double)(n) +#endif static BDIGIT * estimate_initial_sqrt(VALUE *xp, const size_t xn, const BDIGIT *nds, size_t len) @@ -6789,9 +6795,9 @@ estimate_initial_sqrt(VALUE *xp, const s https://github.com/ruby/ruby/blob/trunk/bignum.c#L6795 d <<= -rshift; d |= nds[len-dbl_per_bdig-1] >> (BITSPERDIG+rshift); } - f = sqrt((double)d); + f = sqrt(BDIGIT_DBL_TO_DOUBLE(d)); d = (BDIGIT_DBL)ceil(f); - if ((double)d == f) { + if (BDIGIT_DBL_TO_DOUBLE(d) == f) { if (lowbits || (lowbits = !bary_zero_p(nds, len-dbl_per_bdig))) ++d; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/