Ruby  2.0.0p648(2015-12-16revision53162)
Data Structures | Macros | Enumerations | Functions | Variables
bignum.c File Reference
#include "ruby/ruby.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "internal.h"
#include <math.h>
#include <float.h>
#include <ctype.h>
#include <assert.h>

Go to the source code of this file.

Data Structures

struct  big_div_struct
 

Macros

#define BDIGITS(x)   (RBIGNUM_DIGITS(x))
 
#define BITSPERDIG   (SIZEOF_BDIGITS*CHAR_BIT)
 
#define BIGRAD   ((BDIGIT_DBL)1 << BITSPERDIG)
 
#define BIGRAD_HALF   ((BDIGIT)(BIGRAD >> 1))
 
#define DIGSPERLONG   (SIZEOF_LONG/SIZEOF_BDIGITS)
 
#define BIGUP(x)   ((BDIGIT_DBL)(x) << BITSPERDIG)
 
#define BIGDN(x)   RSHIFT((x),BITSPERDIG)
 
#define BIGLO(x)   ((BDIGIT)((x) & (BIGRAD-1)))
 
#define BDIGMAX   ((BDIGIT)-1)
 
#define BIGZEROP(x)
 
#define BIGNUM_DEBUG   0
 
#define ON_DEBUG(x)
 
#define RBIGNUM_SET_LEN(b, l)
 
#define bignew(len, sign)   bignew_1(rb_cBignum,(len),(sign))
 
#define QUAD_SIZE   8
 
#define BNEG(b)   (RSHIFT(((BDIGIT*)(b))[QUAD_SIZE/SIZEOF_BDIGITS-1],BITSPERDIG-1) != 0)
 
#define ISDIGIT(c)   ('0' <= (c) && (c) <= '9')
 
#define conv_digit(c)
 
#define POW2_P(x)   (((x)&((x)-1))==0)
 
#define MASK_55   0x55555555UL
 
#define MASK_33   0x33333333UL
 
#define MASK_0f   0x0f0f0f0fUL
 
#define LOG2_KARATSUBA_DIGITS   7
 
#define KARATSUBA_DIGITS   (1L<<LOG2_KARATSUBA_DIGITS)
 
#define MAX_BIG2STR_TABLE_ENTRIES   64
 
#define KARATSUBA_MUL_DIGITS   70
 
#define TOOM3_MUL_DIGITS   150
 
#define DBL_BIGDIG   ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)
 

Enumerations

enum  big_op_t { big_op_gt, big_op_ge, big_op_lt, big_op_le }
 

Functions

static int bigzero_p (VALUE x)
 
int rb_bigzero_p (VALUE x)
 
int rb_cmpint (VALUE val, VALUE a, VALUE b)
 
static void rb_big_realloc (VALUE big, long len)
 
void rb_big_resize (VALUE big, long len)
 
static VALUE bignew_1 (VALUE klass, long len, int sign)
 
VALUE rb_big_new (long len, int sign)
 
VALUE rb_big_clone (VALUE x)
 
static void get2comp (VALUE x)
 
void rb_big_2comp (VALUE x)
 
static VALUE bigtrunc (VALUE x)
 
static VALUE bigfixize (VALUE x)
 
static VALUE bignorm (VALUE x)
 
VALUE rb_big_norm (VALUE x)
 
VALUE rb_uint2big (VALUE n)
 
VALUE rb_int2big (SIGNED_VALUE n)
 
VALUE rb_uint2inum (VALUE n)
 
VALUE rb_int2inum (SIGNED_VALUE n)
 
void rb_big_pack (VALUE val, unsigned long *buf, long num_longs)
 
VALUE rb_big_unpack (unsigned long *buf, long num_longs)
 
static int quad_buf_complement (char *buf, size_t len)
 
void rb_quad_pack (char *buf, VALUE val)
 
VALUE rb_quad_unpack (const char *buf, int sign)
 
VALUE rb_cstr_to_inum (const char *str, int base, int badcheck)
 
VALUE rb_str_to_inum (VALUE str, int base, int badcheck)
 
VALUE rb_cstr2inum (const char *str, int base)
 
VALUE rb_str2inum (VALUE str, int base)
 
static VALUE bigsqr (VALUE x)
 
