mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c, intern.h (rb_ull2big, rb_ll2big, rb_ull2inum, rb_ll2inum,
big2ull, rb_big2ull, rb_big2ll): use LONG_LONG macro instead of long long. * numeric.c, intern.h, ruby.h (rb_num2ll, rb_num2ull): ditto. * ruby.h: use _I64_MAX and _I64_MIN if they are defined (for VC++). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
23beb1a9dd
commit
6ba0d31e8f
5 changed files with 48 additions and 30 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Fri Mar 15 17:44:08 2002 Usaku Nakamura <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* bignum.c, intern.h (rb_ull2big, rb_ll2big, rb_ull2inum, rb_ll2inum,
|
||||||
|
big2ull, rb_big2ull, rb_big2ll): use LONG_LONG macro instead of
|
||||||
|
long long.
|
||||||
|
|
||||||
|
* numeric.c, intern.h, ruby.h (rb_num2ll, rb_num2ull): ditto.
|
||||||
|
|
||||||
|
* ruby.h: use _I64_MAX and _I64_MIN if they are defined (for VC++).
|
||||||
|
|
||||||
Fri Mar 15 14:02:43 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
Fri Mar 15 14:02:43 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||||
|
|
||||||
* ext/iconv/iconv.c: fixed document, Iconv#new is no longer an
|
* ext/iconv/iconv.c: fixed document, Iconv#new is no longer an
|
||||||
|
|
30
bignum.c
30
bignum.c
|
@ -27,7 +27,7 @@ typedef LONG_LONG BDIGIT_DBL_SIGNED;
|
||||||
#elif SIZEOF_INT*2 <= SIZEOF_LONG
|
#elif SIZEOF_INT*2 <= SIZEOF_LONG
|
||||||
typedef unsigned int BDIGIT;
|
typedef unsigned int BDIGIT;
|
||||||
typedef unsigned long BDIGIT_DBL;
|
typedef unsigned long BDIGIT_DBL;
|
||||||
typedef long long BDIGIT_DBL_SIGNED;
|
typedef LONG_LONG BDIGIT_DBL_SIGNED;
|
||||||
#else
|
#else
|
||||||
typedef unsigned short BDIGIT;
|
typedef unsigned short BDIGIT;
|
||||||
typedef unsigned long BDIGIT_DBL;
|
typedef unsigned long BDIGIT_DBL;
|
||||||
|
@ -39,7 +39,7 @@ typedef long BDIGIT_DBL_SIGNED;
|
||||||
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG)
|
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG)
|
||||||
#define DIGSPERLONG ((unsigned int)(sizeof(long)/sizeof(BDIGIT)))
|
#define DIGSPERLONG ((unsigned int)(sizeof(long)/sizeof(BDIGIT)))
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
# define DIGSPERLL ((unsigned int)(sizeof(long long)/sizeof(BDIGIT)))
|
# define DIGSPERLL ((unsigned int)(sizeof(LONG_LONG)/sizeof(BDIGIT)))
|
||||||
#endif
|
#endif
|
||||||
#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
|
#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
|
||||||
#define BIGDN(x) RSHIFT(x,BITSPERDIG)
|
#define BIGDN(x) RSHIFT(x,BITSPERDIG)
|
||||||
|
@ -514,7 +514,7 @@ rb_str_to_inum(str, base, badcheck)
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_ull2big(n)
|
rb_ull2big(n)
|
||||||
unsigned long long n;
|
unsigned LONG_LONG n;
|
||||||
{
|
{
|
||||||
BDIGIT_DBL num = n;
|
BDIGIT_DBL num = n;
|
||||||
long i = 0;
|
long i = 0;
|
||||||
|
@ -537,7 +537,7 @@ rb_ull2big(n)
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_ll2big(n)
|
rb_ll2big(n)
|
||||||
long long n;
|
LONG_LONG n;
|
||||||
{
|
{
|
||||||
long neg = 0;
|
long neg = 0;
|
||||||
VALUE big;
|
VALUE big;
|
||||||
|
@ -555,7 +555,7 @@ rb_ll2big(n)
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_ull2inum(n)
|
rb_ull2inum(n)
|
||||||
unsigned long long n;
|
unsigned LONG_LONG n;
|
||||||
{
|
{
|
||||||
if (POSFIXABLE(n)) return INT2FIX(n);
|
if (POSFIXABLE(n)) return INT2FIX(n);
|
||||||
return rb_ull2big(n);
|
return rb_ull2big(n);
|
||||||
|
@ -563,7 +563,7 @@ rb_ull2inum(n)
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_ll2inum(n)
|
rb_ll2inum(n)
|
||||||
long long n;
|
LONG_LONG n;
|
||||||
{
|
{
|
||||||
if (FIXABLE(n)) return INT2FIX(n);
|
if (FIXABLE(n)) return INT2FIX(n);
|
||||||
return rb_ll2big(n);
|
return rb_ll2big(n);
|
||||||
|
@ -716,7 +716,7 @@ rb_big2long(x)
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
|
|
||||||
static unsigned long long
|
static unsigned LONG_LONG
|
||||||
big2ull(x, type)
|
big2ull(x, type)
|
||||||
VALUE x;
|
VALUE x;
|
||||||
char *type;
|
char *type;
|
||||||
|
@ -725,7 +725,7 @@ big2ull(x, type)
|
||||||
BDIGIT_DBL num;
|
BDIGIT_DBL num;
|
||||||
BDIGIT *ds;
|
BDIGIT *ds;
|
||||||
|
|
||||||
if (len > sizeof(long long)/sizeof(BDIGIT))
|
if (len > sizeof(LONG_LONG)/sizeof(BDIGIT))
|
||||||
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
|
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
|
||||||
ds = BDIGITS(x);
|
ds = BDIGITS(x);
|
||||||
num = 0;
|
num = 0;
|
||||||
|
@ -736,27 +736,27 @@ big2ull(x, type)
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long
|
unsigned LONG_LONG
|
||||||
rb_big2ull(x)
|
rb_big2ull(x)
|
||||||
VALUE x;
|
VALUE x;
|
||||||
{
|
{
|
||||||
unsigned long long num = big2ull(x, "unsigned long long");
|
unsigned LONG_LONG num = big2ull(x, "unsigned long long");
|
||||||
|
|
||||||
if (!RBIGNUM(x)->sign) return -num;
|
if (!RBIGNUM(x)->sign) return -num;
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long
|
LONG_LONG
|
||||||
rb_big2ll(x)
|
rb_big2ll(x)
|
||||||
VALUE x;
|
VALUE x;
|
||||||
{
|
{
|
||||||
unsigned long long num = big2ull(x, "long long");
|
unsigned LONG_LONG num = big2ull(x, "long long");
|
||||||
|
|
||||||
if ((long long)num < 0 && (RBIGNUM(x)->sign
|
if ((LONG_LONG)num < 0 && (RBIGNUM(x)->sign
|
||||||
|| (long long)num != LLONG_MIN)) {
|
|| (LONG_LONG)num != LLONG_MIN)) {
|
||||||
rb_raise(rb_eRangeError, "bignum too big to convert into `long long'");
|
rb_raise(rb_eRangeError, "bignum too big to convert into `long long'");
|
||||||
}
|
}
|
||||||
if (!RBIGNUM(x)->sign) return -(long long)num;
|
if (!RBIGNUM(x)->sign) return -(LONG_LONG)num;
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
intern.h
8
intern.h
|
@ -71,10 +71,10 @@ long rb_big2long _((VALUE));
|
||||||
unsigned long rb_big2ulong _((VALUE));
|
unsigned long rb_big2ulong _((VALUE));
|
||||||
#define rb_big2uint(x) rb_big2ulong(x)
|
#define rb_big2uint(x) rb_big2ulong(x)
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
VALUE rb_ll2inum _((long long));
|
VALUE rb_ll2inum _((LONG_LONG));
|
||||||
VALUE rb_ull2inum _((unsigned long long));
|
VALUE rb_ull2inum _((unsigned LONG_LONG));
|
||||||
long long rb_big2ll _((VALUE));
|
LONG_LONG rb_big2ll _((VALUE));
|
||||||
unsigned long long rb_big2ull _((VALUE));
|
unsigned LONG_LONG rb_big2ull _((VALUE));
|
||||||
#endif /* HAVE_LONG_LONG */
|
#endif /* HAVE_LONG_LONG */
|
||||||
void rb_quad_pack _((char*,VALUE));
|
void rb_quad_pack _((char*,VALUE));
|
||||||
VALUE rb_quad_unpack _((const char*,int));
|
VALUE rb_quad_unpack _((const char*,int));
|
||||||
|
|
10
numeric.c
10
numeric.c
|
@ -871,7 +871,7 @@ rb_num2fix(val)
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
|
|
||||||
long long
|
LONG_LONG
|
||||||
rb_num2ll(val)
|
rb_num2ll(val)
|
||||||
VALUE val;
|
VALUE val;
|
||||||
{
|
{
|
||||||
|
@ -879,13 +879,13 @@ rb_num2ll(val)
|
||||||
rb_raise(rb_eTypeError, "no implicit conversion from nil");
|
rb_raise(rb_eTypeError, "no implicit conversion from nil");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FIXNUM_P(val)) return (long long)FIX2LONG(val);
|
if (FIXNUM_P(val)) return (LONG_LONG)FIX2LONG(val);
|
||||||
|
|
||||||
switch (TYPE(val)) {
|
switch (TYPE(val)) {
|
||||||
case T_FLOAT:
|
case T_FLOAT:
|
||||||
if (RFLOAT(val)->value <= (double)LLONG_MAX
|
if (RFLOAT(val)->value <= (double)LLONG_MAX
|
||||||
&& RFLOAT(val)->value >= (double)LLONG_MIN) {
|
&& RFLOAT(val)->value >= (double)LLONG_MIN) {
|
||||||
return (long long)(RFLOAT(val)->value);
|
return (LONG_LONG)(RFLOAT(val)->value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char buf[24];
|
char buf[24];
|
||||||
|
@ -914,14 +914,14 @@ rb_num2ll(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long
|
unsigned LONG_LONG
|
||||||
rb_num2ull(val)
|
rb_num2ull(val)
|
||||||
VALUE val;
|
VALUE val;
|
||||||
{
|
{
|
||||||
if (TYPE(val) == T_BIGNUM) {
|
if (TYPE(val) == T_BIGNUM) {
|
||||||
return rb_big2ull(val);
|
return rb_big2ull(val);
|
||||||
}
|
}
|
||||||
return (unsigned long long)rb_num2ll(val);
|
return (unsigned LONG_LONG)rb_num2ll(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_LONG_LONG */
|
#endif /* HAVE_LONG_LONG */
|
||||||
|
|
20
ruby.h
20
ruby.h
|
@ -90,15 +90,23 @@ typedef unsigned long ID;
|
||||||
# ifdef LONG_LONG_MAX
|
# ifdef LONG_LONG_MAX
|
||||||
# define LLONG_MAX LONG_LONG_MAX
|
# define LLONG_MAX LONG_LONG_MAX
|
||||||
# else
|
# else
|
||||||
|
# ifdef _I64_MAX
|
||||||
|
# define LLONG_MAX _I64_MAX
|
||||||
|
# else
|
||||||
/* assuming 64bit(2's complement) long long */
|
/* assuming 64bit(2's complement) long long */
|
||||||
# define LLONG_MAX 9223372036854775807LL
|
# define LLONG_MAX 9223372036854775807LL
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# ifndef LLONG_MIN
|
# ifndef LLONG_MIN
|
||||||
# ifdef LONG_LONG_MIN
|
# ifdef LONG_LONG_MIN
|
||||||
# define LLONG_MIN LONG_LONG_MIN
|
# define LLONG_MIN LONG_LONG_MIN
|
||||||
# else
|
# else
|
||||||
# define LLONG_MIN (-LLONG_MAX-1)
|
# ifdef _I64_MIN
|
||||||
|
# define LLONG_MIN _I64_MAX
|
||||||
|
# else
|
||||||
|
# define LLONG_MIN (-LLONG_MAX-1)
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -120,9 +128,9 @@ VALUE rb_uint2inum _((unsigned long));
|
||||||
#define rb_uint_new(v) rb_uint2inum(v)
|
#define rb_uint_new(v) rb_uint2inum(v)
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
VALUE rb_ll2inum _((long long));
|
VALUE rb_ll2inum _((LONG_LONG));
|
||||||
#define LL2NUM(v) rb_ll2inum(v)
|
#define LL2NUM(v) rb_ll2inum(v)
|
||||||
VALUE rb_ull2inum _((unsigned long long));
|
VALUE rb_ull2inum _((unsigned LONG_LONG));
|
||||||
#define ULL2NUM(v) rb_ull2inum(v)
|
#define ULL2NUM(v) rb_ull2inum(v)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -233,8 +241,8 @@ int rb_fix2int _((VALUE));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
long long rb_num2ll _((VALUE));
|
LONG_LONG rb_num2ll _((VALUE));
|
||||||
unsigned long long rb_num2ull _((VALUE));
|
unsigned LONG_LONG rb_num2ull _((VALUE));
|
||||||
# define NUM2LL(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2ll((VALUE)x))
|
# define NUM2LL(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2ll((VALUE)x))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue