* ext/bigdecimal/bigdecimal.c (BigDecimal_to_i): update RDoc to
denote that #to_i raises FloatDomainError for Inf and NaN. * ext/bigdecimal/bigdecimal.c (BigDecimal_to_i): fast #to_i using BigDecimal_split(). * bignum.c (conv_digit): use faster ISDIGIT() assuming ASCII. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a715d95a82
commit
d1499525d5
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Fri Jan 29 01:26:53 2010 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_i): update RDoc to
|
||||||
|
denote that #to_i raises FloatDomainError for Inf and NaN.
|
||||||
|
|
||||||
|
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_i): fast #to_i using
|
||||||
|
BigDecimal_split().
|
||||||
|
|
||||||
|
* bignum.c (conv_digit): use faster ISDIGIT() assuming ASCII.
|
||||||
|
|
||||||
Fri Jan 29 00:18:54 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
Fri Jan 29 00:18:54 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* lib/cgi.rb: set autoload to CGI::HtmlExtension. [ruby-dev:40194]
|
* lib/cgi.rb: set autoload to CGI::HtmlExtension. [ruby-dev:40194]
|
||||||
|
2
bignum.c
2
bignum.c
@ -437,6 +437,8 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
|
|||||||
VALUE z;
|
VALUE z;
|
||||||
BDIGIT *zds;
|
BDIGIT *zds;
|
||||||
|
|
||||||
|
#undef ISDIGIT
|
||||||
|
#define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
|
||||||
#define conv_digit(c) \
|
#define conv_digit(c) \
|
||||||
(!ISASCII(c) ? -1 : \
|
(!ISASCII(c) ? -1 : \
|
||||||
ISDIGIT(c) ? ((c) - '0') : \
|
ISDIGIT(c) ? ((c) - '0') : \
|
||||||
|
@ -473,9 +473,11 @@ BigDecimal_check_num(Real *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE BigDecimal_split(VALUE self);
|
||||||
|
|
||||||
/* Returns the value as an integer (Fixnum or Bignum).
|
/* Returns the value as an integer (Fixnum or Bignum).
|
||||||
*
|
*
|
||||||
* If the BigNumber is infinity or NaN, returns nil.
|
* If the BigNumber is infinity or NaN, raises FloatDomainError.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_to_i(VALUE self)
|
BigDecimal_to_i(VALUE self)
|
||||||
@ -497,31 +499,24 @@ BigDecimal_to_i(VALUE self)
|
|||||||
e = VpGetSign(p)*p->frac[0];
|
e = VpGetSign(p)*p->frac[0];
|
||||||
return INT2FIX(e);
|
return INT2FIX(e);
|
||||||
}
|
}
|
||||||
str = rb_str_new(0, e+nf+2);
|
else {
|
||||||
psz = RSTRING_PTR(str);
|
VALUE a = BigDecimal_split(self);
|
||||||
|
VALUE digits = RARRAY_PTR(a)[1];
|
||||||
|
VALUE numerator = rb_funcall(digits, rb_intern("to_i"), 0);
|
||||||
|
int dpower = e - RSTRING_LEN(digits);
|
||||||
|
|
||||||
n = (e+nf-1)/nf;
|
if (VpGetSign(p) < 0) {
|
||||||
pch = psz;
|
numerator = rb_funcall(numerator, '*', 1, INT2FIX(-1));
|
||||||
if(VpGetSign(p)<0) *pch++ = '-';
|
}
|
||||||
for(i=0;i<n;++i) {
|
if (dpower < 0) {
|
||||||
b = VpBaseVal()/10;
|
return rb_funcall(numerator, rb_intern("div"), 1,
|
||||||
if(i>=(int)p->Prec) {
|
rb_funcall(INT2FIX(10), rb_intern("**"), 1,
|
||||||
while(b) {
|
INT2FIX(-dpower)));
|
||||||
*pch++ = '0';
|
}
|
||||||
b /= 10;
|
return rb_funcall(numerator, '*', 1,
|
||||||
}
|
rb_funcall(INT2FIX(10), rb_intern("**"), 1,
|
||||||
continue;
|
INT2FIX(dpower)));
|
||||||
}
|
|
||||||
v = p->frac[i];
|
|
||||||
while(b) {
|
|
||||||
j = v/b;
|
|
||||||
*pch++ = (char)(j + '0');
|
|
||||||
v -= j*b;
|
|
||||||
b /= 10;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*pch++ = 0;
|
|
||||||
return rb_cstr2inum(psz,10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a new Float object having approximately the same value as the
|
/* Returns a new Float object having approximately the same value as the
|
||||||
@ -556,8 +551,6 @@ BigDecimal_to_f(VALUE self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static VALUE BigDecimal_split(VALUE self);
|
|
||||||
|
|
||||||
/* Converts a BigDecimal to a Rational.
|
/* Converts a BigDecimal to a Rational.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user