static void bigdivmod (VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
 
static int ones (register unsigned long x)
 
static unsigned long next_pow2 (register unsigned long x)
 
static int floor_log2 (register unsigned long x)
 
static int ceil_log2 (register unsigned long x)
 
static void power_cache_init (void)
 
static VALUE power_cache_get_power0 (int base, int i)
 
static VALUE power_cache_get_power (int base, long n1, long *m1)
 
static long big2str_find_n1 (VALUE x, int base)
 
static long big2str_orig (VALUE x, int base, char *ptr, long len, long hbase, int trim)
 
static long big2str_karatsuba (VALUE x, int base, char *ptr, long n1, long len, long hbase, int trim)
 
VALUE rb_big2str0 (VALUE x, int base, int trim)
 
VALUE rb_big2str (VALUE x, int base)
 
static VALUE rb_big_to_s (int argc, VALUE *argv, VALUE x)
 
static VALUE big2ulong (VALUE x, const char *type, int check)
 
VALUE rb_big2ulong_pack (VALUE x)
 
VALUE rb_big2ulong (VALUE x)
 
SIGNED_VALUE rb_big2long (VALUE x)
 
static VALUE dbl2big (double d)
 
VALUE rb_dbl2big (double d)
 
static int nlz (BDIGIT x)
 
static double big2dbl (VALUE x)
 
double rb_big2dbl (VALUE x)
 
static VALUE rb_big_to_f (VALUE x)
 
VALUE rb_integer_float_cmp (VALUE x, VALUE y)
 
VALUE rb_integer_float_eq (VALUE x, VALUE y)
 
VALUE rb_big_cmp (VALUE x, VALUE y)
 
static VALUE big_op (VALUE x, VALUE y, enum big_op_t op)
 
static VALUE big_gt (VALUE x, VALUE y)
 
static VALUE big_ge (VALUE x, VALUE y)
 
static VALUE big_lt (VALUE x, VALUE y)
 
static VALUE big_le (VALUE x, VALUE y)
 
VALUE rb_big_eq (VALUE x, VALUE y)
 
VALUE rb_big_eql (VALUE x, VALUE y)
 
VALUE rb_big_uminus (VALUE x)
 
static VALUE rb_big_neg (VALUE x)
 
static void bigsub_core (BDIGIT *xds, long xn, BDIGIT *yds, long yn, BDIGIT *zds, long zn)
 
static VALUE bigsub (VALUE x, VALUE y)
 
static VALUE bigadd_int (VALUE x, long y)
 
static VALUE bigsub_int (VALUE x, long y0)
 
static void bigadd_core (BDIGIT *xds, long xn, BDIGIT *yds, long yn, BDIGIT *zds, long zn)
 
static VALUE bigadd (VALUE x, VALUE y, int sign)
 
VALUE rb_big_plus (VALUE x, VALUE y)
 
VALUE rb_big_minus (VALUE x, VALUE y)
 
static long big_real_len (VALUE x)
 
static VALUE bigmul1_single (VALUE x, VALUE y)
 
static VALUE bigmul1_normal (VALUE x, VALUE y)
 
static VALUE bigmul0 (VALUE x, VALUE y)
 
static VALUE bigmul1_balance (VALUE x, VALUE y)
 
static void big_split (VALUE v, long n, volatile VALUE *ph, volatile VALUE *pl)
 
static VALUE bigmul1_karatsuba (VALUE x, VALUE y)
 
static void biglsh_bang (BDIGIT *xds, long xn, unsigned long shift)
 
static void bigrsh_bang (BDIGIT *xds, long xn, unsigned long shift)
 
static void big_split3 (VALUE v, long n, volatile VALUE *p0, volatile VALUE *p1, volatile VALUE *p2)
 
static VALUE big_lshift (VALUE, unsigned long)
 
static VALUE big_rshift (VALUE, unsigned long)
 
static VALUE bigdivrem (VALUE, VALUE, volatile VALUE *, volatile VALUE *)
 
static VALUE bigmul1_toom3 (VALUE x, VALUE y)
 
static VALUE bigsqr_fast (VALUE x)
 
static VALUE big_sparse_p (VALUE x)
 
VALUE rb_big_mul (VALUE x, VALUE y)
 
static void * bigdivrem1 (void *ptr)
 
static void rb_big_stop (void *ptr)
 
static VALUE rb_big_divide (VALUE x, VALUE y, ID op)
 
VALUE rb_big_div (VALUE x, VALUE y)
 
VALUE rb_big_idiv (VALUE x, VALUE y)
 
VALUE rb_big_modulo (VALUE x, VALUE y)
 
static VALUE rb_big_remainder (VALUE x, VALUE y)
 
VALUE rb_big_divmod (VALUE x, VALUE y)
 
static int bdigbitsize (BDIGIT x)
 
static VALUE big_shift (VALUE x, long n)
 
static VALUE big_fdiv (VALUE x, VALUE y)
 
VALUE rb_big_fdiv (VALUE x, VALUE y)
 
VALUE rb_big_pow (VALUE x, VALUE y)
 
static VALUE bigand_int (VALUE x, long y)
 
VALUE rb_big_and (VALUE xx, VALUE yy)
 
static VALUE bigor_int (VALUE x, long y)
 
VALUE rb_big_or (VALUE xx, VALUE yy)
 
static VALUE bigxor_int (VALUE x, long y)
 
VALUE rb_big_xor (VALUE xx, VALUE yy)
 
static VALUE check_shiftdown (VALUE y, VALUE x)
 
VALUE rb_big_lshift (VALUE x, VALUE y)
 
VALUE rb_big_rshift (VALUE x, VALUE y)
 
static VALUE rb_big_aref (VALUE x, VALUE y)
 
static VALUE rb_big_hash (VALUE x)
 
static VALUE rb_big_coerce (VALUE x, VALUE y)
 
static VALUE rb_big_abs (VALUE x)
 
static VALUE rb_big_size (VALUE big)
 
static VALUE rb_big_odd_p (VALUE num)
 
static VALUE rb_big_even_p (VALUE num)
 
void Init_Bignum (void)
 

Variables

VALUE rb_cBignum
 
static VALUE big_three = Qnil
 
const char ruby_digitmap [] = "0123456789abcdefghijklmnopqrstuvwxyz"
 
static VALUE big2str_power_cache [35][MAX_BIG2STR_TABLE_ENTRIES]
 

Macro Definition Documentation

#define BDIGITS (   x)    (RBIGNUM_DIGITS(x))
#define BDIGMAX   ((BDIGIT)-1)

Definition at line 47 of file bignum.c.

#define BIGDN (   x)    RSHIFT((x),BITSPERDIG)
#define BIGLO (   x)    ((BDIGIT)((x) & (BIGRAD-1)))
#define bignew (   len,
  sign 
)    bignew_1(rb_cBignum,(len),(sign))
#define BIGNUM_DEBUG   0

Definition at line 53 of file bignum.c.

#define BIGRAD   ((BDIGIT_DBL)1 << BITSPERDIG)

Definition at line 38 of file bignum.c.

Referenced by big2dbl(), bigdivrem1(), bigor_int(), dbl2big(), and rb_big_or().

#define BIGRAD_HALF   ((BDIGIT)(BIGRAD >> 1))

Definition at line 39 of file bignum.c.

Referenced by bigmul1_toom3().

#define BIGUP (   x)    ((BDIGIT_DBL)(x) << BITSPERDIG)

Definition at line 44 of file bignum.c.

Referenced by big2str_orig(), big2ulong(), big_rshift(), bigdivrem(), bigdivrem1(), and bigfixize().

#define BIGZEROP (   x)
Value:
(RBIGNUM_LEN(x) == 0 || \
(BDIGITS(x)[0] == 0 && \
(RBIGNUM_LEN(x) == 1 || bigzero_p(x))))
#define RBIGNUM_LEN(b)
Definition: ruby.h:1081
#define BDIGITS(x)
Definition: bignum.c:36
static int bigzero_p(VALUE x)
Definition: bignum.c:79

Definition at line 49 of file bignum.c.

Referenced by big2str_find_n1(), big2str_karatsuba(), bigdivmod(), bigdivrem(), bigmul1_karatsuba(), rb_big2str0(), rb_big_pow(), rb_bigzero_p(), and rb_cmpint().

#define BITSPERDIG   (SIZEOF_BDIGITS*CHAR_BIT)
#define BNEG (   b)    (RSHIFT(((BDIGIT*)(b))[QUAD_SIZE/SIZEOF_BDIGITS-1],BITSPERDIG-1) != 0)

Definition at line 558 of file bignum.c.

Referenced by rb_quad_unpack().

#define conv_digit (   c)
Value:
(!ISASCII(c) ? -1 : \
ISDIGIT(c) ? ((c) - '0') : \
ISLOWER(c) ? ((c) - 'a' + 10) : \
ISUPPER(c) ? ((c) - 'A' + 10) : \
-1)
#define ISDIGIT(c)
#define ISASCII(c)
Definition: ruby.h:1629
#define ISUPPER(c)
Definition: ruby.h:1633
#define ISLOWER(c)
Definition: ruby.h:1634

Referenced by rb_cstr_to_inum().

#define DBL_BIGDIG   ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)

Referenced by big_fdiv().

#define DIGSPERLONG   (SIZEOF_LONG/SIZEOF_BDIGITS)

Definition at line 40 of file bignum.c.

Referenced by big2ulong(), rb_big_aref(), rb_big_pack(), rb_big_unpack(), and rb_uint2big().

#define ISDIGIT (   c)    ('0' <= (c) && (c) <= '9')
#define KARATSUBA_DIGITS   (1L<<LOG2_KARATSUBA_DIGITS)
#define KARATSUBA_MUL_DIGITS   70

Definition at line 2594 of file bignum.c.

Referenced by bigmul0().

#define LOG2_KARATSUBA_DIGITS   7

Definition at line 943 of file bignum.c.

Referenced by power_cache_get_power().

