2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
bignum.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Fri Jun 10 00:48:55 JST 1994
|
|
|
|
|
2003-01-16 02:34:03 -05:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
2000-05-01 05:42:38 -04:00
|
|
|
|
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-05-14 02:22:31 -04:00
|
|
|
#include "ruby.h"
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <math.h>
|
1999-01-19 23:59:39 -05:00
|
|
|
#include <ctype.h>
|
2003-12-22 03:23:55 -05:00
|
|
|
#ifdef HAVE_IEEEFP_H
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_cBignum;
|
2000-06-04 11:32:19 -04:00
|
|
|
|
|
|
|
#if defined __MINGW32__
|
|
|
|
#define USHORT _USHORT
|
|
|
|
#endif
|
|
|
|
|
2000-10-31 03:37:47 -05:00
|
|
|
#define BDIGITS(x) ((BDIGIT*)RBIGNUM(x)->digits)
|
2002-04-10 04:45:26 -04:00
|
|
|
#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
|
2000-11-01 03:49:40 -05:00
|
|
|
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG)
|
2002-04-10 04:45:26 -04:00
|
|
|
#define DIGSPERLONG ((unsigned int)(SIZEOF_LONG/SIZEOF_BDIGITS))
|
2002-03-14 01:23:46 -05:00
|
|
|
#if HAVE_LONG_LONG
|
2002-04-10 04:45:26 -04:00
|
|
|
# define DIGSPERLL ((unsigned int)(SIZEOF_LONG_LONG/SIZEOF_BDIGITS))
|
2002-03-14 01:23:46 -05:00
|
|
|
#endif
|
2000-11-01 03:49:40 -05:00
|
|
|
#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
|
1999-12-01 04:24:48 -05:00
|
|
|
#define BIGDN(x) RSHIFT(x,BITSPERDIG)
|
2000-10-31 03:37:47 -05:00
|
|
|
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
|
2003-01-14 02:45:19 -05:00
|
|
|
#define BDIGMAX ((BDIGIT)-1)
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-04-09 02:44:34 -04:00
|
|
|
#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
bignew_1(VALUE klass, long len, int sign)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
NEWOBJ(big, struct RBignum);
|
1999-01-19 23:59:39 -05:00
|
|
|
OBJSETUP(big, klass, T_BIGNUM);
|
2005-10-21 02:28:41 -04:00
|
|
|
big->sign = sign?1:0;
|
1998-01-16 07:13:05 -05:00
|
|
|
big->len = len;
|
2000-10-31 03:37:47 -05:00
|
|
|
big->digits = ALLOC_N(BDIGIT, len);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return (VALUE)big;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#define bignew(len,sign) bignew_1(rb_cBignum,len,sign)
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_clone(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE z = bignew_1(CLASS_OF(x), RBIGNUM(x)->len, RBIGNUM(x)->sign);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-10-31 03:37:47 -05:00
|
|
|
MEMCPY(BDIGITS(z), BDIGITS(x), BDIGIT, RBIGNUM(x)->len);
|
1998-01-16 07:19:22 -05:00
|
|
|
return z;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2005-06-30 02:20:09 -04:00
|
|
|
/* modify a bignum by 2's complement */
|
2002-02-22 05:28:47 -05:00
|
|
|
static void
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
long i = RBIGNUM(x)->len;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds = BDIGITS(x);
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (i--) ds[i] = ~ds[i];
|
|
|
|
i = 0; num = 1;
|
|
|
|
do {
|
1999-01-19 23:59:39 -05:00
|
|
|
num += ds[i];
|
1998-01-16 07:13:05 -05:00
|
|
|
ds[i++] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
1998-01-16 07:19:22 -05:00
|
|
|
} while (i < RBIGNUM(x)->len);
|
2005-06-30 02:20:09 -04:00
|
|
|
if (num != 0) {
|
2002-08-12 03:21:25 -04:00
|
|
|
REALLOC_N(RBIGNUM(x)->digits, BDIGIT, ++RBIGNUM(x)->len);
|
1998-01-16 07:13:05 -05:00
|
|
|
ds = BDIGITS(x);
|
2005-06-30 02:20:09 -04:00
|
|
|
ds[RBIGNUM(x)->len-1] = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-22 05:28:47 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_2comp(VALUE x) /* get 2's complement */
|
2002-02-22 05:28:47 -05:00
|
|
|
{
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(x);
|
2002-02-22 05:28:47 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
bignorm(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-02-22 00:26:33 -05:00
|
|
|
if (FIXNUM_P(x)) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
else if (TYPE(x) == T_BIGNUM) {
|
2000-07-12 02:06:50 -04:00
|
|
|
long len = RBIGNUM(x)->len;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds = BDIGITS(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-12 02:06:50 -04:00
|
|
|
while (len-- && !ds[len]) ;
|
2005-06-07 22:16:35 -04:00
|
|
|
RBIGNUM(x)->len = ++len;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-06-07 22:16:35 -04:00
|
|
|
if (len*SIZEOF_BDIGITS <= sizeof(VALUE)) {
|
2006-07-11 01:00:02 -04:00
|
|
|
SIGNED_VALUE num = 0;
|
2000-07-12 02:06:50 -04:00
|
|
|
while (len--) {
|
|
|
|
num = BIGUP(num) + ds[len];
|
|
|
|
}
|
|
|
|
if (num >= 0) {
|
|
|
|
if (RBIGNUM(x)->sign) {
|
2002-08-21 11:47:54 -04:00
|
|
|
if (POSFIXABLE(num)) return LONG2FIX(num);
|
2000-07-12 02:06:50 -04:00
|
|
|
}
|
2002-08-21 11:47:54 -04:00
|
|
|
else if (NEGFIXABLE(-(long)num)) return LONG2FIX(-(long)num);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
return x;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_norm(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return bignorm(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2006-07-11 01:00:02 -04:00
|
|
|
rb_uint2big(VALUE n)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num = n;
|
2000-10-31 03:37:47 -05:00
|
|
|
long i = 0;
|
|
|
|
BDIGIT *digits;
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE big;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
big = bignew(DIGSPERLONG, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
digits = BDIGITS(big);
|
2000-01-04 23:41:21 -05:00
|
|
|
while (i < DIGSPERLONG) {
|
2000-10-31 03:37:47 -05:00
|
|
|
digits[i++] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
i = DIGSPERLONG;
|
2002-08-13 05:21:18 -04:00
|
|
|
while (--i && !digits[i]) ;
|
1998-01-16 07:19:22 -05:00
|
|
|
RBIGNUM(big)->len = i+1;
|
|
|
|
return big;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2006-07-11 01:00:02 -04:00
|
|
|
rb_int2big(SIGNED_VALUE n)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
long neg = 0;
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE big;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
n = -n;
|
|
|
|
neg = 1;
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
big = rb_uint2big(n);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (neg) {
|
1998-01-16 07:19:22 -05:00
|
|
|
RBIGNUM(big)->sign = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
return big;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2006-07-11 01:00:02 -04:00
|
|
|
rb_uint2inum(VALUE n)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
if (POSFIXABLE(n)) return LONG2FIX(n);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_uint2big(n);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2006-07-11 01:00:02 -04:00
|
|
|
rb_int2inum(SIGNED_VALUE n)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
if (FIXABLE(n)) return LONG2FIX(n);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_int2big(n);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-02-13 04:01:11 -05:00
|
|
|
#ifdef HAVE_LONG_LONG
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_quad_pack(char *buf, VALUE val)
|
2002-02-13 04:01:11 -05:00
|
|
|
{
|
|
|
|
LONG_LONG q;
|
|
|
|
|
|
|
|
val = rb_to_int(val);
|
|
|
|
if (FIXNUM_P(val)) {
|
|
|
|
q = FIX2LONG(val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
long len = RBIGNUM(val)->len;
|
|
|
|
BDIGIT *ds;
|
|
|
|
|
2004-01-22 13:06:38 -05:00
|
|
|
if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) {
|
2006-07-11 02:47:09 -04:00
|
|
|
len = SIZEOF_LONG_LONG/SIZEOF_BDIGITS;
|
2004-01-22 13:06:38 -05:00
|
|
|
}
|
2002-02-13 04:01:11 -05:00
|
|
|
ds = BDIGITS(val);
|
|
|
|
q = 0;
|
|
|
|
while (len--) {
|
|
|
|
q = BIGUP(q);
|
|
|
|
q += ds[len];
|
|
|
|
}
|
2003-05-25 10:48:26 -04:00
|
|
|
if (!RBIGNUM(val)->sign) q = -q;
|
2002-02-13 04:01:11 -05:00
|
|
|
}
|
2002-04-10 04:45:26 -04:00
|
|
|
memcpy(buf, (char*)&q, SIZEOF_LONG_LONG);
|
2002-02-13 04:01:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_quad_unpack(const char *buf, int sign)
|
2002-02-13 04:01:11 -05:00
|
|
|
{
|
|
|
|
unsigned LONG_LONG q;
|
|
|
|
long neg = 0;
|
2002-08-21 11:47:54 -04:00
|
|
|
long i;
|
2002-02-13 04:01:11 -05:00
|
|
|
BDIGIT *digits;
|
|
|
|
VALUE big;
|
|
|
|
|
2002-04-10 04:45:26 -04:00
|
|
|
memcpy(&q, buf, SIZEOF_LONG_LONG);
|
2002-02-13 04:01:11 -05:00
|
|
|
if (sign) {
|
2002-08-21 11:47:54 -04:00
|
|
|
if (FIXABLE((LONG_LONG)q)) return LONG2FIX((LONG_LONG)q);
|
2002-02-13 04:01:11 -05:00
|
|
|
if ((LONG_LONG)q < 0) {
|
|
|
|
q = -(LONG_LONG)q;
|
|
|
|
neg = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-08-21 11:47:54 -04:00
|
|
|
if (POSFIXABLE(q)) return LONG2FIX(q);
|
2002-02-13 04:01:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2002-11-19 03:07:51 -05:00
|
|
|
big = bignew(DIGSPERLL, 1);
|
2002-02-13 04:01:11 -05:00
|
|
|
digits = BDIGITS(big);
|
2002-11-19 03:07:51 -05:00
|
|
|
while (i < DIGSPERLL) {
|
2002-02-13 04:01:11 -05:00
|
|
|
digits[i++] = BIGLO(q);
|
|
|
|
q = BIGDN(q);
|
|
|
|
}
|
|
|
|
|
2002-11-19 03:07:51 -05:00
|
|
|
i = DIGSPERLL;
|
2002-02-13 04:01:11 -05:00
|
|
|
while (i-- && !digits[i]) ;
|
|
|
|
RBIGNUM(big)->len = i+1;
|
|
|
|
|
|
|
|
if (neg) {
|
|
|
|
RBIGNUM(big)->sign = 0;
|
|
|
|
}
|
|
|
|
return bignorm(big);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define QUAD_SIZE 8
|
|
|
|
|
|
|
|
void
|
2006-03-01 05:06:03 -05:00
|
|
|
rb_quad_pack(char *buf, VALUE val)
|
2002-02-13 04:01:11 -05:00
|
|
|
{
|
|
|
|
long len;
|
|
|
|
|
|
|
|
memset(buf, 0, QUAD_SIZE);
|
|
|
|
val = rb_to_int(val);
|
|
|
|
if (FIXNUM_P(val)) {
|
2002-02-13 04:53:17 -05:00
|
|
|
val = rb_int2big(FIX2LONG(val));
|
2002-02-13 04:01:11 -05:00
|
|
|
}
|
2002-04-10 04:45:26 -04:00
|
|
|
len = RBIGNUM(val)->len * SIZEOF_BDIGITS;
|
2003-12-26 10:34:33 -05:00
|
|
|
if (len > QUAD_SIZE) {
|
|
|
|
rb_raise(rb_eRangeError, "bignum too big to convert into `quad int'");
|
|
|
|
}
|
2002-02-13 04:01:11 -05:00
|
|
|
memcpy(buf, (char*)BDIGITS(val), len);
|
2002-02-13 04:53:17 -05:00
|
|
|
if (!RBIGNUM(val)->sign) {
|
|
|
|
len = QUAD_SIZE;
|
|
|
|
while (len--) {
|
2002-03-25 22:01:30 -05:00
|
|
|
*buf = ~*buf;
|
2002-03-22 02:26:42 -05:00
|
|
|
buf++;
|
2002-02-13 04:53:17 -05:00
|
|
|
}
|
|
|
|
}
|
2002-02-13 04:01:11 -05:00
|
|
|
}
|
|
|
|
|
2002-04-10 04:45:26 -04:00
|
|
|
#define BNEG(b) (RSHIFT(((BDIGIT*)b)[QUAD_SIZE/SIZEOF_BDIGITS-1],BITSPERDIG-1) != 0)
|
2002-02-13 04:53:17 -05:00
|
|
|
|
2002-02-13 04:01:11 -05:00
|
|
|
VALUE
|
2006-03-01 05:06:03 -05:00
|
|
|
rb_quad_unpack(const char *buf, int sign)
|
2002-02-13 04:01:11 -05:00
|
|
|
{
|
2002-04-10 04:45:26 -04:00
|
|
|
VALUE big = bignew(QUAD_SIZE/SIZEOF_BDIGITS, 1);
|
2002-02-13 04:01:11 -05:00
|
|
|
|
|
|
|
memcpy((char*)BDIGITS(big), buf, QUAD_SIZE);
|
2002-02-13 04:53:17 -05:00
|
|
|
if (sign && BNEG(buf)) {
|
|
|
|
long len = QUAD_SIZE;
|
|
|
|
char *tmp = (char*)BDIGITS(big);
|
|
|
|
|
2002-02-13 04:01:11 -05:00
|
|
|
RBIGNUM(big)->sign = 0;
|
2002-02-13 04:53:17 -05:00
|
|
|
while (len--) {
|
2002-03-22 02:26:42 -05:00
|
|
|
*tmp = ~*tmp;
|
|
|
|
tmp++;
|
2002-02-13 04:53:17 -05:00
|
|
|
}
|
2002-02-13 04:01:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return bignorm(big);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_cstr_to_inum(const char *str, int base, int badcheck)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-01-04 23:41:21 -05:00
|
|
|
const char *s = str;
|
|
|
|
char *end;
|
2003-07-24 14:33:50 -04:00
|
|
|
char sign = 1, nondigit = 0;
|
|
|
|
int c;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num;
|
1999-08-13 01:45:20 -04:00
|
|
|
long len, blen = 1;
|
|
|
|
long i;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE z;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *zds;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-10-17 03:27:00 -04:00
|
|
|
if (!str) {
|
|
|
|
if (badcheck) goto bad;
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
2006-06-27 12:15:22 -04:00
|
|
|
while (ISSPACE(*str)) str++;
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2000-12-22 04:00:23 -05:00
|
|
|
if (str[0] == '+') {
|
1999-01-19 23:59:39 -05:00
|
|
|
str++;
|
|
|
|
}
|
2000-12-22 04:00:23 -05:00
|
|
|
else if (str[0] == '-') {
|
1998-01-16 07:13:05 -05:00
|
|
|
str++;
|
|
|
|
sign = 0;
|
|
|
|
}
|
2001-03-13 23:45:46 -05:00
|
|
|
if (str[0] == '+' || str[0] == '-') {
|
|
|
|
if (badcheck) goto bad;
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
2002-02-01 05:23:22 -05:00
|
|
|
if (base <= 0) {
|
2000-12-22 04:00:23 -05:00
|
|
|
if (str[0] == '0') {
|
2002-08-16 02:39:27 -04:00
|
|
|
switch (str[1]) {
|
|
|
|
case 'x': case 'X':
|
1998-01-16 07:13:05 -05:00
|
|
|
base = 16;
|
2002-08-16 02:39:27 -04:00
|
|
|
break;
|
|
|
|
case 'b': case 'B':
|
1999-08-13 01:45:20 -04:00
|
|
|
base = 2;
|
2002-08-16 02:39:27 -04:00
|
|
|
break;
|
|
|
|
case 'o': case 'O':
|
|
|
|
base = 8;
|
|
|
|
break;
|
|
|
|
case 'd': case 'D':
|
|
|
|
base = 10;
|
|
|
|
break;
|
|
|
|
default:
|
1998-01-16 07:13:05 -05:00
|
|
|
base = 8;
|
|
|
|
}
|
|
|
|
}
|
2002-02-01 05:23:22 -05:00
|
|
|
else if (base < -1) {
|
|
|
|
base = -base;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
else {
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
}
|
2002-08-16 02:39:27 -04:00
|
|
|
switch (base) {
|
|
|
|
case 2:
|
|
|
|
len = 1;
|
|
|
|
if (str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) {
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
break;
|
2003-04-14 02:54:27 -04:00
|
|
|
case 3:
|
|
|
|
len = 2;
|
|
|
|
break;
|
2002-08-16 02:39:27 -04:00
|
|
|
case 8:
|
|
|
|
if (str[0] == '0' && (str[1] == 'o'||str[1] == 'O')) {
|
1999-01-19 23:59:39 -05:00
|
|
|
str += 2;
|
|
|
|
}
|
2003-04-14 02:54:27 -04:00
|
|
|
case 4: case 5: case 6: case 7:
|
|
|
|
len = 3;
|
2002-08-16 02:39:27 -04:00
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
if (str[0] == '0' && (str[1] == 'd'||str[1] == 'D')) {
|
1999-08-13 01:45:20 -04:00
|
|
|
str += 2;
|
|
|
|
}
|
2003-04-21 05:36:31 -04:00
|
|
|
case 9: case 11: case 12: case 13: case 14: case 15:
|
2003-04-14 02:54:27 -04:00
|
|
|
len = 4;
|
2002-08-16 02:39:27 -04:00
|
|
|
break;
|
|
|
|
case 16:
|
2001-12-26 12:01:20 -05:00
|
|
|
len = 4;
|
2002-08-16 02:39:27 -04:00
|
|
|
if (str[0] == '0' && (str[1] == 'x'||str[1] == 'X')) {
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
break;
|
2003-04-14 02:54:27 -04:00
|
|
|
default:
|
|
|
|
if (base < 2 || 36 < base) {
|
|
|
|
rb_raise(rb_eArgError, "illegal radix %d", base);
|
|
|
|
}
|
|
|
|
if (base <= 32) {
|
|
|
|
len = 5;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = 6;
|
|
|
|
}
|
|
|
|
break;
|
2001-12-26 12:01:20 -05:00
|
|
|
}
|
2003-01-18 00:53:53 -05:00
|
|
|
if (*str == '0') { /* squeeze preceeding 0s */
|
|
|
|
while (*++str == '0');
|
|
|
|
--str;
|
|
|
|
}
|
2001-12-26 12:01:20 -05:00
|
|
|
len *= strlen(str)*sizeof(char);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (len <= (sizeof(VALUE)*CHAR_BIT)) {
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
unsigned long val = strtoul(str, &end, base);
|
2000-01-04 23:41:21 -05:00
|
|
|
|
2006-06-27 12:15:22 -04:00
|
|
|
if (str < end && *end == '_') goto bigparse;
|
2000-01-04 23:41:21 -05:00
|
|
|
if (badcheck) {
|
2002-01-04 09:15:33 -05:00
|
|
|
if (end == str) goto bad; /* no number */
|
2002-01-15 21:20:25 -05:00
|
|
|
while (*end && ISSPACE(*end)) end++;
|
2003-04-14 02:54:27 -04:00
|
|
|
if (*end) goto bad; /* trailing garbage */
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (POSFIXABLE(val)) {
|
2002-08-21 11:47:54 -04:00
|
|
|
if (sign) return LONG2FIX(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
else {
|
1999-01-19 23:59:39 -05:00
|
|
|
long result = -(long)val;
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(result);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE big = rb_uint2big(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
RBIGNUM(big)->sign = sign;
|
2002-08-13 05:21:18 -04:00
|
|
|
return bignorm(big);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
2000-12-21 22:22:25 -05:00
|
|
|
bigparse:
|
1998-01-16 07:19:22 -05:00
|
|
|
len = (len/BITSPERDIG)+1;
|
2000-12-21 22:22:25 -05:00
|
|
|
if (badcheck && *str == '_') goto bad;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
z = bignew(len, sign);
|
|
|
|
zds = BDIGITS(z);
|
|
|
|
for (i=len;i--;) zds[i]=0;
|
|
|
|
while (c = *str++) {
|
2003-04-14 02:54:27 -04:00
|
|
|
if (c == '_') {
|
2002-02-01 05:23:22 -05:00
|
|
|
if (badcheck) {
|
|
|
|
if (nondigit) goto bad;
|
|
|
|
nondigit = c;
|
|
|
|
}
|
2000-12-21 22:22:25 -05:00
|
|
|
continue;
|
2003-04-14 02:54:27 -04:00
|
|
|
}
|
2004-05-07 04:44:24 -04:00
|
|
|
else if (!ISASCII(c)) {
|
|
|
|
break;
|
|
|
|
}
|
2003-04-14 02:54:27 -04:00
|
|
|
else if (isdigit(c)) {
|
|
|
|
c -= '0';
|
|
|
|
}
|
|
|
|
else if (islower(c)) {
|
|
|
|
c -= 'a' - 10;
|
|
|
|
}
|
|
|
|
else if (isupper(c)) {
|
|
|
|
c -= 'A' - 10;
|
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c >= base) break;
|
2003-04-14 02:54:27 -04:00
|
|
|
nondigit = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
i = 0;
|
|
|
|
num = c;
|
|
|
|
for (;;) {
|
|
|
|
while (i<blen) {
|
2000-11-01 03:49:40 -05:00
|
|
|
num += (BDIGIT_DBL)zds[i]*base;
|
1998-01-16 07:13:05 -05:00
|
|
|
zds[i++] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
}
|
|
|
|
if (num) {
|
|
|
|
blen++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-25 01:29:27 -05:00
|
|
|
if (badcheck) {
|
|
|
|
str--;
|
|
|
|
if (s+1 < str && str[-1] == '_') goto bad;
|
2001-12-26 12:01:20 -05:00
|
|
|
while (*str && ISSPACE(*str)) str++;
|
2003-04-14 02:54:27 -04:00
|
|
|
if (*str) {
|
|
|
|
bad:
|
|
|
|
rb_invalid_str(s, "Integer");
|
|
|
|
}
|
2000-12-25 01:29:27 -05:00
|
|
|
}
|
2000-01-04 23:41:21 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_str_to_inum(VALUE str, int base, int badcheck)
|
2000-01-04 23:41:21 -05:00
|
|
|
{
|
|
|
|
char *s;
|
2002-08-21 11:47:54 -04:00
|
|
|
long len;
|
2000-01-04 23:41:21 -05:00
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
StringValue(str);
|
2003-07-20 13:17:52 -04:00
|
|
|
if (badcheck) {
|
|
|
|
s = StringValueCStr(str);
|
|
|
|
}
|
|
|
|
else {
|
2006-08-31 06:47:44 -04:00
|
|
|
s = RSTRING_PTR(str);
|
2003-07-20 13:17:52 -04:00
|
|
|
}
|
2002-10-17 03:27:00 -04:00
|
|
|
if (s) {
|
2006-08-31 06:47:44 -04:00
|
|
|
len = RSTRING_LEN(str);
|
2002-10-17 03:27:00 -04:00
|
|
|
if (s[len]) { /* no sentinel somehow */
|
|
|
|
char *p = ALLOCA_N(char, len+1);
|
|
|
|
|
|
|
|
MEMCPY(p, s, char, len);
|
|
|
|
p[len] = '\0';
|
|
|
|
s = p;
|
|
|
|
}
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
2002-02-01 05:23:22 -05:00
|
|
|
return rb_cstr_to_inum(s, base, badcheck);
|
|
|
|
}
|
|
|
|
|
2002-03-14 01:23:46 -05:00
|
|
|
#if HAVE_LONG_LONG
|
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_ull2big(unsigned LONG_LONG n)
|
2002-03-14 01:23:46 -05:00
|
|
|
{
|
|
|
|
BDIGIT_DBL num = n;
|
|
|
|
long i = 0;
|
|
|
|
BDIGIT *digits;
|
|
|
|
VALUE big;
|
|
|
|
|
|
|
|
big = bignew(DIGSPERLL, 1);
|
|
|
|
digits = BDIGITS(big);
|
|
|
|
while (i < DIGSPERLL) {
|
|
|
|
digits[i++] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = DIGSPERLL;
|
|
|
|
while (i-- && !digits[i]) ;
|
|
|
|
RBIGNUM(big)->len = i+1;
|
|
|
|
return big;
|
|
|
|
}
|
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_ll2big(LONG_LONG n)
|
2002-03-14 01:23:46 -05:00
|
|
|
{
|
|
|
|
long neg = 0;
|
|
|
|
VALUE big;
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
n = -n;
|
|
|
|
neg = 1;
|
|
|
|
}
|
|
|
|
big = rb_ull2big(n);
|
|
|
|
if (neg) {
|
|
|
|
RBIGNUM(big)->sign = 0;
|
|
|
|
}
|
|
|
|
return big;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_ull2inum(unsigned LONG_LONG n)
|
2002-03-14 01:23:46 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
if (POSFIXABLE(n)) return LONG2FIX(n);
|
2002-03-14 01:23:46 -05:00
|
|
|
return rb_ull2big(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_ll2inum(LONG_LONG n)
|
2002-03-14 01:23:46 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
if (FIXABLE(n)) return LONG2FIX(n);
|
2002-03-14 01:23:46 -05:00
|
|
|
return rb_ll2big(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LONG_LONG */
|
|
|
|
|
2002-02-01 05:23:22 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_cstr2inum(const char *str, int base)
|
2002-02-01 05:23:22 -05:00
|
|
|
{
|
|
|
|
return rb_cstr_to_inum(str, base, base==0);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_str2inum(VALUE str, int base)
|
2002-02-01 05:23:22 -05:00
|
|
|
{
|
|
|
|
return rb_str_to_inum(str, base, base==0);
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
|
2003-04-14 02:54:27 -04:00
|
|
|
const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big2str(VALUE x, int base)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-21 00:22:54 -04:00
|
|
|
volatile VALUE t;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds;
|
|
|
|
long i, j, hbase;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE ss;
|
1999-01-19 23:59:39 -05:00
|
|
|
char *s, c;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (FIXNUM_P(x)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_fix2str(x, base);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-04-09 02:44:34 -04:00
|
|
|
if (BIGZEROP(x)) {
|
2002-08-19 01:56:09 -04:00
|
|
|
return rb_str_new2("0");
|
|
|
|
}
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
i = RBIGNUM(x)->len;
|
2003-04-14 02:54:27 -04:00
|
|
|
j = SIZEOF_BDIGITS*CHAR_BIT*i;
|
|
|
|
switch (base) {
|
|
|
|
case 2: break;
|
|
|
|
case 3:
|
|
|
|
j = j * 647L / 1024;
|
|
|
|
break;
|
|
|
|
case 4: case 5: case 6: case 7:
|
|
|
|
j /= 2;
|
|
|
|
break;
|
|
|
|
case 8: case 9:
|
|
|
|
j /= 3;
|
|
|
|
break;
|
|
|
|
case 10: case 11: case 12: case 13: case 14: case 15:
|
|
|
|
j = j * 241L / 800;
|
|
|
|
break;
|
|
|
|
case 16: case 17: case 18: case 19: case 20: case 21:
|
|
|
|
case 22: case 23: case 24: case 25: case 26: case 27:
|
|
|
|
case 28: case 29: case 30: case 31:
|
|
|
|
j /= 4;
|
|
|
|
break;
|
|
|
|
case 32: case 33: case 34: case 35: case 36:
|
|
|
|
j /= 5;
|
|
|
|
break;
|
|
|
|
default:
|
2001-11-19 00:03:03 -05:00
|
|
|
rb_raise(rb_eArgError, "illegal radix %d", base);
|
2003-04-14 02:54:27 -04:00
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-04-14 02:54:27 -04:00
|
|
|
j += 2;
|
2003-07-09 18:28:42 -04:00
|
|
|
|
2003-04-14 02:54:27 -04:00
|
|
|
hbase = base * base;
|
2003-07-09 18:28:42 -04:00
|
|
|
#if SIZEOF_BDIGITS > 2
|
2003-04-14 02:54:27 -04:00
|
|
|
hbase *= hbase;
|
2003-07-09 18:28:42 -04:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
t = rb_big_clone(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
ds = BDIGITS(t);
|
1999-01-19 23:59:39 -05:00
|
|
|
ss = rb_str_new(0, j);
|
2006-08-31 06:47:44 -04:00
|
|
|
s = RSTRING_PTR(ss);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
s[0] = RBIGNUM(x)->sign ? '+' : '-';
|
1998-01-16 07:13:05 -05:00
|
|
|
while (i && j) {
|
1999-08-13 01:45:20 -04:00
|
|
|
long k = i;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num = 0;
|
2000-10-31 03:37:47 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
while (k--) {
|
|
|
|
num = BIGUP(num) + ds[k];
|
2000-10-31 03:37:47 -05:00
|
|
|
ds[k] = (BDIGIT)(num / hbase);
|
1998-01-16 07:13:05 -05:00
|
|
|
num %= hbase;
|
|
|
|
}
|
|
|
|
if (ds[i-1] == 0) i--;
|
2003-07-09 18:28:42 -04:00
|
|
|
k = SIZEOF_BDIGITS;
|
1998-01-16 07:13:05 -05:00
|
|
|
while (k--) {
|
1999-01-19 23:59:39 -05:00
|
|
|
c = (char)(num % base);
|
2003-04-14 02:54:27 -04:00
|
|
|
s[--j] = ruby_digitmap[(int)c];
|
1998-01-16 07:13:05 -05:00
|
|
|
num /= base;
|
|
|
|
if (i == 0 && num == 0) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (s[j] == '0') j++;
|
2006-08-31 06:47:44 -04:00
|
|
|
i = RSTRING_LEN(ss)-(RBIGNUM(x)->sign?j:j-1);
|
|
|
|
memmove(RBIGNUM(x)->sign?s:s+1, s+j, i);
|
|
|
|
rb_str_set_len(ss, i);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.to_s(base=10) => string
|
|
|
|
*
|
|
|
|
* Returns a string containing the representation of <i>big</i> radix
|
|
|
|
* <i>base</i> (2 through 36).
|
|
|
|
*
|
|
|
|
* 12345654321.to_s #=> "12345654321"
|
|
|
|
* 12345654321.to_s(2) #=> "1011011111110110111011110000110001"
|
|
|
|
* 12345654321.to_s(8) #=> "133766736061"
|
|
|
|
* 12345654321.to_s(16) #=> "2dfdbbc31"
|
|
|
|
* 78546939656932.to_s(36) #=> "rubyrules"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_to_s(int argc, VALUE *argv, VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-11-19 00:03:03 -05:00
|
|
|
VALUE b;
|
|
|
|
int base;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "01", &b);
|
|
|
|
if (argc == 0) base = 10;
|
|
|
|
else base = NUM2INT(b);
|
|
|
|
return rb_big2str(x, base);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
static VALUE
|
2005-10-21 02:28:41 -04:00
|
|
|
big2ulong(VALUE x, const char *type, int check)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
long len = RBIGNUM(x)->len;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
if (len > SIZEOF_VALUE/SIZEOF_BDIGITS) {
|
2004-01-22 13:06:38 -05:00
|
|
|
if (check)
|
|
|
|
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
|
2006-07-11 02:47:09 -04:00
|
|
|
len = SIZEOF_VALUE/SIZEOF_BDIGITS;
|
2004-01-22 13:06:38 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
ds = BDIGITS(x);
|
|
|
|
num = 0;
|
|
|
|
while (len--) {
|
|
|
|
num = BIGUP(num);
|
|
|
|
num += ds[len];
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big2ulong_pack(VALUE x)
|
2004-01-22 13:06:38 -05:00
|
|
|
{
|
2006-07-11 02:47:09 -04:00
|
|
|
VALUE num = big2ulong(x, "unsigned long", Qfalse);
|
2004-01-22 13:06:38 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
|
|
|
return -num;
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big2ulong(VALUE x)
|
2000-01-04 23:41:21 -05:00
|
|
|
{
|
2006-07-11 02:47:09 -04:00
|
|
|
VALUE num = big2ulong(x, "unsigned long", Qtrue);
|
2000-01-04 23:41:21 -05:00
|
|
|
|
2003-10-09 13:45:53 -04:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
2006-07-11 02:47:09 -04:00
|
|
|
if ((SIGNED_VALUE)num < 0) {
|
2003-10-09 13:45:53 -04:00
|
|
|
rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
|
|
|
|
}
|
|
|
|
return -num;
|
|
|
|
}
|
2000-05-12 05:07:57 -04:00
|
|
|
return num;
|
2000-01-04 23:41:21 -05:00
|
|
|
}
|
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
SIGNED_VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big2long(VALUE x)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2006-07-11 02:47:09 -04:00
|
|
|
VALUE num = big2ulong(x, "long", Qtrue);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
if ((SIGNED_VALUE)num < 0 &&
|
|
|
|
(RBIGNUM(x)->sign || (SIGNED_VALUE)num != LONG_MIN)) {
|
2003-12-26 10:34:33 -05:00
|
|
|
rb_raise(rb_eRangeError, "bignum too big to convert into `long'");
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2006-07-11 02:47:09 -04:00
|
|
|
if (!RBIGNUM(x)->sign) return -(SIGNED_VALUE)num;
|
1999-01-19 23:59:39 -05:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2002-03-14 01:23:46 -05:00
|
|
|
#if HAVE_LONG_LONG
|
|
|
|
|
* 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
2002-03-15 03:51:31 -05:00
|
|
|
static unsigned LONG_LONG
|
2005-10-21 02:28:41 -04:00
|
|
|
big2ull(VALUE x, const char *type)
|
2002-03-14 01:23:46 -05:00
|
|
|
{
|
|
|
|
long len = RBIGNUM(x)->len;
|
|
|
|
BDIGIT_DBL num;
|
|
|
|
BDIGIT *ds;
|
|
|
|
|
2002-04-10 04:45:26 -04:00
|
|
|
if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
|
2002-03-14 01:23:46 -05:00
|
|
|
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
|
|
|
|
ds = BDIGITS(x);
|
|
|
|
num = 0;
|
|
|
|
while (len--) {
|
|
|
|
num = BIGUP(num);
|
|
|
|
num += ds[len];
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
* 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
2002-03-15 03:51:31 -05:00
|
|
|
unsigned LONG_LONG
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big2ull(VALUE x)
|
2002-03-14 01:23:46 -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
2002-03-15 03:51:31 -05:00
|
|
|
unsigned LONG_LONG num = big2ull(x, "unsigned long long");
|
2002-03-14 01:23:46 -05:00
|
|
|
|
|
|
|
if (!RBIGNUM(x)->sign) return -num;
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
* 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
2002-03-15 03:51:31 -05:00
|
|
|
LONG_LONG
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big2ll(VALUE x)
|
2002-03-14 01:23:46 -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
2002-03-15 03:51:31 -05:00
|
|
|
unsigned LONG_LONG num = big2ull(x, "long long");
|
2002-03-14 01:23:46 -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
2002-03-15 03:51:31 -05:00
|
|
|
if ((LONG_LONG)num < 0 && (RBIGNUM(x)->sign
|
|
|
|
|| (LONG_LONG)num != LLONG_MIN)) {
|
2002-03-14 01:23:46 -05:00
|
|
|
rb_raise(rb_eRangeError, "bignum too big to convert into `long long'");
|
|
|
|
}
|
* 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
2002-03-15 03:51:31 -05:00
|
|
|
if (!RBIGNUM(x)->sign) return -(LONG_LONG)num;
|
2002-03-14 01:23:46 -05:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LONG_LONG */
|
|
|
|
|
2000-06-22 04:29:58 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
dbl2big(double d)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-10-31 03:37:47 -05:00
|
|
|
long i = 0;
|
2000-11-02 04:04:54 -05:00
|
|
|
BDIGIT c;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *digits;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE z;
|
|
|
|
double u = (d < 0)?-d:d;
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (isinf(d)) {
|
|
|
|
rb_raise(rb_eFloatDomainError, d < 0 ? "-Infinity" : "Infinity");
|
|
|
|
}
|
|
|
|
if (isnan(d)) {
|
|
|
|
rb_raise(rb_eFloatDomainError, "NaN");
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!POSFIXABLE(u) || 0 != (long)u) {
|
1998-01-16 07:13:05 -05:00
|
|
|
u /= (double)(BIGRAD);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
z = bignew(i, d>=0);
|
|
|
|
digits = BDIGITS(z);
|
|
|
|
while (i--) {
|
|
|
|
u *= BIGRAD;
|
2000-11-02 04:04:54 -05:00
|
|
|
c = (BDIGIT)u;
|
1998-01-16 07:13:05 -05:00
|
|
|
u -= c;
|
2000-11-02 04:04:54 -05:00
|
|
|
digits[i] = c;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-06-22 04:29:58 -04:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_dbl2big(double d)
|
2000-06-22 04:29:58 -04:00
|
|
|
{
|
|
|
|
return bignorm(dbl2big(d));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big2dbl(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
double d = 0.0;
|
1999-08-13 01:45:20 -04:00
|
|
|
long i = RBIGNUM(x)->len;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds = BDIGITS(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
d = ds[i] + BIGRAD*d;
|
|
|
|
}
|
2003-07-09 18:28:42 -04:00
|
|
|
if (isinf(d)) {
|
|
|
|
rb_warn("Bignum out of Float range");
|
|
|
|
d = HUGE_VAL;
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(x)->sign) d = -d;
|
1998-01-16 07:13:05 -05:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.to_f -> float
|
|
|
|
*
|
|
|
|
* Converts <i>big</i> to a <code>Float</code>. If <i>big</i> doesn't
|
|
|
|
* fit in a <code>Float</code>, the result is infinity.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_to_f(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(rb_big2dbl(x));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big <=> numeric => -1, 0, +1
|
|
|
|
*
|
|
|
|
* Comparison---Returns -1, 0, or +1 depending on whether <i>big</i> is
|
|
|
|
* less than, equal to, or greater than <i>numeric</i>. This is the
|
|
|
|
* basis for the tests in <code>Comparable</code>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-08-12 04:13:28 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_cmp(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
long xlen = RBIGNUM(x)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
|
2000-06-05 04:46:59 -04:00
|
|
|
case T_FLOAT:
|
2002-08-19 01:56:09 -04:00
|
|
|
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT(y)->value);
|
2000-06-05 04:46:59 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
2002-12-19 04:20:20 -05:00
|
|
|
return rb_num_coerce_cmp(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RBIGNUM(x)->sign > RBIGNUM(y)->sign) return INT2FIX(1);
|
|
|
|
if (RBIGNUM(x)->sign < RBIGNUM(y)->sign) return INT2FIX(-1);
|
|
|
|
if (xlen < RBIGNUM(y)->len)
|
|
|
|
return (RBIGNUM(x)->sign) ? INT2FIX(-1) : INT2FIX(1);
|
|
|
|
if (xlen > RBIGNUM(y)->len)
|
|
|
|
return (RBIGNUM(x)->sign) ? INT2FIX(1) : INT2FIX(-1);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while(xlen-- && (BDIGITS(x)[xlen]==BDIGITS(y)[xlen]));
|
|
|
|
if (-1 == xlen) return INT2FIX(0);
|
|
|
|
return (BDIGITS(x)[xlen] > BDIGITS(y)[xlen]) ?
|
1998-01-16 07:19:22 -05:00
|
|
|
(RBIGNUM(x)->sign ? INT2FIX(1) : INT2FIX(-1)) :
|
|
|
|
(RBIGNUM(x)->sign ? INT2FIX(-1) : INT2FIX(1));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big == obj => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> only if <i>obj</i> has the same value
|
|
|
|
* as <i>big</i>. Contrast this with <code>Bignum#eql?</code>, which
|
|
|
|
* requires <i>obj</i> to be a <code>Bignum</code>.
|
|
|
|
*
|
|
|
|
* 68719476736 == 68719476736.0 #=> true
|
|
|
|
*/
|
|
|
|
|
2005-08-12 04:13:28 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_eq(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-06-05 04:46:59 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
y = rb_int2big(FIX2LONG(y));
|
|
|
|
break;
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
case T_FLOAT:
|
2004-04-02 03:35:32 -05:00
|
|
|
{
|
2004-06-04 05:56:25 -04:00
|
|
|
volatile double a, b;
|
2004-04-02 03:35:32 -05:00
|
|
|
|
|
|
|
a = RFLOAT(y)->value;
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(a)) return Qfalse;
|
2004-04-02 03:35:32 -05:00
|
|
|
b = rb_big2dbl(x);
|
|
|
|
return (a == b)?Qtrue:Qfalse;
|
|
|
|
}
|
2000-06-05 04:46:59 -04:00
|
|
|
default:
|
2002-04-18 04:46:18 -04:00
|
|
|
return rb_equal(y, x);
|
2000-06-05 04:46:59 -04:00
|
|
|
}
|
|
|
|
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign) return Qfalse;
|
|
|
|
if (RBIGNUM(x)->len != RBIGNUM(y)->len) return Qfalse;
|
2000-10-31 03:37:47 -05:00
|
|
|
if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,RBIGNUM(y)->len) != 0) return Qfalse;
|
2000-06-05 04:46:59 -04:00
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.eql?(obj) => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> only if <i>obj</i> is a
|
|
|
|
* <code>Bignum</code> with the same value as <i>big</i>. Contrast this
|
|
|
|
* with <code>Bignum#==</code>, which performs type conversions.
|
|
|
|
*
|
|
|
|
* 68719476736.eql?(68719476736.0) #=> false
|
|
|
|
*/
|
|
|
|
|
2001-11-08 01:43:14 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_eql(VALUE x, VALUE y)
|
2001-11-08 01:43:14 -05:00
|
|
|
{
|
|
|
|
if (TYPE(y) != T_BIGNUM) return Qfalse;
|
|
|
|
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign) return Qfalse;
|
|
|
|
if (RBIGNUM(x)->len != RBIGNUM(y)->len) return Qfalse;
|
|
|
|
if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,RBIGNUM(y)->len) != 0) return Qfalse;
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* -big => other_big
|
|
|
|
*
|
|
|
|
* Unary minus (returns a new Bignum whose value is 0-big)
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_uminus(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE z = rb_big_clone(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
RBIGNUM(z)->sign = !RBIGNUM(x)->sign;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ~big => integer
|
|
|
|
*
|
|
|
|
* Inverts the bits in big. As Bignums are conceptually infinite
|
|
|
|
* length, the result acts as if it had an infinite number of one
|
|
|
|
* bits to the left. In hex representations, this is displayed
|
|
|
|
* as two periods to the left of the digits.
|
|
|
|
*
|
|
|
|
* sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_neg(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE z = rb_big_clone(x);
|
2005-07-01 04:56:09 -04:00
|
|
|
BDIGIT *ds;
|
|
|
|
long i;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-06-30 02:20:09 -04:00
|
|
|
if (!RBIGNUM(x)->sign) get2comp(z);
|
2005-07-01 04:56:09 -04:00
|
|
|
ds = BDIGITS(z);
|
|
|
|
i = RBIGNUM(x)->len;
|
2005-06-07 22:16:35 -04:00
|
|
|
while (i--) {
|
|
|
|
ds[i] = ~ds[i];
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
|
2005-06-30 02:20:09 -04:00
|
|
|
if (RBIGNUM(x)->sign) get2comp(z);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
bigsub(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE z = 0;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *zds;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL_SIGNED num;
|
2002-08-21 11:47:54 -04:00
|
|
|
long i = RBIGNUM(x)->len;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
/* if x is larger than y, swap */
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RBIGNUM(x)->len < RBIGNUM(y)->len) {
|
1998-01-16 07:13:05 -05:00
|
|
|
z = x; x = y; y = z; /* swap x y */
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
else if (RBIGNUM(x)->len == RBIGNUM(y)->len) {
|
1998-01-16 07:13:05 -05:00
|
|
|
while (i > 0) {
|
|
|
|
i--;
|
|
|
|
if (BDIGITS(x)[i] > BDIGITS(y)[i]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (BDIGITS(x)[i] < BDIGITS(y)[i]) {
|
|
|
|
z = x; x = y; y = z; /* swap x y */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-21 02:28:41 -04:00
|
|
|
z = bignew(RBIGNUM(x)->len, z==0);
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
for (i = 0, num = 0; i < RBIGNUM(y)->len; i++) {
|
2000-11-01 03:49:40 -05:00
|
|
|
num += (BDIGIT_DBL_SIGNED)BDIGITS(x)[i] - BDIGITS(y)[i];
|
1998-01-16 07:13:05 -05:00
|
|
|
zds[i] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
while (num && i < RBIGNUM(x)->len) {
|
1998-01-16 07:13:05 -05:00
|
|
|
num += BDIGITS(x)[i];
|
|
|
|
zds[i++] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
while (i < RBIGNUM(x)->len) {
|
1998-01-16 07:13:05 -05:00
|
|
|
zds[i] = BDIGITS(x)[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2000-07-12 02:06:50 -04:00
|
|
|
return z;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
bigadd(VALUE x, VALUE y, int sign)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE z;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num;
|
1999-08-13 01:45:20 -04:00
|
|
|
long i, len;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
sign = (sign == RBIGNUM(y)->sign);
|
|
|
|
if (RBIGNUM(x)->sign != sign) {
|
|
|
|
if (sign) return bigsub(y, x);
|
1998-01-16 07:13:05 -05:00
|
|
|
return bigsub(x, y);
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
|
|
|
|
len = RBIGNUM(x)->len + 1;
|
|
|
|
z = x; x = y; y = z;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:19:22 -05:00
|
|
|
len = RBIGNUM(y)->len + 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
z = bignew(len, sign);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
len = RBIGNUM(x)->len;
|
|
|
|
for (i = 0, num = 0; i < len; i++) {
|
2000-11-01 03:49:40 -05:00
|
|
|
num += (BDIGIT_DBL)BDIGITS(x)[i] + BDIGITS(y)[i];
|
1998-01-16 07:13:05 -05:00
|
|
|
BDIGITS(z)[i] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
len = RBIGNUM(y)->len;
|
|
|
|
while (num && i < len) {
|
1998-01-16 07:13:05 -05:00
|
|
|
num += BDIGITS(y)[i];
|
|
|
|
BDIGITS(z)[i++] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
while (i < len) {
|
1998-01-16 07:13:05 -05:00
|
|
|
BDIGITS(z)[i] = BDIGITS(y)[i];
|
|
|
|
i++;
|
|
|
|
}
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGITS(z)[i] = (BDIGIT)num;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-12 02:06:50 -04:00
|
|
|
return z;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big + other => Numeric
|
|
|
|
*
|
|
|
|
* Adds big and other, returning the result.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_plus(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
/* fall through */
|
|
|
|
case T_BIGNUM:
|
2000-07-12 02:06:50 -04:00
|
|
|
return bignorm(bigadd(x, y, 1));
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(rb_big2dbl(x) + RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big - other => Numeric
|
|
|
|
*
|
|
|
|
* Subtracts other from big, returning the result.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_minus(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
/* fall through */
|
|
|
|
case T_BIGNUM:
|
2000-07-12 02:06:50 -04:00
|
|
|
return bignorm(bigadd(x, y, 0));
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(rb_big2dbl(x) - RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-09 21:39:24 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_mul0(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
long i, j;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL n = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE z;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *zds;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(rb_big2dbl(x) * RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
j = RBIGNUM(x)->len + RBIGNUM(y)->len + 1;
|
|
|
|
z = bignew(j, RBIGNUM(x)->sign==RBIGNUM(y)->sign);
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
while (j--) zds[j] = 0;
|
1998-01-16 07:19:22 -05:00
|
|
|
for (i = 0; i < RBIGNUM(x)->len; i++) {
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL dd = BDIGITS(x)[i];
|
1998-01-16 07:13:05 -05:00
|
|
|
if (dd == 0) continue;
|
|
|
|
n = 0;
|
1998-01-16 07:19:22 -05:00
|
|
|
for (j = 0; j < RBIGNUM(y)->len; j++) {
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL ee = n + (BDIGIT_DBL)dd * BDIGITS(y)[j];
|
1998-01-16 07:13:05 -05:00
|
|
|
n = zds[i + j] + ee;
|
|
|
|
if (ee) zds[i + j] = BIGLO(n);
|
|
|
|
n = BIGDN(n);
|
|
|
|
}
|
|
|
|
if (n) {
|
|
|
|
zds[i + j] = n;
|
|
|
|
}
|
|
|
|
}
|
2005-08-09 21:39:24 -04:00
|
|
|
return z;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-08-09 21:39:24 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big * other => Numeric
|
|
|
|
*
|
|
|
|
* Multiplies big and other, returning the result.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_mul(VALUE x, VALUE y)
|
2005-08-09 21:39:24 -04:00
|
|
|
{
|
|
|
|
return bignorm(rb_big_mul0(x, y));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
long nx = RBIGNUM(x)->len, ny = RBIGNUM(y)->len;
|
|
|
|
long i, j;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE yy, z;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *xds, *yds, *zds, *tds;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL t2;
|
|
|
|
BDIGIT_DBL_SIGNED num;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT dd, q;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-04-09 02:44:34 -04:00
|
|
|
if (BIGZEROP(y)) rb_num_zerodiv();
|
1998-01-16 07:13:05 -05:00
|
|
|
yds = BDIGITS(y);
|
2003-01-16 02:38:40 -05:00
|
|
|
if (nx < ny || (nx == ny && BDIGITS(x)[nx - 1] < BDIGITS(y)[ny - 1])) {
|
2000-07-12 03:33:34 -04:00
|
|
|
if (divp) *divp = rb_int2big(0);
|
2000-07-12 02:06:50 -04:00
|
|
|
if (modp) *modp = x;
|
1998-01-16 07:13:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
xds = BDIGITS(x);
|
|
|
|
if (ny == 1) {
|
|
|
|
dd = yds[0];
|
1999-01-19 23:59:39 -05:00
|
|
|
z = rb_big_clone(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
t2 = 0; i = nx;
|
|
|
|
while (i--) {
|
|
|
|
t2 = BIGUP(t2) + zds[i];
|
2000-10-31 03:37:47 -05:00
|
|
|
zds[i] = (BDIGIT)(t2 / dd);
|
1998-01-16 07:13:05 -05:00
|
|
|
t2 %= dd;
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
RBIGNUM(z)->sign = RBIGNUM(x)->sign==RBIGNUM(y)->sign;
|
2001-01-09 02:26:21 -05:00
|
|
|
if (modp) {
|
2006-07-11 01:00:02 -04:00
|
|
|
*modp = rb_uint2big((VALUE)t2);
|
2001-01-09 02:26:21 -05:00
|
|
|
RBIGNUM(*modp)->sign = RBIGNUM(x)->sign;
|
|
|
|
}
|
2000-07-12 02:06:50 -04:00
|
|
|
if (divp) *divp = z;
|
1998-01-16 07:13:05 -05:00
|
|
|
return;
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
z = bignew(nx==ny?nx+2:nx+1, RBIGNUM(x)->sign==RBIGNUM(y)->sign);
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
if (nx==ny) zds[nx+1] = 0;
|
|
|
|
while (!yds[ny-1]) ny--;
|
2000-11-08 00:29:37 -05:00
|
|
|
|
|
|
|
dd = 0;
|
|
|
|
q = yds[ny-1];
|
2006-07-03 16:07:10 -04:00
|
|
|
while ((q & (1UL<<(BITSPERDIG-1))) == 0) {
|
|
|
|
q <<= 1UL;
|
2000-11-08 00:29:37 -05:00
|
|
|
dd++;
|
|
|
|
}
|
|
|
|
if (dd) {
|
1999-01-19 23:59:39 -05:00
|
|
|
yy = rb_big_clone(y);
|
|
|
|
tds = BDIGITS(yy);
|
1998-01-16 07:13:05 -05:00
|
|
|
j = 0;
|
2000-11-08 00:29:37 -05:00
|
|
|
t2 = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
while (j<ny) {
|
2000-11-08 00:29:37 -05:00
|
|
|
t2 += (BDIGIT_DBL)yds[j]<<dd;
|
|
|
|
tds[j++] = BIGLO(t2);
|
|
|
|
t2 = BIGDN(t2);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
yds = tds;
|
|
|
|
j = 0;
|
2000-11-08 00:29:37 -05:00
|
|
|
t2 = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
while (j<nx) {
|
2000-11-08 00:29:37 -05:00
|
|
|
t2 += (BDIGIT_DBL)xds[j]<<dd;
|
|
|
|
zds[j++] = BIGLO(t2);
|
|
|
|
t2 = BIGDN(t2);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-11-08 00:29:37 -05:00
|
|
|
zds[j] = (BDIGIT)t2;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
zds[nx] = 0;
|
|
|
|
j = nx;
|
|
|
|
while (j--) zds[j] = xds[j];
|
|
|
|
}
|
2000-11-08 00:29:37 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
j = nx==ny?nx+1:nx;
|
|
|
|
do {
|
|
|
|
if (zds[j] == yds[ny-1]) q = BIGRAD-1;
|
2000-10-31 03:37:47 -05:00
|
|
|
else q = (BDIGIT)((BIGUP(zds[j]) + zds[j-1])/yds[ny-1]);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (q) {
|
|
|
|
i = 0; num = 0; t2 = 0;
|
|
|
|
do { /* multiply and subtract */
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL ee;
|
|
|
|
t2 += (BDIGIT_DBL)yds[i] * q;
|
1998-01-16 07:13:05 -05:00
|
|
|
ee = num - BIGLO(t2);
|
2000-11-01 03:49:40 -05:00
|
|
|
num = (BDIGIT_DBL)zds[j - ny + i] + ee;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (ee) zds[j - ny + i] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
t2 = BIGDN(t2);
|
|
|
|
} while (++i < ny);
|
2000-11-01 03:49:40 -05:00
|
|
|
num += zds[j - ny + i] - t2;/* borrow from high digit; don't update */
|
1998-01-16 07:13:05 -05:00
|
|
|
while (num) { /* "add back" required */
|
|
|
|
i = 0; num = 0; q--;
|
|
|
|
do {
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL ee = num + yds[i];
|
|
|
|
num = (BDIGIT_DBL)zds[j - ny + i] + ee;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (ee) zds[j - ny + i] = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
} while (++i < ny);
|
|
|
|
num--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zds[j] = q;
|
|
|
|
} while (--j >= ny);
|
2000-07-12 02:06:50 -04:00
|
|
|
if (divp) { /* move quotient down in z */
|
|
|
|
*divp = rb_big_clone(z);
|
2000-07-12 02:33:23 -04:00
|
|
|
zds = BDIGITS(*divp);
|
1998-01-16 07:13:05 -05:00
|
|
|
j = (nx==ny ? nx+2 : nx+1) - ny;
|
|
|
|
for (i = 0;i < j;i++) zds[i] = zds[i+ny];
|
2000-07-12 02:33:23 -04:00
|
|
|
RBIGNUM(*divp)->len = i;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-10-07 03:44:18 -04:00
|
|
|
if (modp) { /* normalize remainder */
|
2000-07-12 02:06:50 -04:00
|
|
|
*modp = rb_big_clone(z);
|
2001-05-02 00:22:21 -04:00
|
|
|
zds = BDIGITS(*modp);
|
2002-10-07 03:44:18 -04:00
|
|
|
while (--ny && !zds[ny]); ++ny;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (dd) {
|
2001-05-02 00:22:21 -04:00
|
|
|
t2 = 0; i = ny;
|
1998-01-16 07:13:05 -05:00
|
|
|
while(i--) {
|
2000-11-08 00:29:37 -05:00
|
|
|
t2 = (t2 | zds[i]) >> dd;
|
|
|
|
q = zds[i];
|
|
|
|
zds[i] = BIGLO(t2);
|
|
|
|
t2 = BIGUP(q);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
2000-07-12 02:06:50 -04:00
|
|
|
RBIGNUM(*modp)->len = ny;
|
|
|
|
RBIGNUM(*modp)->sign = RBIGNUM(x)->sign;
|
2000-07-06 03:21:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
bigdivmod(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
VALUE mod;
|
|
|
|
|
|
|
|
bigdivrem(x, y, divp, &mod);
|
2003-04-09 02:49:51 -04:00
|
|
|
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign && !BIGZEROP(mod)) {
|
2000-07-06 03:21:26 -04:00
|
|
|
if (divp) *divp = bigadd(*divp, rb_int2big(1), 0);
|
|
|
|
if (modp) *modp = bigadd(mod, y, 1);
|
|
|
|
}
|
|
|
|
else {
|
2000-07-12 02:06:50 -04:00
|
|
|
if (divp) *divp = *divp;
|
|
|
|
if (modp) *modp = mod;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big / other => Numeric
|
|
|
|
* big.div(other) => Numeric
|
|
|
|
*
|
|
|
|
* Divides big by other, returning the result.
|
|
|
|
*/
|
|
|
|
|
2005-08-03 03:09:48 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_div(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE z;
|
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(rb_big2dbl(x) / RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-07-06 03:21:26 -04:00
|
|
|
bigdivmod(x, y, &z, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-12 02:06:50 -04:00
|
|
|
return bignorm(z);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big % other => Numeric
|
|
|
|
* big.modulo(other) => Numeric
|
|
|
|
*
|
|
|
|
* Returns big modulo other. See Numeric.divmod for more
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
|
2005-08-03 03:09:48 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_modulo(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE z;
|
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-07-03 01:46:36 -04:00
|
|
|
bigdivmod(x, y, 0, &z);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-12 02:06:50 -04:00
|
|
|
return bignorm(z);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.remainder(numeric) => number
|
|
|
|
*
|
|
|
|
* Returns the remainder after dividing <i>big</i> by <i>numeric</i>.
|
|
|
|
*
|
|
|
|
* -1234567890987654321.remainder(13731) #=> -6966
|
|
|
|
* -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
|
|
|
|
*/
|
2000-07-06 03:21:26 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_remainder(VALUE x, VALUE y)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
VALUE z;
|
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
y = rb_int2big(FIX2LONG(y));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
|
|
|
bigdivrem(x, y, 0, &z);
|
|
|
|
|
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.divmod(numeric) => array
|
|
|
|
*
|
|
|
|
* See <code>Numeric#divmod</code>.
|
|
|
|
*
|
|
|
|
*/
|
2000-05-12 05:07:57 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_divmod(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE div, mod;
|
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-07-03 01:46:36 -04:00
|
|
|
bigdivmod(x, y, &div, &mod);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-12 02:06:50 -04:00
|
|
|
return rb_assoc_new(bignorm(div), bignorm(mod));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.quo(numeric) -> float
|
|
|
|
*
|
|
|
|
* Returns the floating point result of dividing <i>big</i> by
|
|
|
|
* <i>numeric</i>.
|
|
|
|
*
|
|
|
|
* -1234567890987654321.quo(13731) #=> -89910996357705.5
|
|
|
|
* -1234567890987654321.quo(13731.24) #=> -89909424858035.7
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-01-23 01:22:50 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_quo(VALUE x, VALUE y)
|
2003-01-23 01:22:50 -05:00
|
|
|
{
|
|
|
|
double dx = rb_big2dbl(x);
|
|
|
|
double dy;
|
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
dy = (double)FIX2LONG(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
dy = rb_big2dbl(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
dy = RFLOAT(y)->value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
|
|
|
return rb_float_new(dx / dy);
|
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big ** exponent #=> numeric
|
|
|
|
*
|
|
|
|
* Raises _big_ to the _exponent_ power (which may be an integer, float,
|
|
|
|
* or anything that will coerce to a number). The result may be
|
|
|
|
* a Fixnum, Bignum, or Float
|
|
|
|
*
|
|
|
|
* 123456789 ** 2 #=> 15241578750190521
|
|
|
|
* 123456789 ** 1.2 #=> 5126464716.09932
|
|
|
|
* 123456789 ** -2 #=> 6.5610001194102e-17
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_pow(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
double d;
|
1999-01-19 23:59:39 -05:00
|
|
|
long yy;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (y == INT2FIX(0)) return INT2FIX(1);
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FLOAT:
|
|
|
|
d = RFLOAT(y)->value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_warn("in a**b, b may be too big");
|
|
|
|
d = rb_big2dbl(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FIXNUM:
|
2004-03-14 21:27:29 -05:00
|
|
|
yy = FIX2LONG(y);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (yy > 0) {
|
2002-06-11 03:02:23 -04:00
|
|
|
VALUE z = x;
|
1999-01-19 23:59:39 -05:00
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
if (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024) {
|
|
|
|
rb_warn("in a**b, b may be too big");
|
|
|
|
d = (double)yy;
|
|
|
|
break;
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
for (;;) {
|
2002-06-11 03:02:23 -04:00
|
|
|
yy -= 1;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (yy == 0) break;
|
|
|
|
while (yy % 2 == 0) {
|
2002-06-11 03:02:23 -04:00
|
|
|
yy /= 2;
|
2005-08-09 21:39:24 -04:00
|
|
|
x = rb_big_mul0(x, x);
|
2006-09-04 16:10:45 -04:00
|
|
|
if (!BDIGITS(x)[RBIGNUM(x)->len-1]) RBIGNUM(x)->len--;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-08-09 21:39:24 -04:00
|
|
|
z = rb_big_mul0(z, x);
|
2006-09-04 16:10:45 -04:00
|
|
|
if (!BDIGITS(z)[RBIGNUM(z)->len-1]) RBIGNUM(z)->len--;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2002-06-11 03:02:23 -04:00
|
|
|
return bignorm(z);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
d = (double)yy;
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(pow(rb_big2dbl(x), d));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big & numeric => integer
|
|
|
|
*
|
|
|
|
* Performs bitwise +and+ between _big_ and _numeric_.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_and(VALUE xx, VALUE yy)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2004-08-28 10:14:11 -04:00
|
|
|
volatile VALUE x, y, z;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds1, *ds2, *zds;
|
1999-08-13 01:45:20 -04:00
|
|
|
long i, l1, l2;
|
1998-01-16 07:13:05 -05:00
|
|
|
char sign;
|
|
|
|
|
2004-08-28 10:14:11 -04:00
|
|
|
x = xx;
|
|
|
|
y = rb_to_int(yy);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(y)->sign) {
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_big_clone(y);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
1999-01-19 23:59:39 -05:00
|
|
|
x = rb_big_clone(x);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
|
|
|
|
l1 = RBIGNUM(y)->len;
|
|
|
|
l2 = RBIGNUM(x)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
ds1 = BDIGITS(y);
|
|
|
|
ds2 = BDIGITS(x);
|
1998-01-16 07:19:22 -05:00
|
|
|
sign = RBIGNUM(y)->sign;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:19:22 -05:00
|
|
|
l1 = RBIGNUM(x)->len;
|
|
|
|
l2 = RBIGNUM(y)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
ds1 = BDIGITS(x);
|
|
|
|
ds2 = BDIGITS(y);
|
1998-01-16 07:19:22 -05:00
|
|
|
sign = RBIGNUM(x)->sign;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
z = bignew(l2, RBIGNUM(x)->sign || RBIGNUM(y)->sign);
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
|
|
|
|
for (i=0; i<l1; i++) {
|
|
|
|
zds[i] = ds1[i] & ds2[i];
|
|
|
|
}
|
|
|
|
for (; i<l2; i++) {
|
|
|
|
zds[i] = sign?0:ds2[i];
|
|
|
|
}
|
2005-06-30 02:20:09 -04:00
|
|
|
if (!RBIGNUM(z)->sign) get2comp(z);
|
1998-01-16 07:13:05 -05:00
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big | numeric => integer
|
|
|
|
*
|
|
|
|
* Performs bitwise +or+ between _big_ and _numeric_.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_or(VALUE xx, VALUE yy)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2004-08-28 10:14:11 -04:00
|
|
|
volatile VALUE x, y, z;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds1, *ds2, *zds;
|
|
|
|
long i, l1, l2;
|
1998-01-16 07:13:05 -05:00
|
|
|
char sign;
|
|
|
|
|
2004-08-28 10:14:11 -04:00
|
|
|
x = xx;
|
|
|
|
y = rb_to_int(yy);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(y)->sign) {
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_big_clone(y);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
1999-01-19 23:59:39 -05:00
|
|
|
x = rb_big_clone(x);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
|
|
|
|
l1 = RBIGNUM(y)->len;
|
|
|
|
l2 = RBIGNUM(x)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
ds1 = BDIGITS(y);
|
|
|
|
ds2 = BDIGITS(x);
|
1998-01-16 07:19:22 -05:00
|
|
|
sign = RBIGNUM(y)->sign;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:19:22 -05:00
|
|
|
l1 = RBIGNUM(x)->len;
|
|
|
|
l2 = RBIGNUM(y)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
ds1 = BDIGITS(x);
|
|
|
|
ds2 = BDIGITS(y);
|
1998-01-16 07:19:22 -05:00
|
|
|
sign = RBIGNUM(x)->sign;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
z = bignew(l2, RBIGNUM(x)->sign && RBIGNUM(y)->sign);
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
|
|
|
|
for (i=0; i<l1; i++) {
|
|
|
|
zds[i] = ds1[i] | ds2[i];
|
|
|
|
}
|
|
|
|
for (; i<l2; i++) {
|
|
|
|
zds[i] = sign?ds2[i]:(BIGRAD-1);
|
|
|
|
}
|
2005-06-30 02:20:09 -04:00
|
|
|
if (!RBIGNUM(z)->sign) get2comp(z);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big ^ numeric => integer
|
|
|
|
*
|
|
|
|
* Performs bitwise +exclusive or+ between _big_ and _numeric_.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_xor(VALUE xx, VALUE yy)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2004-09-03 05:00:52 -04:00
|
|
|
volatile VALUE x, y;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE z;
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *ds1, *ds2, *zds;
|
|
|
|
long i, l1, l2;
|
1998-01-16 07:13:05 -05:00
|
|
|
char sign;
|
|
|
|
|
2004-09-03 05:00:52 -04:00
|
|
|
x = xx;
|
|
|
|
y = rb_to_int(yy);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_int2big(FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(y)->sign) {
|
1999-01-19 23:59:39 -05:00
|
|
|
y = rb_big_clone(y);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
1999-01-19 23:59:39 -05:00
|
|
|
x = rb_big_clone(x);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
|
|
|
|
l1 = RBIGNUM(y)->len;
|
|
|
|
l2 = RBIGNUM(x)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
ds1 = BDIGITS(y);
|
|
|
|
ds2 = BDIGITS(x);
|
1998-01-16 07:19:22 -05:00
|
|
|
sign = RBIGNUM(y)->sign;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:19:22 -05:00
|
|
|
l1 = RBIGNUM(x)->len;
|
|
|
|
l2 = RBIGNUM(y)->len;
|
1998-01-16 07:13:05 -05:00
|
|
|
ds1 = BDIGITS(x);
|
|
|
|
ds2 = BDIGITS(y);
|
1998-01-16 07:19:22 -05:00
|
|
|
sign = RBIGNUM(x)->sign;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
RBIGNUM(x)->sign = RBIGNUM(x)->sign?1:0;
|
|
|
|
RBIGNUM(y)->sign = RBIGNUM(y)->sign?1:0;
|
|
|
|
z = bignew(l2, !(RBIGNUM(x)->sign ^ RBIGNUM(y)->sign));
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
|
|
|
|
for (i=0; i<l1; i++) {
|
|
|
|
zds[i] = ds1[i] ^ ds2[i];
|
|
|
|
}
|
|
|
|
for (; i<l2; i++) {
|
|
|
|
zds[i] = sign?ds2[i]:~ds2[i];
|
|
|
|
}
|
2005-06-30 02:20:09 -04:00
|
|
|
if (!RBIGNUM(z)->sign) get2comp(z);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
static VALUE rb_big_rshift(VALUE,VALUE);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big << numeric => integer
|
|
|
|
*
|
|
|
|
* Shifts big left _numeric_ positions (right if _numeric_ is negative).
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_lshift(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *xds, *zds;
|
1998-01-16 07:13:05 -05:00
|
|
|
int shift = NUM2INT(y);
|
1999-08-13 01:45:20 -04:00
|
|
|
int s1 = shift/BITSPERDIG;
|
|
|
|
int s2 = shift%BITSPERDIG;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE z;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num = 0;
|
1999-08-13 01:45:20 -04:00
|
|
|
long len, i;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (shift < 0) return rb_big_rshift(x, INT2FIX(-shift));
|
1998-01-16 07:19:22 -05:00
|
|
|
len = RBIGNUM(x)->len;
|
|
|
|
z = bignew(len+s1+1, RBIGNUM(x)->sign);
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
for (i=0; i<s1; i++) {
|
|
|
|
*zds++ = 0;
|
|
|
|
}
|
2000-06-28 04:31:35 -04:00
|
|
|
xds = BDIGITS(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i<len; i++) {
|
2000-12-21 22:22:25 -05:00
|
|
|
num = num | (BDIGIT_DBL)*xds++<<s2;
|
1998-01-16 07:13:05 -05:00
|
|
|
*zds++ = BIGLO(num);
|
|
|
|
num = BIGDN(num);
|
|
|
|
}
|
|
|
|
*zds = BIGLO(num);
|
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big >> numeric => integer
|
|
|
|
*
|
|
|
|
* Shifts big right _numeric_ positions (left if _numeric_ is negative).
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_rshift(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *xds, *zds;
|
1998-01-16 07:13:05 -05:00
|
|
|
int shift = NUM2INT(y);
|
2002-08-21 11:47:54 -04:00
|
|
|
long s1 = shift/BITSPERDIG;
|
|
|
|
long s2 = shift%BITSPERDIG;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE z;
|
2000-11-01 03:49:40 -05:00
|
|
|
BDIGIT_DBL num = 0;
|
2002-08-21 11:47:54 -04:00
|
|
|
long i, j;
|
2005-12-16 13:59:31 -05:00
|
|
|
volatile VALUE save_x;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (shift < 0) return rb_big_lshift(x, INT2FIX(-shift));
|
2002-02-14 23:43:58 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (s1 > RBIGNUM(x)->len) {
|
|
|
|
if (RBIGNUM(x)->sign)
|
1998-01-16 07:13:05 -05:00
|
|
|
return INT2FIX(0);
|
|
|
|
else
|
|
|
|
return INT2FIX(-1);
|
|
|
|
}
|
2002-02-14 23:43:58 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
2005-12-16 13:59:31 -05:00
|
|
|
save_x = x = rb_big_clone(x);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(x);
|
2002-02-14 23:43:58 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
xds = BDIGITS(x);
|
1998-01-16 07:19:22 -05:00
|
|
|
i = RBIGNUM(x)->len; j = i - s1;
|
|
|
|
z = bignew(j, RBIGNUM(x)->sign);
|
2002-10-04 13:54:29 -04:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
|
|
|
num = ((BDIGIT_DBL)~0) << BITSPERDIG;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
zds = BDIGITS(z);
|
|
|
|
while (i--, j--) {
|
|
|
|
num = (num | xds[i]) >> s2;
|
|
|
|
zds[j] = BIGLO(num);
|
|
|
|
num = BIGUP(xds[i]);
|
|
|
|
}
|
2002-02-14 23:43:58 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(z);
|
2002-02-14 23:43:58 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
return bignorm(z);
|
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big[n] -> 0, 1
|
|
|
|
*
|
|
|
|
* Bit Reference---Returns the <em>n</em>th bit in the (assumed) binary
|
|
|
|
* representation of <i>big</i>, where <i>big</i>[0] is the least
|
|
|
|
* significant bit.
|
|
|
|
*
|
|
|
|
* a = 9**15
|
|
|
|
* 50.downto(0) do |n|
|
|
|
|
* print a[n]
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* 000101110110100000111000011110010100111100010111001
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_aref(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-10-31 03:37:47 -05:00
|
|
|
BDIGIT *xds;
|
2001-11-01 00:11:24 -05:00
|
|
|
int shift;
|
2002-08-21 11:47:54 -04:00
|
|
|
long s1, s2;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-11-01 00:11:24 -05:00
|
|
|
if (TYPE(y) == T_BIGNUM) {
|
|
|
|
if (!RBIGNUM(y)->sign || RBIGNUM(x)->sign)
|
|
|
|
return INT2FIX(0);
|
|
|
|
return INT2FIX(1);
|
|
|
|
}
|
|
|
|
shift = NUM2INT(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (shift < 0) return INT2FIX(0);
|
1998-01-16 07:19:22 -05:00
|
|
|
s1 = shift/BITSPERDIG;
|
|
|
|
s2 = shift%BITSPERDIG;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
|
|
|
if (s1 >= RBIGNUM(x)->len) return INT2FIX(1);
|
1999-01-19 23:59:39 -05:00
|
|
|
x = rb_big_clone(x);
|
2005-06-30 02:20:09 -04:00
|
|
|
get2comp(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:19:22 -05:00
|
|
|
if (s1 >= RBIGNUM(x)->len) return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
xds = BDIGITS(x);
|
|
|
|
if (xds[s1] & (1<<s2))
|
|
|
|
return INT2FIX(1);
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
2003-12-28 22:56:22 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.hash => fixnum
|
|
|
|
*
|
|
|
|
* Compute a hash based on the value of _big_.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_hash(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-10-31 03:37:47 -05:00
|
|
|
long i, len, key;
|
|
|
|
BDIGIT *digits;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-10-31 03:37:47 -05:00
|
|
|
key = 0; digits = BDIGITS(x); len = RBIGNUM(x)->len;
|
|
|
|
for (i=0; i<len; i++) {
|
1998-01-16 07:13:05 -05:00
|
|
|
key ^= *digits++;
|
|
|
|
}
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(key);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* MISSING: documentation
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_coerce(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (FIXNUM_P(y)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-08-09 21:39:24 -04:00
|
|
|
else if (TYPE(y) == T_BIGNUM) {
|
|
|
|
return rb_assoc_new(y, x);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
else {
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
rb_raise(rb_eTypeError, "can't coerce %s to Bignum",
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
/* not reached */
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.abs -> aBignum
|
|
|
|
*
|
|
|
|
* Returns the absolute value of <i>big</i>.
|
|
|
|
*
|
|
|
|
* -1234567890987654321.abs #=> 1234567890987654321
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_abs(VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
if (!RBIGNUM(x)->sign) {
|
1999-01-19 23:59:39 -05:00
|
|
|
x = rb_big_clone(x);
|
1998-01-16 07:19:22 -05:00
|
|
|
RBIGNUM(x)->sign = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return x;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 22:58:57 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* big.size -> integer
|
|
|
|
*
|
|
|
|
* Returns the number of bytes in the machine representation of
|
|
|
|
* <i>big</i>.
|
|
|
|
*
|
|
|
|
* (256**10 - 1).size #=> 12
|
|
|
|
* (256**20 - 1).size #=> 20
|
|
|
|
* (256**40 - 1).size #=> 40
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_big_size(VALUE big)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(RBIGNUM(big)->len*SIZEOF_BDIGITS);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-18 19:01:19 -05:00
|
|
|
/*
|
|
|
|
* Bignum objects hold integers outside the range of
|
|
|
|
* Fixnum. Bignum objects are created
|
|
|
|
* automatically when integer calculations would otherwise overflow a
|
|
|
|
* Fixnum. When a calculation involving
|
|
|
|
* Bignum objects returns a result that will fit in a
|
|
|
|
* Fixnum, the result is automatically converted.
|
|
|
|
*
|
|
|
|
* For the purposes of the bitwise operations and <code>[]</code>, a
|
|
|
|
* Bignum is treated as if it were an infinite-length
|
|
|
|
* bitstring with 2's complement representation.
|
|
|
|
*
|
|
|
|
* While Fixnum values are immediate, Bignum
|
|
|
|
* objects are not---assignment and parameter passing work with
|
|
|
|
* references to objects, not the objects themselves.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_Bignum(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_cBignum = rb_define_class("Bignum", rb_cInteger);
|
|
|
|
|
2001-11-19 00:03:03 -05:00
|
|
|
rb_define_method(rb_cBignum, "to_s", rb_big_to_s, -1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cBignum, "coerce", rb_big_coerce, 1);
|
|
|
|
rb_define_method(rb_cBignum, "-@", rb_big_uminus, 0);
|
|
|
|
rb_define_method(rb_cBignum, "+", rb_big_plus, 1);
|
|
|
|
rb_define_method(rb_cBignum, "-", rb_big_minus, 1);
|
|
|
|
rb_define_method(rb_cBignum, "*", rb_big_mul, 1);
|
|
|
|
rb_define_method(rb_cBignum, "/", rb_big_div, 1);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cBignum, "%", rb_big_modulo, 1);
|
2002-10-07 03:16:12 -04:00
|
|
|
rb_define_method(rb_cBignum, "div", rb_big_div, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cBignum, "divmod", rb_big_divmod, 1);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cBignum, "modulo", rb_big_modulo, 1);
|
|
|
|
rb_define_method(rb_cBignum, "remainder", rb_big_remainder, 1);
|
2003-01-23 01:22:50 -05:00
|
|
|
rb_define_method(rb_cBignum, "quo", rb_big_quo, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cBignum, "**", rb_big_pow, 1);
|
|
|
|
rb_define_method(rb_cBignum, "&", rb_big_and, 1);
|
|
|
|
rb_define_method(rb_cBignum, "|", rb_big_or, 1);
|
|
|
|
rb_define_method(rb_cBignum, "^", rb_big_xor, 1);
|
|
|
|
rb_define_method(rb_cBignum, "~", rb_big_neg, 0);
|
|
|
|
rb_define_method(rb_cBignum, "<<", rb_big_lshift, 1);
|
|
|
|
rb_define_method(rb_cBignum, ">>", rb_big_rshift, 1);
|
|
|
|
rb_define_method(rb_cBignum, "[]", rb_big_aref, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cBignum, "<=>", rb_big_cmp, 1);
|
|
|
|
rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
|
2001-11-08 01:43:14 -05:00
|
|
|
rb_define_method(rb_cBignum, "eql?", rb_big_eql, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cBignum, "hash", rb_big_hash, 0);
|
|
|
|
rb_define_method(rb_cBignum, "to_f", rb_big_to_f, 0);
|
|
|
|
rb_define_method(rb_cBignum, "abs", rb_big_abs, 0);
|
|
|
|
rb_define_method(rb_cBignum, "size", rb_big_size, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|