зеркало из https://github.com/github/ruby.git
* numeric.c (rb_num2long): accept LONG_MAX < x < LONG_MAX+1 and
LONG_MIN-1 < x < LONG_MIN as well because they are converted into the valid range of long by truncation. (rb_num2ulong): accept ULONG_MAX < x < ULONG_MAX+1 and LONG_MIN-1 < x < LONG_MIN as well. (rb_num2ll): accept LLONG_MAX < x < LLONG_MAX+1 and LLONG_MIN-1 < x < LLONG_MIN. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
5d229db887
Коммит
26202fba93
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Fri Jul 2 05:31:51 2010 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* numeric.c (rb_num2long): accept LONG_MAX < x < LONG_MAX+1 and
|
||||
LONG_MIN-1 < x < LONG_MIN as well because they are converted
|
||||
into the valid range of long by truncation.
|
||||
(rb_num2ulong): accept ULONG_MAX < x < ULONG_MAX+1 and
|
||||
LONG_MIN-1 < x < LONG_MIN as well.
|
||||
(rb_num2ll): accept LLONG_MAX < x < LLONG_MAX+1 and
|
||||
LLONG_MIN-1 < x < LLONG_MIN.
|
||||
|
||||
Thu Jul 1 23:10:25 2010 James Edward Gray II <jeg2@ruby-lang.org>
|
||||
|
||||
* lib/csv.rb: Improving documentation.
|
||||
|
|
20
numeric.c
20
numeric.c
|
@ -1683,6 +1683,10 @@ num_step(int argc, VALUE *argv, VALUE from)
|
|||
return from;
|
||||
}
|
||||
|
||||
#define LONG_MIN_MINUS_ONE ((double)LONG_MIN-1)
|
||||
#define LONG_MAX_PLUS_ONE (2*(double)(LONG_MAX/2+1))
|
||||
#define ULONG_MAX_PLUS_ONE (2*(double)(ULONG_MAX/2+1))
|
||||
|
||||
SIGNED_VALUE
|
||||
rb_num2long(VALUE val)
|
||||
{
|
||||
|
@ -1695,8 +1699,8 @@ rb_num2long(VALUE val)
|
|||
|
||||
switch (TYPE(val)) {
|
||||
case T_FLOAT:
|
||||
if (RFLOAT_VALUE(val) <= (double)LONG_MAX
|
||||
&& RFLOAT_VALUE(val) >= (double)LONG_MIN) {
|
||||
if (RFLOAT_VALUE(val) < LONG_MAX_PLUS_ONE
|
||||
&& RFLOAT_VALUE(val) > LONG_MIN_MINUS_ONE) {
|
||||
return (SIGNED_VALUE)(RFLOAT_VALUE(val));
|
||||
}
|
||||
else {
|
||||
|
@ -1729,8 +1733,8 @@ rb_num2ulong(VALUE val)
|
|||
|
||||
switch (TYPE(val)) {
|
||||
case T_FLOAT:
|
||||
if (RFLOAT_VALUE(val) <= (double)ULONG_MAX
|
||||
&& RFLOAT_VALUE(val) >= (double)LONG_MIN) {
|
||||
if (RFLOAT_VALUE(val) < ULONG_MAX_PLUS_ONE
|
||||
&& RFLOAT_VALUE(val) > LONG_MIN_MINUS_ONE) {
|
||||
return (VALUE)RFLOAT_VALUE(val);
|
||||
}
|
||||
else {
|
||||
|
@ -1853,6 +1857,10 @@ rb_num2fix(VALUE val)
|
|||
|
||||
#if HAVE_LONG_LONG
|
||||
|
||||
#define LLONG_MIN_MINUS_ONE ((double)LLONG_MIN-1)
|
||||
#define LLONG_MAX_PLUS_ONE (2*(double)(LLONG_MAX/2+1))
|
||||
#define ULLONG_MAX_PLUS_ONE (2*(double)(ULLONG_MAX/2+1))
|
||||
|
||||
LONG_LONG
|
||||
rb_num2ll(VALUE val)
|
||||
{
|
||||
|
@ -1864,8 +1872,8 @@ rb_num2ll(VALUE val)
|
|||
|
||||
switch (TYPE(val)) {
|
||||
case T_FLOAT:
|
||||
if (RFLOAT_VALUE(val) <= (double)LLONG_MAX
|
||||
&& RFLOAT_VALUE(val) >= (double)LLONG_MIN) {
|
||||
if (RFLOAT_VALUE(val) < LLONG_MAX_PLUS_ONE
|
||||
&& RFLOAT_VALUE(val) > LLONG_MIN_MINUS_ONE) {
|
||||
return (LONG_LONG)(RFLOAT_VALUE(val));
|
||||
}
|
||||
else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче