mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (rb_num2ull): use own switch sentense.
Current implementation can't convert 18446744073709551615. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a259db72b7
commit
136c117fc1
2 changed files with 40 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Jul 7 15:16:51 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* numeric.c (rb_num2ull): use own switch sentense.
|
||||
Current implementation can't convert 18446744073709551615.
|
||||
|
||||
Thu Jul 7 06:56:15 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* cont.c (FIBER_STACK_FLAGS): workaround fix for r32420 on FreeBSD.
|
||||
|
|
37
numeric.c
37
numeric.c
|
@ -1973,10 +1973,43 @@ rb_num2ll(VALUE val)
|
|||
unsigned LONG_LONG
|
||||
rb_num2ull(VALUE val)
|
||||
{
|
||||
if (TYPE(val) == T_BIGNUM) {
|
||||
switch (TYPE(val)) {
|
||||
case T_NIL:
|
||||
rb_raise(rb_eTypeError, "no implicit conversion from nil");
|
||||
|
||||
case T_FIXNUM:
|
||||
return (LONG_LONG)FIX2ULONG(val);
|
||||
|
||||
case T_FLOAT:
|
||||
if (RFLOAT_VALUE(val) < ULLONG_MAX_PLUS_ONE
|
||||
&& RFLOAT_VALUE(val) > 0) {
|
||||
return (unsigned LONG_LONG)(RFLOAT_VALUE(val));
|
||||
}
|
||||
else {
|
||||
char buf[24];
|
||||
char *s;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%-.10g", RFLOAT_VALUE(val));
|
||||
if ((s = strchr(buf, ' ')) != 0) *s = '\0';
|
||||
rb_raise(rb_eRangeError, "float %s out of range of unsgined long long", buf);
|
||||
}
|
||||
|
||||
case T_BIGNUM:
|
||||
return rb_big2ull(val);
|
||||
|
||||
case T_STRING:
|
||||
rb_raise(rb_eTypeError, "no implicit conversion from string");
|
||||
return Qnil; /* not reached */
|
||||
|
||||
case T_TRUE:
|
||||
case T_FALSE:
|
||||
rb_raise(rb_eTypeError, "no implicit conversion from boolean");
|
||||
return Qnil; /* not reached */
|
||||
|
||||
default:
|
||||
val = rb_to_int(val);
|
||||
return NUM2ULL(val);
|
||||
}
|
||||
return (unsigned LONG_LONG)rb_num2ll(val);
|
||||
}
|
||||
|
||||
#endif /* HAVE_LONG_LONG */
|
||||
|
|
Loading…
Reference in a new issue