#define MASK_0f   0x0f0f0f0fUL

Referenced by ones().

#define MASK_33   0x33333333UL

Referenced by ones().

#define MASK_55   0x55555555UL

Referenced by ones().

#define MAX_BIG2STR_TABLE_ENTRIES   64

Definition at line 945 of file bignum.c.

Referenced by power_cache_get_power(), and power_cache_init().

#define ON_DEBUG (   x)

Definition at line 75 of file bignum.c.

#define POW2_P (   x)    (((x)&((x)-1))==0)

Definition at line 881 of file bignum.c.

Referenced by ceil_log2().

#define QUAD_SIZE   8

Definition at line 452 of file bignum.c.

Referenced by rb_quad_pack(), and rb_quad_unpack().

#define RBIGNUM_SET_LEN (   b,
 
)
Value:
((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
(void)(RBASIC(b)->flags = \
(RBASIC(b)->flags & ~RBIGNUM_EMBED_LEN_MASK) | \
(void)(RBIGNUM(b)->as.heap.len = (l)))
#define RBIGNUM_EMBED_LEN_MASK
Definition: ruby.h:1079
#define RBIGNUM(obj)
Definition: ruby.h:1106
#define RBIGNUM_EMBED_LEN_SHIFT
Definition: ruby.h:1080
#define RBASIC(obj)
Definition: ruby.h:1094
#define RBIGNUM_EMBED_FLAG
Definition: ruby.h:1078

Definition at line 118 of file bignum.c.

Referenced by bigdivrem(), bigmul1_balance(), bignew_1(), rb_big_realloc(), rb_big_resize(), and rb_uint2big().

#define TOOM3_MUL_DIGITS   150

Definition at line 2595 of file bignum.c.

Referenced by bigmul0().

Enumeration Type Documentation

enum big_op_t
Enumerator
big_op_gt 
big_op_ge 
big_op_lt 
big_op_le 

Definition at line 1590 of file bignum.c.

Function Documentation

static int bdigbitsize ( BDIGIT  x)
static

Definition at line 3031 of file bignum.c.

References BDIGIT, BITSPERDIG, and size.

Referenced by big_fdiv().

static double big2dbl ( VALUE  x)
static

Definition at line 1380 of file bignum.c.

References BDIGIT, BDIGITS, BIGRAD, bigtrunc(), BITSPERDIG, DBL_MANT_DIG, DBL_MAX_EXP, i, lo, nlz(), RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by big_fdiv(), rb_big2dbl(), and rb_big_fdiv().

static long big2str_find_n1 ( VALUE  x,
int  base 
)
static

Definition at line 1011 of file bignum.c.

References BIGZEROP, BITSPERDIG, CHAR_BIT, FIXNUM_P, LONG_MAX, rb_bug(), rb_eRangeError, rb_raise(), and RBIGNUM_LEN.

Referenced by rb_big2str0().

static long big2str_karatsuba ( VALUE  x,
int  base,
char *  ptr,
long  n1,
long  len,
long  hbase,
int  trim 
)
static
static long big2str_orig ( VALUE  x,
int  base,
char *  ptr,
long  len,
long  hbase,
int  trim 
)
static

Definition at line 1050 of file bignum.c.

References BDIGIT, BDIGIT_DBL, BDIGITS, BIGUP, i, MEMMOVE, RBIGNUM_LEN, and SIZEOF_BDIGITS.

Referenced by big2str_karatsuba(), and rb_big2str0().

static VALUE big2ulong ( VALUE  x,
const char *  type,
int  check 
)
static
static VALUE big_fdiv ( VALUE  x,
VALUE  y 
)
static
static VALUE big_ge ( VALUE  x,
VALUE  y 
)
static

Definition at line 1661 of file bignum.c.

References big_op(), and big_op_ge.

Referenced by Init_Bignum().

static VALUE big_gt ( VALUE  x,
VALUE  y 
)
static

Definition at line 1647 of file bignum.c.

References big_op(), and big_op_gt.

Referenced by Init_Bignum().

static VALUE big_le ( VALUE  x,
VALUE  y 
)
static

Definition at line 1689 of file bignum.c.

References big_op(), and big_op_le.

Referenced by Init_Bignum().

static VALUE big_lshift ( VALUE  x,
unsigned long  shift 
)
static
static VALUE big_lt ( VALUE  x,
VALUE  y 
)
static

Definition at line 1675 of file bignum.c.

References big_op(), and big_op_lt.

Referenced by Init_Bignum().

static VALUE big_op ( VALUE  x,
VALUE  y,
enum big_op_t  op 
)
static
static long big_real_len ( VALUE  x)
static

Definition at line 2098 of file bignum.c.

References BDIGIT, BDIGITS, and RBIGNUM_LEN.

Referenced by bigmul1_balance(), bigmul1_karatsuba(), and bigmul1_toom3().

static VALUE big_rshift ( VALUE  x,
unsigned long  shift 
)
static
static VALUE big_shift ( VALUE  x,
long  n 
)
static

Definition at line 3055 of file bignum.c.

References big_lshift(), and big_rshift().

Referenced by big_fdiv().

static VALUE big_sparse_p ( VALUE  x)
inlinestatic

Definition at line 2600 of file bignum.c.

References BDIGITS, Qfalse, Qtrue, rb_genrand_ulong_limited(), and RBIGNUM_LEN.

Referenced by bigmul0().

static void big_split ( VALUE  v,
long  n,
volatile VALUE ph,
volatile VALUE pl 
)
static

Definition at line 2196 of file bignum.c.

References BDIGIT, BDIGITS, bignew, MEMCPY, rb_uint2big(), and RBIGNUM_LEN.

Referenced by big_split3(), and bigmul1_karatsuba().

static void big_split3 ( VALUE  v,
long  n,
volatile VALUE p0,
volatile VALUE p1,
volatile VALUE p2 
)
static

Definition at line 2375 of file bignum.c.

References big_split(), and bigtrunc().

Referenced by bigmul1_toom3().

static VALUE bigadd ( VALUE  x,
VALUE  y,
int  sign 
)
static

Definition at line 1997 of file bignum.c.

References BDIGITS, bigadd_core(), bignew, bigsub(), RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by bigdivmod(), bigmul1_toom3(), rb_big_minus(), and rb_big_plus().

static void bigadd_core ( BDIGIT xds,
long  xn,
BDIGIT yds,
long  yn,
BDIGIT zds,
long  zn 
)
static

Definition at line 1963 of file bignum.c.

References assert, BDIGIT, BDIGIT_DBL, BIGDN, BIGLO, and i.

Referenced by bigadd(), bigmul1_balance(), bigmul1_karatsuba(), and bigmul1_toom3().

static VALUE bigadd_int ( VALUE  x,
long  y 
)
static

Definition at line 1910 of file bignum.c.

References assert, BDIGIT, BDIGIT_DBL, BDIGITS, BIGDN, BIGLO, bignew, bignorm(), i, RB_GC_GUARD, RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by rb_big_minus(), and rb_big_plus().

static VALUE bigand_int ( VALUE  x,
long  y 
)
static
static void bigdivmod ( VALUE  x,
VALUE  y,
volatile VALUE divp,
volatile VALUE modp 
)
static
static VALUE bigdivrem ( VALUE  x,
VALUE  y,
volatile VALUE divp,
volatile VALUE modp 
)
static
static void* bigdivrem1 ( void *  ptr)
static
static VALUE bigfixize ( VALUE  x)
inlinestatic

Definition at line 245 of file bignum.c.

References BDIGIT, BDIGITS, BIGUP, INT2FIX, LONG2FIX, NEGFIXABLE, POSFIXABLE, RBIGNUM_LEN, RBIGNUM_SIGN, and SIZEOF_BDIGITS.

Referenced by bignorm().

static void biglsh_bang ( BDIGIT xds,
long  xn,
unsigned long  shift 
)
static

Definition at line 2323 of file bignum.c.

References assert, BDIGIT, BITSPERDIG, i, and MEMZERO.

Referenced by bigmul1_toom3().

static VALUE bigmul0 ( VALUE  x,
VALUE  y 
)
static
static VALUE bigmul1_balance ( VALUE  x,
VALUE  y 
)
static

Definition at line 2159 of file bignum.c.

References assert, BDIGIT, BDIGITS, big_real_len(), bigadd_core(), bigmul0(), bignew, i, MEMCPY, RBIGNUM_LEN, RBIGNUM_SET_LEN, and RBIGNUM_SIGN.

Referenced by bigmul0().

static VALUE bigmul1_karatsuba ( VALUE  x,
VALUE  y 
)
static
static VALUE bigmul1_normal ( VALUE  x,
VALUE  y 
)
static

Definition at line 2125 of file bignum.c.

References BDIGIT, BDIGIT_DBL, BDIGITS, BIGDN, BIGLO, bignew, i, rb_thread_check_ints(), RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by bigmul0().

static VALUE bigmul1_single ( VALUE  x,
VALUE  y 
)
static

Definition at line 2107 of file bignum.c.

References BDIGIT, BDIGIT_DBL, BDIGITS, BIGDN, BIGLO, bignew, and RBIGNUM_SIGN.

Referenced by bigmul0().

static VALUE bigmul1_toom3 ( VALUE  x,
VALUE  y 
)
static
static VALUE bignew_1 ( VALUE  klass,
long  len,
int  sign 
)
static
static VALUE bignorm ( VALUE  x)
static
static VALUE bigor_int ( VALUE  x,
long  y 
)
static

Definition at line 3332 of file bignum.c.

References BDIGIT, BDIGIT_DBL, BDIGITS, BIGDN, BIGLO, bignew, bignorm(), BIGRAD, get2comp(), i, RBIGNUM_LEN, RBIGNUM_SIGN, and big_div_struct::zds.

Referenced by rb_big_or().

static void bigrsh_bang ( BDIGIT xds,
long  xn,
unsigned long  shift 
)
static

Definition at line 2349 of file bignum.c.

References assert, BDIGIT, BITSPERDIG, i, and MEMZERO.

Referenced by bigmul1_toom3().

static VALUE bigsqr ( VALUE  x)
static

Definition at line 3156 of file bignum.c.

References bigmul0(), and bigtrunc().

Referenced by power_cache_get_power(), power_cache_get_power0(), and rb_big_pow().

static VALUE bigsqr_fast ( VALUE  x)
static

Definition at line 2562 of file bignum.c.

References BDIGIT, BDIGIT_DBL, BDIGITS, BIGDN, BIGLO, bignew, i, RBIGNUM_LEN, and v.

Referenced by bigmul0().

static VALUE bigsub ( VALUE  x,
VALUE  y 
)
static

Definition at line 1822 of file bignum.c.

References BDIGIT, BDIGITS, bignew, bigsub_core(), and RBIGNUM_LEN.

Referenced by bigadd(), bigmul1_toom3(), and bigsub_int().

static void bigsub_core ( BDIGIT xds,
long  xn,
BDIGIT yds,
long  yn,
BDIGIT zds,
long  zn 
)
static

Definition at line 1796 of file bignum.c.

References assert, BDIGIT_DBL_SIGNED, BIGDN, BIGLO, and i.

Referenced by bigmul1_karatsuba(), and bigsub().

static VALUE bigsub_int ( VALUE  x,
long  y0 
)
static
static VALUE bigtrunc ( VALUE  x)
inlinestatic
static VALUE bigxor_int ( VALUE  x,
long  y 
)
static

Definition at line 3428 of file bignum.c.

References BDIGIT, BDIGIT_DBL, BDIGITS, BIGDN, BIGLO, bignew, bignorm(), get2comp(), i, RBIGNUM_LEN, RBIGNUM_SIGN, and big_div_struct::zds.

Referenced by rb_big_xor().

static int bigzero_p ( VALUE  x)
static

Definition at line 79 of file bignum.c.

References BDIGIT, BDIGITS, i, and RBIGNUM_LEN.

static int ceil_log2 ( register unsigned long  x)
inlinestatic

Definition at line 938 of file bignum.c.

References floor_log2(), and POW2_P.

Referenced by power_cache_get_power().

static VALUE check_shiftdown ( VALUE  y,
VALUE  x 
)
static

Definition at line 3527 of file bignum.c.

References INT2FIX, Qnil, RBIGNUM_LEN, RBIGNUM_SIGN, and SIZEOF_BDIGITS.

Referenced by rb_big_lshift(), and rb_big_rshift().

static VALUE dbl2big ( double  d)
static

Definition at line 1321 of file bignum.c.

References BDIGIT, BDIGITS, bignew, BIGRAD, i, isinf(), isnan, POSFIXABLE, rb_eFloatDomainError, and rb_raise().

Referenced by big_fdiv(), and rb_dbl2big().

static int floor_log2 ( register unsigned long  x)
inlinestatic

Definition at line 924 of file bignum.c.

References ones().

Referenced by ceil_log2().

static void get2comp ( VALUE  x)
static
void Init_Bignum ( void  )
static unsigned long next_pow2 ( register unsigned long  x)
inlinestatic

Definition at line 910 of file bignum.c.

static int nlz ( BDIGIT  x)
static

Definition at line 1359 of file bignum.c.

References BDIGIT, and BITSPERDIG.

Referenced by big2dbl().

static int ones ( register unsigned long  x)
inlinestatic

Definition at line 884 of file bignum.c.

References MASK_0f, MASK_33, and MASK_55.

Referenced by floor_log2().

static VALUE power_cache_get_power ( int  base,
long  n1,
long *  m1 
)
static
static VALUE power_cache_get_power0 ( int  base,
int  i 
)
inlinestatic
static void power_cache_init ( void  )
static

Definition at line 950 of file bignum.c.

References i, MAX_BIG2STR_TABLE_ENTRIES, and Qnil.

Referenced by Init_Bignum().

static int quad_buf_complement ( char *  buf,
size_t  len 
)
static

Definition at line 525 of file bignum.c.

References i.

Referenced by rb_quad_pack(), and rb_quad_unpack().

double rb_big2dbl ( VALUE  x)
SIGNED_VALUE rb_big2long ( VALUE  x)

Definition at line 1243 of file bignum.c.

References big2ulong(), LONG_MAX, LONG_MIN, rb_eRangeError, rb_raise(), RBIGNUM_POSITIVE_P, and TRUE.

Referenced by rb_num2long().

VALUE rb_big2str ( VALUE  x,
int  base 
)

Definition at line 1159 of file bignum.c.

References rb_big2str0().

Referenced by GetVpValueWithPrec(), rb_big_to_s(), and rb_str_format().

VALUE rb_big2str0 ( VALUE  x,
int  base,
int  trim 
)
VALUE rb_big2ulong ( VALUE  x)
VALUE rb_big2ulong_pack ( VALUE  x)

Definition at line 1215 of file bignum.c.

References big2ulong(), FALSE, RBIGNUM_SIGN, and SIGNED_VALUE.

Referenced by rb_dlcfunc_call().

void rb_big_2comp ( VALUE  x)

Definition at line 225 of file bignum.c.

References get2comp().

Referenced by rb_str_format().

static VALUE rb_big_abs ( VALUE  x)
static

Definition at line 3789 of file bignum.c.

References rb_big_clone(), RBIGNUM_SET_SIGN, and RBIGNUM_SIGN.

Referenced by Init_Bignum().

VALUE rb_big_and ( VALUE  xx,
VALUE  yy 
)
static VALUE rb_big_aref ( VALUE  x,
VALUE  y 
)
static
VALUE rb_big_clone ( VALUE  x)
VALUE rb_big_cmp ( VALUE  x,
VALUE  y 
)
static VALUE rb_big_coerce ( VALUE  x,
VALUE  y 
)
static
VALUE rb_big_div ( VALUE  x,
VALUE  y 
)

Definition at line 2924 of file bignum.c.

References rb_big_divide().

Referenced by fix_divide(), and Init_Bignum().

static VALUE rb_big_divide ( VALUE  x,
VALUE  y,
ID  op 
)
static
VALUE rb_big_divmod ( VALUE  x,
VALUE  y 
)
VALUE rb_big_eq ( VALUE  x,
VALUE  y 
)
VALUE rb_big_eql ( VALUE  x,
VALUE  y 
)

Definition at line 1737 of file bignum.c.

References BDIGIT, BDIGITS, MEMCMP, Qfalse, Qtrue, RB_TYPE_P, RBIGNUM_LEN, RBIGNUM_SIGN, and T_BIGNUM.

Referenced by Init_Bignum().

static VALUE rb_big_even_p ( VALUE  num)
static

Definition at line 3840 of file bignum.c.

References BDIGITS, Qfalse, and Qtrue.

Referenced by Init_Bignum().

VALUE rb_big_fdiv ( VALUE  x,
VALUE  y 
)
static VALUE rb_big_hash ( VALUE  x)
static

Definition at line 3754 of file bignum.c.

References BDIGIT, BDIGITS, hash(), INT2FIX, rb_memhash(), RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by Init_Bignum().

VALUE rb_big_idiv ( VALUE  x,
VALUE  y 
)

Definition at line 2937 of file bignum.c.

References rb_big_divide(), and rb_intern.

Referenced by Init_Bignum().

VALUE rb_big_lshift ( VALUE  x,
VALUE  y 
)
VALUE rb_big_minus ( VALUE  x,
VALUE  y 
)
VALUE rb_big_modulo ( VALUE  x,
VALUE  y 
)

Definition at line 2952 of file bignum.c.

References bigdivmod(), bignorm(), FIX2LONG, rb_int2big(), rb_num_coerce_bin(), T_BIGNUM, T_FIXNUM, and TYPE.

Referenced by fix_mod(), Init_Bignum(), and mod().

VALUE rb_big_mul ( VALUE  x,
VALUE  y 
)
static VALUE rb_big_neg ( VALUE  x)
static
VALUE rb_big_new ( long  len,
int  sign 
)

Definition at line 186 of file bignum.c.

References bignew.

Referenced by int_pair_to_real_inclusive(), and mt_state().

VALUE rb_big_norm ( VALUE  x)

Definition at line 282 of file bignum.c.

References bignorm().

Referenced by fix_aref(), limited_big_rand(), make_seed_value(), mt_state(), r_object0(), and rand_range().

static VALUE rb_big_odd_p ( VALUE  num)
static

Definition at line 3824 of file bignum.c.

References BDIGITS, Qfalse, and Qtrue.

Referenced by Init_Bignum().

VALUE rb_big_or ( VALUE  xx,
VALUE  yy 
)
void rb_big_pack ( VALUE  val,
unsigned long *  buf,
long  num_longs 
)

Definition at line 369 of file bignum.c.

References BDIGIT, BDIGITS, BITSPERDIG, DIGSPERLONG, FIX2LONG, FIXNUM_P, i, rb_to_int(), RBIGNUM_LEN, and RBIGNUM_NEGATIVE_P.

Referenced by pack_pack().

VALUE rb_big_plus ( VALUE  x,
VALUE  y 
)
VALUE rb_big_pow ( VALUE  x,
VALUE  y 
)
static void rb_big_realloc ( VALUE  big,
long  len 
)
static
static VALUE rb_big_remainder ( VALUE  x,
VALUE  y 
)
static

Definition at line 2982 of file bignum.c.

References bigdivrem(), bignorm(), FIX2LONG, rb_int2big(), rb_intern, rb_num_coerce_bin(), T_BIGNUM, T_FIXNUM, and TYPE.

Referenced by Init_Bignum().

void rb_big_resize ( VALUE  big,
long  len 
)
VALUE rb_big_rshift ( VALUE  x,
VALUE  y 
)
static VALUE rb_big_size ( VALUE  big)
static

Definition at line 3811 of file bignum.c.

References LONG2FIX, RBIGNUM_LEN, and SIZEOF_BDIGITS.

Referenced by Init_Bignum().

static void rb_big_stop ( void *  ptr)
static

Definition at line 2734 of file bignum.c.

References Qtrue, and big_div_struct::stop.

Referenced by bigdivrem().

static VALUE rb_big_to_f ( VALUE  x)
static

Definition at line 1453 of file bignum.c.

References DBL2NUM, and rb_big2dbl().

Referenced by Init_Bignum().

static VALUE rb_big_to_s ( int  argc,
VALUE argv,
VALUE  x 
)
static

Definition at line 1179 of file bignum.c.

References NUM2INT, rb_big2str(), and rb_scan_args().

Referenced by Init_Bignum().

VALUE rb_big_uminus ( VALUE  x)

Definition at line 1754 of file bignum.c.

References bignorm(), rb_big_clone(), RBIGNUM_SET_SIGN, and RBIGNUM_SIGN.

Referenced by Init_Bignum().

VALUE rb_big_unpack ( unsigned long *  buf,
long  num_longs 
)

Definition at line 411 of file bignum.c.

References BDIGIT, BDIGITS, BIGDN, BIGLO, bignew, bignorm(), DIGSPERLONG, get2comp(), i, INT2FIX, LONG2NUM, and RBIGNUM_SET_SIGN.

Referenced by pack_unpack().

VALUE rb_big_xor ( VALUE  xx,
VALUE  yy 
)
int rb_bigzero_p ( VALUE  x)

Definition at line 91 of file bignum.c.

References BIGZEROP.

Referenced by rand_int(), and rand_range().

int rb_cmpint ( VALUE  val,
VALUE  a,
VALUE  b 
)
VALUE rb_cstr2inum ( const char *  str,
int  base 
)

Definition at line 865 of file bignum.c.

References rb_cstr_to_inum().

Referenced by JSON_parse_integer().

VALUE rb_cstr_to_inum ( const char *  str,
int  base,
int  badcheck 
)
VALUE rb_dbl2big ( double  d)
VALUE rb_int2big ( SIGNED_VALUE  n)
VALUE rb_int2inum ( SIGNED_VALUE  n)

Definition at line 337 of file bignum.c.

References FIXABLE, LONG2FIX, and rb_int2big().

Referenced by gzfile_reader_rewind().

VALUE rb_integer_float_cmp ( VALUE  x,
VALUE  y 
)
VALUE rb_integer_float_eq ( VALUE  x,
VALUE  y 
)

Definition at line 1509 of file bignum.c.

References FIX2LONG, FIXNUM_P, isinf(), isnan, LONG_MAX, LONG_MIN, Qfalse, Qtrue, rb_big_eq(), rb_dbl2big(), and RFLOAT_VALUE.

Referenced by fix_equal(), flo_eq(), and rb_big_eq().

void rb_quad_pack ( char *  buf,
VALUE  val 
)
VALUE rb_quad_unpack ( const char *  buf,
int  sign 
)
VALUE rb_str2inum ( VALUE  str,
int  base 
)

Definition at line 871 of file bignum.c.

References rb_str_to_inum().

VALUE rb_str_to_inum ( VALUE  str,
int  base,
int  badcheck 
)
VALUE rb_uint2big ( VALUE  n)
VALUE rb_uint2inum ( VALUE  n)

Variable Documentation

VALUE big2str_power_cache[35][MAX_BIG2STR_TABLE_ENTRIES]
static

Definition at line 947 of file bignum.c.

VALUE big_three = Qnil
static

Definition at line 30 of file bignum.c.

Referenced by bigmul1_toom3(), and Init_Bignum().

VALUE rb_cBignum
const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz"

Definition at line 876 of file bignum.c.

Referenced by rb_fix2str().