Ruby  2.1.10p492(2016-04-01revision54464)
Data Structures | Macros | Typedefs | 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
 
struct  big2str_struct
 

Macros

#define RB_BIGNUM_TYPE_P(x)   RB_TYPE_P((x), T_BIGNUM)
 
#define SIZEOF_BDIGIT_DBL   SIZEOF_LONG_LONG
 
#define HOST_BIGENDIAN_P   0
 
#define ALIGNOF(type)   ((int)offsetof(struct { char f1; type f2; }, f2))
 
#define LSHIFTABLE(d, n)   ((n) < sizeof(d) * CHAR_BIT)
 
#define LSHIFTX(d, n)   (!LSHIFTABLE(d, n) ? 0 : ((d) << (!LSHIFTABLE(d, n) ? 0 : (n))))
 
#define CLEAR_LOWBITS(d, numbits)   ((d) & LSHIFTX(~((d)*0), (numbits)))
 
#define FILL_LOWBITS(d, numbits)   ((d) | (LSHIFTX(((d)*0+1), (numbits))-1))
 
#define POW2_P(x)   (((x)&((x)-1))==0)
 
#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 BDIGIT_MSB(d)   (((d) & BIGRAD_HALF) != 0)
 
#define BIGUP(x)   LSHIFTX(((x) + (BDIGIT_DBL)0), BITSPERDIG)
 
#define BIGDN(x)   RSHIFT((x),BITSPERDIG)
 
#define BIGLO(x)   ((BDIGIT)((x) & BDIGMAX))
 
#define BDIGMAX   ((BDIGIT)(BIGRAD-1))
 
#define BDIGIT_DBL_MAX   (~(BDIGIT_DBL)0)
 
#define BIGZEROP(x)
 
#define BIGSIZE(x)
 
#define BIGDIVREM_EXTRA_WORDS   1
 
#define roomof(n, m)   ((long)(((n)+(m)-1) / (m)))
 
#define bdigit_roomof(n)   roomof(n, SIZEOF_BDIGITS)
 
#define BARY_ARGS(ary)   ary, numberof(ary)
 
#define BARY_ADD(z, x, y)   bary_add(BARY_ARGS(z), BARY_ARGS(x), BARY_ARGS(y))
 
#define BARY_SUB(z, x, y)   bary_sub(BARY_ARGS(z), BARY_ARGS(x), BARY_ARGS(y))
 
#define BARY_SHORT_MUL(z, x, y)   bary_short_mul(BARY_ARGS(z), BARY_ARGS(x), BARY_ARGS(y))
 
#define BARY_DIVMOD(q, r, x, y)   bary_divmod(BARY_ARGS(q), BARY_ARGS(r), BARY_ARGS(x), BARY_ARGS(y))
 
#define BARY_ZERO_P(x)   bary_zero_p(BARY_ARGS(x))
 
#define RBIGNUM_SET_NEGATIVE_SIGN(b)   RBIGNUM_SET_SIGN(b, 0)
 
#define RBIGNUM_SET_POSITIVE_SIGN(b)   RBIGNUM_SET_SIGN(b, 1)
 
#define bignew(len, sign)   bignew_1(rb_cBignum,(len),(sign))
 
#define BDIGITS_ZERO(ptr, n)
 
#define BARY_TRUNC(ds, n)
 
#define KARATSUBA_BALANCED(xn, yn)   ((yn)/2 < (xn))
 
#define TOOM3_BALANCED(xn, yn)   (((yn)+2)/3 * 2 < (xn))
 
#define GMP_MUL_DIGITS   20
 
#define KARATSUBA_MUL_DIGITS   70
 
#define TOOM3_MUL_DIGITS   150
 
#define GMP_DIV_DIGITS   20
 
#define GMP_BIG2STR_DIGITS   20
 
#define GMP_STR2BIG_DIGITS   20
 
#define U16(a)   ((uint16_t)(a))
 
#define U32(a)   ((uint32_t)(a))
 
#define INTEGER_PACK_WORDORDER_MASK
 
#define INTEGER_PACK_BYTEORDER_MASK
 
#define FILL_DD   integer_pack_fill_dd(&dp, &de, &dd, &numbits_in_dd)
 
#define TAKE_LOWBITS(n)   integer_pack_take_lowbits(n, &dd, &numbits_in_dd)
 
#define PUSH_BITS(data, numbits)   integer_unpack_push_bits(data, numbits, &dd, &numbits_in_dd, &dp)
 
#define BIGNUM_DEBUG   0
 
#define ON_DEBUG(x)
 
#define RBIGNUM_SET_LEN(b, l)
 
#define QUAD_SIZE   8
 
#define conv_digit(c)   (ruby_digit36_to_number_table[(unsigned char)(c)])
 
#define MAX_BASE36_POWER_TABLE_ENTRIES   (SIZEOF_SIZE_T * CHAR_BIT + 1)
 
#define DBL_BIGDIG   ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)
 

Typedefs

typedef voidmulfunc_t )(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 

Enumerations

enum  big_op_t { big_op_gt, big_op_ge, big_op_lt, big_op_le }
 

Functions

 STATIC_ASSERT (sizeof_bdigit_dbl, sizeof(BDIGIT_DBL)==SIZEOF_BDIGIT_DBL)
 
 STATIC_ASSERT (sizeof_bdigit_dbl_signed, sizeof(BDIGIT_DBL_SIGNED)==SIZEOF_BDIGIT_DBL)
 
 STATIC_ASSERT (sizeof_bdigit, SIZEOF_BDIGITS<=sizeof(BDIGIT))
 
 STATIC_ASSERT (sizeof_bdigit_and_dbl, SIZEOF_BDIGITS *2<=SIZEOF_BDIGIT_DBL)
 
 STATIC_ASSERT (bdigit_signedness, 0< (BDIGIT)-1)
 
 STATIC_ASSERT (bdigit_dbl_signedness, 0< (BDIGIT_DBL)-1)
 
 STATIC_ASSERT (bdigit_dbl_signed_signedness, 0 >(BDIGIT_DBL_SIGNED)-1)
 
 STATIC_ASSERT (rbignum_embed_len_max, RBIGNUM_EMBED_LEN_MAX<=(RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT))
 
 STATIC_ASSERT (sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGITS%SIZEOF_LONG==0)
 
static BDIGIT bigdivrem_single (BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT y)
 
static void bary_divmod (BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
static VALUE bigmul0 (VALUE x, VALUE y)
 
static void bary_mul_toom3 (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 
static VALUE bignew_1 (VALUE klass, long len, int sign)
 
static VALUE bigtrunc (VALUE x)
 
static VALUE bigsq (VALUE x)
 
static void bigdivmod (VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
 
static VALUE power_cache_get_power (int base, int power_level, size_t *numdigits_ret)
 
static int nlz (BDIGIT x)
 
static BDIGIT_DBL maxpow_in_bdigit_dbl (int base, int *exp_ret)
 
static BDIGIT_DBL bary2bdigitdbl (const BDIGIT *ds, size_t n)
 
static void bdigitdbl2bary (BDIGIT *ds, size_t n, BDIGIT_DBL num)
 
static int bary_cmp (const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
static BDIGIT bary_small_lshift (BDIGIT *zds, const BDIGIT *xds, size_t n, int shift)
 
static void bary_small_rshift (BDIGIT *zds, const BDIGIT *xds, size_t n, int shift, BDIGIT higher_bdigit)
 
static int bary_zero_p (BDIGIT *xds, size_t xn)
 
static void bary_neg (BDIGIT *ds, size_t n)
 
static int bary_2comp (BDIGIT *ds, size_t n)
 
static void bary_swap (BDIGIT *ds, size_t num_bdigits)
 
static void validate_integer_pack_format (size_t numwords, size_t wordsize, size_t nails, int flags, int supported_flags)
 
static void integer_pack_loop_setup (size_t numwords, size_t wordsize, size_t nails, int flags, size_t *word_num_fullbytes_ret, int *word_num_partialbits_ret, size_t *word_start_ret, ssize_t *word_step_ret, size_t *word_last_ret, size_t *byte_start_ret, int *byte_step_ret)
 
static void integer_pack_fill_dd (BDIGIT **dpp, BDIGIT **dep, BDIGIT_DBL *ddp, int *numbits_in_dd_p)
 
static BDIGIT_DBL integer_pack_take_lowbits (int n, BDIGIT_DBL *ddp, int *numbits_in_dd_p)
 
static int bytes_2comp (unsigned char *buf, size_t len)
 
static int bary_pack (int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 
static size_t integer_unpack_num_bdigits_small (size_t numwords, size_t wordsize, size_t nails, int *nlp_bits_ret)
 
static size_t integer_unpack_num_bdigits_generic (size_t numwords, size_t wordsize, size_t nails, int *nlp_bits_ret)
 
static size_t integer_unpack_num_bdigits (size_t numwords, size_t wordsize, size_t nails, int *nlp_bits_ret)
 
static void integer_unpack_push_bits (int data, int numbits, BDIGIT_DBL *ddp, int *numbits_in_dd_p, BDIGIT **dpp)
 
static int integer_unpack_single_bdigit (BDIGIT u, size_t size, int flags, BDIGIT *dp)
 
static int bary_unpack_internal (BDIGIT *bdigits, size_t num_bdigits, const void *words, size_t numwords, size_t wordsize, size_t nails, int flags, int nlp_bits)
 
static void bary_unpack (BDIGIT *bdigits, size_t num_bdigits, const void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 
static int bary_subb (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, int borrow)
 
static int bary_sub (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
static int bary_sub_one (BDIGIT *zds, size_t zn)
 
static int bary_addc (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, int carry)
 
static int bary_add (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
static int bary_add_one (BDIGIT *ds, size_t n)
 
static void bary_mul_single (BDIGIT *zds, size_t zn, BDIGIT x, BDIGIT y)
 
static int bary_muladd_1xN (BDIGIT *zds, size_t zn, BDIGIT x, const BDIGIT *yds, size_t yn)
 
static BDIGIT_DBL_SIGNED bigdivrem_mulsub (BDIGIT *zds, size_t zn, BDIGIT x, const BDIGIT *yds, size_t yn)
 
static int bary_mulsub_1xN (BDIGIT *zds, size_t zn, BDIGIT x, const BDIGIT *yds, size_t yn)
 
static void bary_mul_normal (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
VALUE rb_big_mul_normal (VALUE x, VALUE y)
 
static void bary_sq_fast (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn)
 
VALUE rb_big_sq_fast (VALUE x)
 
static void bary_mul_balance_with_mulfunc (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn, mulfunc_t *mulfunc)
 
VALUE rb_big_mul_balance (VALUE x, VALUE y)
 
static void bary_mul_karatsuba (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 
VALUE rb_big_mul_karatsuba (VALUE x, VALUE y)
 
VALUE rb_big_mul_toom3 (VALUE x, VALUE y)
 
static void bary_short_mul (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
static int bary_sparse_p (const BDIGIT *ds, size_t n)
 
static int bary_mul_precheck (BDIGIT **zdsp, size_t *znp, const BDIGIT **xdsp, size_t *xnp, const BDIGIT **ydsp, size_t *ynp)
 
static void bary_mul_karatsuba_branch (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 
static void bary_mul_karatsuba_start (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 
static void bary_mul_toom3_branch (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 
static void bary_mul_toom3_start (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 
static void bary_mul (BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
static voidbigdivrem1 (void *ptr)
 
static void rb_big_stop (void *ptr)
 
static BDIGIT bigdivrem_single1 (BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT x_higher_bdigit, BDIGIT y)
 
static void bigdivrem_restoring (BDIGIT *zds, size_t zn, BDIGIT *yds, size_t yn)
 
static void bary_divmod_normal (BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
VALUE rb_big_divrem_normal (VALUE x, VALUE y)
 
static void bary_divmod_branch (BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 
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)
 
VALUE rb_big_new (long len, int sign)
 
VALUE rb_big_clone (VALUE x)
 
static void big_extend_carry (VALUE x)
 
static void get2comp (VALUE x)
 
void rb_big_2comp (VALUE x)
 
static BDIGIT abs2twocomp (VALUE *xp, long *n_ret)
 
static void twocomp2abs_bang (VALUE x, int hibits)
 
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)
 
size_t rb_absint_size (VALUE val, int *nlz_bits_ret)
 
static size_t absint_numwords_small (size_t numbytes, int nlz_bits_in_msbyte, size_t word_numbits, size_t *nlz_bits_ret)
 
static size_t absint_numwords_generic (size_t numbytes, int nlz_bits_in_msbyte, size_t word_numbits, size_t *nlz_bits_ret)
 
size_t rb_absint_numwords (VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
 
int rb_absint_singlebit_p (VALUE val)
 
int rb_integer_pack (VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 
VALUE rb_integer_unpack (const void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 
void rb_quad_pack (char *buf, VALUE val)
 
VALUE rb_quad_unpack (const char *buf, int signed_p)
 
static void str2big_scan_digits (const char *s, const char *str, int base, int badcheck, size_t *num_digits_p, size_t *len_p)
 
static VALUE str2big_poweroftwo (int sign, const char *digits_start, const char *digits_end, size_t num_digits, int bits_per_digit)
 
static VALUE str2big_normal (int sign, const char *digits_start, const char *digits_end, size_t num_bdigits, int base)
 
static VALUE str2big_karatsuba (int sign, const char *digits_start, const char *digits_end, size_t num_digits, size_t num_bdigits, int digits_per_bdigits_dbl, int base)
 
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_str2big_poweroftwo (VALUE arg, int base, int badcheck)
 
VALUE rb_str2big_normal (VALUE arg, int base, int badcheck)
 
VALUE rb_str2big_karatsuba (VALUE arg, int base, int badcheck)
 
VALUE rb_cstr2inum (const char *str, int base)
 
VALUE rb_str2inum (VALUE str, int base)
 
static VALUE big_shift3 (VALUE x, int lshift_p, size_t shift_numdigits, int shift_numbits)
 
static VALUE big_shift2 (VALUE x, int lshift_p, VALUE y)
 
static VALUE big_lshift (VALUE x, unsigned long shift)
 
static VALUE big_rshift (VALUE x, unsigned long shift)
 
static void power_cache_init (void)
 
static long big2str_find_n1 (VALUE x, int base)
 
static void big2str_alloc (struct big2str_struct *b2s, size_t len)
 
static void big2str_2bdigits (struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t taillen)
 
static void big2str_karatsuba (struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t wn, int power_level, size_t taillen)
 
static VALUE big2str_base_poweroftwo (VALUE x, int base)
 
VALUE rb_big2str_poweroftwo (VALUE x, int base)
 
static VALUE big2str_generic (VALUE x, int base)
 
VALUE rb_big2str_generic (VALUE x, int base)
 
static VALUE rb_big2str1 (VALUE x, int base)
 
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 unsigned long big2ulong (VALUE x, const char *type)
 
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 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 VALUE bigsub (VALUE x, VALUE y)
 
static VALUE bigadd_int (VALUE x, long y)
 
static VALUE bigsub_int (VALUE x, long y0)
 
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)
 
VALUE rb_big_mul (VALUE x, VALUE y)
 
static VALUE bigdivrem (VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
 
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 VALUE big_shift (VALUE x, long n)
 
static VALUE big_fdiv (VALUE x, VALUE y, long ey)
 
static VALUE big_fdiv_int (VALUE x, VALUE y)
 
static VALUE big_fdiv_float (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 xn, BDIGIT hibitsx, long y)
 
VALUE rb_big_and (VALUE x, VALUE y)
 
static VALUE bigor_int (VALUE x, long xn, BDIGIT hibitsx, long y)
 
VALUE rb_big_or (VALUE x, VALUE y)
 
static VALUE bigxor_int (VALUE x, long xn, BDIGIT hibitsx, long y)
 
VALUE rb_big_xor (VALUE x, VALUE y)
 
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_bit_length (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
 
const char ruby_digitmap [] = "0123456789abcdefghijklmnopqrstuvwxyz"
 
static mulfunc_t bary_mul_toom3_start
 
static mulfunc_t bary_mul_karatsuba_start
 
static VALUE base36_power_cache [35][MAX_BASE36_POWER_TABLE_ENTRIES]
 
static size_t base36_numdigits_cache [35][MAX_BASE36_POWER_TABLE_ENTRIES]
 

Macro Definition Documentation

#define ALIGNOF (   type)    ((int)offsetof(struct { char f1; type f2; }, f2))

Definition at line 66 of file bignum.c.

Referenced by bary_pack(), and bary_unpack_internal().

#define BARY_ADD (   z,
  x,
 
)    bary_add(BARY_ARGS(z), BARY_ARGS(x), BARY_ARGS(y))

Definition at line 106 of file bignum.c.

Referenced by absint_numwords_generic().

#define BARY_ARGS (   ary)    ary, numberof(ary)

Definition at line 104 of file bignum.c.

Referenced by absint_numwords_generic(), and rb_big_bit_length().

#define BARY_DIVMOD (   q,
  r,
  x,
 
)    bary_divmod(BARY_ARGS(q), BARY_ARGS(r), BARY_ARGS(x), BARY_ARGS(y))

Definition at line 109 of file bignum.c.

Referenced by absint_numwords_generic().

#define BARY_SHORT_MUL (   z,
  x,
 
)    bary_short_mul(BARY_ARGS(z), BARY_ARGS(x), BARY_ARGS(y))

Definition at line 108 of file bignum.c.

Referenced by absint_numwords_generic(), and rb_big_bit_length().

#define BARY_SUB (   z,
  x,
 
)    bary_sub(BARY_ARGS(z), BARY_ARGS(x), BARY_ARGS(y))

Definition at line 107 of file bignum.c.

Referenced by absint_numwords_generic(), and rb_big_bit_length().

#define BARY_TRUNC (   ds,
  n 
)
Value:
do { \
while (0 < (n) && (ds)[(n)-1] == 0) \
(n)--; \
} while (0)
while(a->frac[0]/shift==0)
Definition: bigdecimal.c:5241
data n
Definition: enum.c:860

Definition at line 126 of file bignum.c.

Referenced by abs2twocomp(), bary_cmp(), bary_divmod(), bary_mul_toom3(), big2str_generic(), big2str_karatsuba(), bigdivrem(), bigfixize(), rb_big2str1(), rb_big_divrem_normal(), and str2big_karatsuba().

#define BARY_ZERO_P (   x)    bary_zero_p(BARY_ARGS(x))

Definition at line 110 of file bignum.c.

Referenced by absint_numwords_generic().

#define BDIGIT_DBL_MAX   (~(BDIGIT_DBL)0)

Definition at line 83 of file bignum.c.

Referenced by maxpow_in_bdigit_dbl().

#define BDIGIT_MSB (   d)    (((d) & BIGRAD_HALF) != 0)

Definition at line 78 of file bignum.c.

Referenced by bary_unpack_internal(), bigdivrem_restoring(), and rb_integer_unpack().

#define bdigit_roomof (   n)    roomof(n, SIZEOF_BDIGITS)
#define BDIGITS (   x)    (RBIGNUM_DIGITS(x))
#define BDIGITS_ZERO (   ptr,
  n 
)
Value:
do { \
BDIGIT *bdigitz_zero_ptr = (ptr); \
size_t bdigitz_zero_n = (n); \
while (bdigitz_zero_n) { \
*bdigitz_zero_ptr++ = 0; \
bdigitz_zero_n--; \
} \
} while (0)
while(a->frac[0]/shift==0)
Definition: bigdecimal.c:5241
return ptr
Definition: tcltklib.c:789
data n
Definition: enum.c:860
#define BDIGIT
Definition: bigdecimal.h:40

Definition at line 117 of file bignum.c.

Referenced by bary_divmod(), bary_divmod_normal(), bary_mul_balance_with_mulfunc(), bary_mul_normal(), bary_mul_precheck(), bary_mul_single(), bary_mul_toom3(), bary_pack(), bary_sq_fast(), bary_unpack(), big_shift3(), and str2big_normal().

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

Definition at line 2871 of file bignum.c.

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

Definition at line 76 of file bignum.c.

Referenced by big2dbl(), and dbl2big().

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

Definition at line 77 of file bignum.c.

#define BIGSIZE (   x)
Value:
(RBIGNUM_LEN(x) == 0 ? (size_t)0 : \
BDIGITS(x)[RBIGNUM_LEN(x)-1] ? \
#define RBIGNUM_LEN(b)
#define BDIGITS(x)
Definition: bignum.c:74
size_t rb_absint_size(VALUE val, int *nlz_bits_ret)
Definition: bignum.c:3231
#define CHAR_BIT
Definition: ruby.h:198
static int nlz(BDIGIT x)
Definition: bignum.c:159
#define SIZEOF_BDIGITS
Definition: bigdecimal.h:43
#define NULL
Definition: _sdbm.c:102

Definition at line 96 of file bignum.c.

Referenced by big2ulong(), rb_big_aref(), and rb_big_size().

#define BIGUP (   x)    LSHIFTX(((x) + (BDIGIT_DBL)0), BITSPERDIG)
#define BIGZEROP (   x)
Value:
(RBIGNUM_LEN(x) == 0 || \
(BDIGITS(x)[0] == 0 && \
(RBIGNUM_LEN(x) == 1 || bigzero_p(x))))
#define RBIGNUM_LEN(b)
#define BDIGITS(x)
Definition: bignum.c:74
static int bigzero_p(VALUE x)
Definition: bignum.c:2897

Definition at line 93 of file bignum.c.

Referenced by big2str_find_n1(), big_shift2(), bigdivmod(), rb_big2str0(), rb_big_pow(), rb_bigzero_p(), and rb_cmpint().

#define BITSPERDIG   (SIZEOF_BDIGITS*CHAR_BIT)
#define CLEAR_LOWBITS (   d,
  numbits 
)    ((d) & LSHIFTX(~((d)*0), (numbits)))

Definition at line 70 of file bignum.c.

Referenced by bary_pack().

#define conv_digit (   c)    (ruby_digit36_to_number_table[(unsigned char)(c)])
#define DBL_BIGDIG   ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)

Referenced by big_fdiv(), and big_fdiv_int().

#define FILL_DD   integer_pack_fill_dd(&dp, &de, &dd, &numbits_in_dd)

Referenced by bary_pack().

#define FILL_LOWBITS (   d,
  numbits 
)    ((d) | (LSHIFTX(((d)*0+1), (numbits))-1))

Definition at line 71 of file bignum.c.

Referenced by bary_pack().

#define GMP_BIG2STR_DIGITS   20

Definition at line 139 of file bignum.c.

Referenced by rb_big2str1().

#define GMP_DIV_DIGITS   20

Definition at line 138 of file bignum.c.

Referenced by bary_divmod_branch().

#define GMP_MUL_DIGITS   20

Definition at line 134 of file bignum.c.

Referenced by bary_mul(), and bigsq().

#define GMP_STR2BIG_DIGITS   20

Definition at line 140 of file bignum.c.

Referenced by rb_cstr_to_inum().

#define HOST_BIGENDIAN_P   0

Definition at line 64 of file bignum.c.

Referenced by bary_pack(), and bary_unpack_internal().

#define INTEGER_PACK_BYTEORDER_MASK
Value:
#define INTEGER_PACK_LSBYTE_FIRST
#define INTEGER_PACK_MSBYTE_FIRST
#define INTEGER_PACK_NATIVE_BYTE_ORDER

Definition at line 484 of file bignum.c.

Referenced by bary_pack(), bary_unpack_internal(), integer_pack_loop_setup(), and validate_integer_pack_format().

#define INTEGER_PACK_WORDORDER_MASK
Value:
#define INTEGER_PACK_MSWORD_FIRST
#define INTEGER_PACK_LSWORD_FIRST

Definition at line 481 of file bignum.c.

Referenced by bary_pack(), bary_unpack_internal(), integer_pack_loop_setup(), and validate_integer_pack_format().

#define KARATSUBA_BALANCED (   xn,
  yn 
)    ((yn)/2 < (xn))
#define KARATSUBA_MUL_DIGITS   70

Definition at line 135 of file bignum.c.

Referenced by bary_mul(), bary_mul_karatsuba_branch(), bigsq(), and rb_cstr_to_inum().

#define LSHIFTABLE (   d,
  n 
)    ((n) < sizeof(d) * CHAR_BIT)

Definition at line 68 of file bignum.c.

#define LSHIFTX (   d,
  n 
)    (!LSHIFTABLE(d, n) ? 0 : ((d) << (!LSHIFTABLE(d, n) ? 0 : (n))))

Definition at line 69 of file bignum.c.

Referenced by integer_unpack_single_bdigit().

#define MAX_BASE36_POWER_TABLE_ENTRIES   (SIZEOF_SIZE_T * CHAR_BIT + 1)

Definition at line 4482 of file bignum.c.

Referenced by big2str_generic(), power_cache_get_power(), and power_cache_init().

#define ON_DEBUG (   x)

Definition at line 2893 of file bignum.c.

#define POW2_P (   x)    (((x)&((x)-1))==0)
#define PUSH_BITS (   data,
  numbits 
)    integer_unpack_push_bits(data, numbits, &dd, &numbits_in_dd, &dp)

Referenced by bary_unpack_internal().

#define QUAD_SIZE   8

Definition at line 3688 of file bignum.c.

Referenced by rb_quad_pack(), and rb_quad_unpack().

#define RB_BIGNUM_TYPE_P (   x)    RB_TYPE_P((x), T_BIGNUM)
#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_SHIFT
#define RBIGNUM_EMBED_LEN_MASK
VP_EXPORT void
Definition: bigdecimal.c:5207
Real * b
Definition: bigdecimal.c:1198
#define RBIGNUM(obj)
#define RBASIC(obj)
#define RBIGNUM_EMBED_FLAG

Definition at line 2930 of file bignum.c.

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

#define RBIGNUM_SET_NEGATIVE_SIGN (   b)    RBIGNUM_SET_SIGN(b, 0)

Definition at line 112 of file bignum.c.

Referenced by bigsub(), and rb_big_neg().

#define RBIGNUM_SET_POSITIVE_SIGN (   b)    RBIGNUM_SET_SIGN(b, 1)

Definition at line 113 of file bignum.c.

Referenced by rb_big_neg().

#define roomof (   n,
  m 
)    ((long)(((n)+(m)-1) / (m)))
#define SIZEOF_BDIGIT_DBL   SIZEOF_LONG_LONG

Definition at line 40 of file bignum.c.

Referenced by big2str_2bdigits().

#define TAKE_LOWBITS (   n)    integer_pack_take_lowbits(n, &dd, &numbits_in_dd)

Referenced by bary_pack().

#define TOOM3_BALANCED (   xn,
  yn 
)    (((yn)+2)/3 * 2 < (xn))
#define TOOM3_MUL_DIGITS   150

Definition at line 136 of file bignum.c.

Referenced by bary_mul_toom3_branch().

#define U16 (   a)    ((uint16_t)(a))

Definition at line 168 of file bignum.c.

#define U32 (   a)    ((uint32_t)(a))

Definition at line 169 of file bignum.c.

Typedef Documentation

typedef void( mulfunc_t)(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)

Definition at line 142 of file bignum.c.

Enumeration Type Documentation

enum big_op_t
Enumerator
big_op_gt 
big_op_ge 
big_op_lt 
big_op_le 

Definition at line 5419 of file bignum.c.

Function Documentation

static BDIGIT abs2twocomp ( VALUE xp,
long *  n_ret 
)
static
static size_t absint_numwords_generic ( size_t  numbytes,
int  nlz_bits_in_msbyte,
size_t  word_numbits,
size_t *  nlz_bits_ret 
)
static
static size_t absint_numwords_small ( size_t  numbytes,
int  nlz_bits_in_msbyte,
size_t  word_numbits,
size_t *  nlz_bits_ret 
)
static

Definition at line 3278 of file bignum.c.

References CHAR_BIT, div, and mod.

Referenced by rb_absint_numwords().

static BDIGIT_DBL bary2bdigitdbl ( const BDIGIT ds,
size_t  n 
)
inlinestatic

Definition at line 360 of file bignum.c.

References assert, and BIGUP.

Referenced by bary_divmod(), big2str_2bdigits(), and bigdivrem().

static int bary_2comp ( BDIGIT ds,
size_t  n 
)
static

Definition at line 449 of file bignum.c.

References BIGLO, i, and n.

Referenced by abs2twocomp(), bary_mul_karatsuba(), bary_mul_toom3(), bary_pack(), bary_unpack_internal(), bigsub(), and get2comp().

static int bary_add ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static
static int bary_add_one ( BDIGIT ds,
size_t  n 
)
static

Definition at line 1428 of file bignum.c.

References BIGLO, i, and n.

Referenced by bary_mul_karatsuba(), and rb_big_neg().

static int bary_addc ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
int  carry 
)
static

Definition at line 1376 of file bignum.c.

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

Referenced by bary_add(), and bary_mul_karatsuba().

static int bary_cmp ( const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 381 of file bignum.c.

References BARY_TRUNC.

Referenced by big2str_karatsuba(), and rb_big_cmp().

static void bary_divmod ( BDIGIT qds,
size_t  qn,
BDIGIT rds,
size_t  rn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static
static void bary_divmod_branch ( BDIGIT qds,
size_t  qn,
BDIGIT rds,
size_t  rn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 2814 of file bignum.c.

References bary_divmod_normal(), and GMP_DIV_DIGITS.

Referenced by bary_divmod(), and bigdivrem().

static void bary_divmod_normal ( BDIGIT qds,
size_t  qn,
BDIGIT rds,
size_t  rn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static
static void bary_mul ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static
static void bary_mul_balance_with_mulfunc ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
BDIGIT wds,
size_t  wn,
mulfunc_t mulfunc 
)
static
static void bary_mul_karatsuba ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
BDIGIT wds,
size_t  wn 
)
static
static void bary_mul_karatsuba_branch ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
BDIGIT wds,
size_t  wn 
)
static
static void bary_mul_karatsuba_start ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
BDIGIT wds,
size_t  wn 
)
static

Definition at line 2454 of file bignum.c.

References bary_mul_karatsuba_branch(), and bary_mul_precheck().

static void bary_mul_normal ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 1527 of file bignum.c.

References assert, bary_muladd_1xN(), BDIGITS_ZERO, and i.

Referenced by bary_mul_precheck(), bary_short_mul(), and rb_big_mul_normal().

static int bary_mul_precheck ( BDIGIT **  zdsp,
size_t *  znp,
const BDIGIT **  xdsp,
size_t *  xnp,
const BDIGIT **  ydsp,
size_t *  ynp 
)
static
static void bary_mul_single ( BDIGIT zds,
size_t  zn,
BDIGIT  x,
BDIGIT  y 
)
static

Definition at line 1440 of file bignum.c.

References assert, BDIGIT_DBL, bdigitdbl2bary(), BDIGITS_ZERO, and n.

Referenced by bary_short_mul().

static void bary_mul_toom3 ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
BDIGIT wds,
size_t  wn 
)
static
static void bary_mul_toom3_branch ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
BDIGIT wds,
size_t  wn 
)
static
static void bary_mul_toom3_start ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
BDIGIT wds,
size_t  wn 
)
static

Definition at line 2479 of file bignum.c.

References bary_mul_precheck(), and bary_mul_toom3_branch().

static int bary_muladd_1xN ( BDIGIT zds,
size_t  zn,
BDIGIT  x,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 1452 of file bignum.c.

References assert, BDIGIT_DBL, BIGDN, BIGLO, j, and n.

Referenced by bary_mul_karatsuba(), bary_mul_normal(), and bary_mul_toom3().

static int bary_mulsub_1xN ( BDIGIT zds,
size_t  zn,
BDIGIT  x,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 1513 of file bignum.c.

References assert, BDIGIT_DBL_SIGNED, bigdivrem_mulsub(), BIGDN, and BIGLO.

Referenced by bary_mul_toom3().

static void bary_neg ( BDIGIT ds,
size_t  n 
)
static

Definition at line 442 of file bignum.c.

References BIGLO, and n.

Referenced by rb_big_neg().

static int bary_pack ( int  sign,
BDIGIT ds,
size_t  num_bdigits,
void words,
size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags 
)
static
static void bary_short_mul ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 2299 of file bignum.c.

References assert, bary_mul_normal(), bary_mul_single(), and rb_thread_check_ints().

Referenced by bary_mul(), and bary_mul_karatsuba_branch().

static BDIGIT bary_small_lshift ( BDIGIT zds,
const BDIGIT xds,
size_t  n,
int  shift 
)
static
static void bary_small_rshift ( BDIGIT zds,
const BDIGIT xds,
size_t  n,
int  shift,
BDIGIT  higher_bdigit 
)
static
static int bary_sparse_p ( const BDIGIT ds,
size_t  n 
)
inlinestatic

Definition at line 2314 of file bignum.c.

References c, and rb_genrand_ulong_limited().

Referenced by bary_mul_karatsuba_branch().

static void bary_sq_fast ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn 
)
static

Definition at line 1555 of file bignum.c.

References assert, BDIGIT, BDIGIT_DBL, BDIGITS_ZERO, BIGDN, BIGLO, c, i, int, j, and v.

Referenced by bary_mul(), bary_mul_karatsuba_branch(), bigsq(), and rb_big_sq_fast().

static int bary_sub ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 1364 of file bignum.c.

References bary_subb().

Referenced by bary_mul_karatsuba(), bary_mul_toom3(), and bigsub().

static int bary_sub_one ( BDIGIT zds,
size_t  zn 
)
static

Definition at line 1370 of file bignum.c.

References bary_subb(), and NULL.

Referenced by bary_mul_karatsuba().

static int bary_subb ( BDIGIT zds,
size_t  zn,
const BDIGIT xds,
size_t  xn,
const BDIGIT yds,
size_t  yn,
int  borrow 
)
static

Definition at line 1313 of file bignum.c.

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

Referenced by bary_sub(), and bary_sub_one().

static void bary_swap ( BDIGIT ds,
size_t  num_bdigits 
)
static

Definition at line 470 of file bignum.c.

References BDIGIT, and tmp.

Referenced by bary_pack(), and bary_unpack_internal().

static void bary_unpack ( BDIGIT bdigits,
size_t  num_bdigits,
const void words,
size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags 
)
static
static int bary_unpack_internal ( BDIGIT bdigits,
size_t  num_bdigits,
const void words,
size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags,
int  nlp_bits 
)
static
static int bary_zero_p ( BDIGIT xds,
size_t  xn 
)
static
static void bdigitdbl2bary ( BDIGIT ds,
size_t  n,
BDIGIT_DBL  num 
)
inlinestatic

Definition at line 372 of file bignum.c.

References assert, BDIGIT, BIGDN, and BIGLO.

Referenced by bary_mul_single(), and power_cache_get_power().

static double big2dbl ( VALUE  x)
static
static void big2str_2bdigits ( struct big2str_struct b2s,
BDIGIT xds,
size_t  xn,
size_t  taillen 
)
static
static void big2str_alloc ( struct big2str_struct b2s,
size_t  len 
)
static
static VALUE big2str_base_poweroftwo ( VALUE  x,
int  base 
)
static
static long big2str_find_n1 ( VALUE  x,
int  base 
)
static

Definition at line 4559 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 VALUE big2str_generic ( VALUE  x,
int  base 
)
static
static void big2str_karatsuba ( struct big2str_struct b2s,
BDIGIT xds,
size_t  xn,
size_t  wn,
int  power_level,
size_t  taillen 
)
static
static unsigned long big2ulong ( VALUE  x,
const char *  type 
)
static

Definition at line 5049 of file bignum.c.

References BDIGIT, BDIGITS, BIGSIZE, BITSPERDIG, rb_eRangeError, rb_raise(), and RBIGNUM_LEN.

Referenced by rb_big2long(), rb_big2ulong(), and rb_big_aref().

static void big_extend_carry ( VALUE  x)
static

Definition at line 3014 of file bignum.c.

References BDIGITS, rb_big_resize(), and RBIGNUM_LEN.

Referenced by get2comp(), rb_big_neg(), and rb_integer_unpack().

static VALUE big_fdiv ( VALUE  x,
VALUE  y,
long  ey 
)
static
static VALUE big_fdiv_float ( VALUE  x,
VALUE  y 
)
static

Definition at line 6300 of file bignum.c.

References big_fdiv(), dbl2big(), DBL_MANT_DIG, i, and RFLOAT_VALUE.

Referenced by rb_big_fdiv().

static VALUE big_fdiv_int ( VALUE  x,
VALUE  y 
)
static

Definition at line 6288 of file bignum.c.

References BDIGITS, big_fdiv(), big_shift(), bigtrunc(), BITSPERDIG, DBL_BIGDIG, nlz(), and RBIGNUM_LEN.

Referenced by rb_big_fdiv().

static VALUE big_ge ( VALUE  x,
VALUE  y 
)
static

Definition at line 5484 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 5470 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 5512 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

Definition at line 4467 of file bignum.c.

References big_shift3(), BITSPERDIG, and int.

Referenced by big_shift().

static VALUE big_lt ( VALUE  x,
VALUE  y 
)
static

Definition at line 5498 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 VALUE big_rshift ( VALUE  x,
unsigned long  shift 
)
static

Definition at line 4475 of file bignum.c.

References big_shift3(), BITSPERDIG, and int.

Referenced by big_shift().

static VALUE big_shift ( VALUE  x,
long  n 
)
static

Definition at line 6253 of file bignum.c.

References big_lshift(), and big_rshift().

Referenced by big_fdiv(), and big_fdiv_int().

static VALUE big_shift2 ( VALUE  x,
int  lshift_p,
VALUE  y 
)
static
static VALUE big_shift3 ( VALUE  x,
int  lshift_p,
size_t  shift_numdigits,
int  shift_numbits 
)
static
static VALUE bigadd ( VALUE  x,
VALUE  y,
int  sign 
)
static

Definition at line 5833 of file bignum.c.

References bary_add(), BDIGITS, bignew, bigsub(), len, RBIGNUM_LEN, and RBIGNUM_SIGN.

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

static VALUE bigadd_int ( VALUE  x,
long  y 
)
static
static VALUE bigand_int ( VALUE  x,
long  xn,
BDIGIT  hibitsx,
long  y 
)
static

Definition at line 6417 of file bignum.c.

References BDIGIT, bdigit_roomof, BDIGITS, BDIGMAX, BIGDN, BIGLO, bignew, bignorm(), i, INT2FIX, LONG2NUM, RB_GC_GUARD(), and twocomp2abs_bang().

Referenced by rb_big_and().

static void bigdivmod ( VALUE  x,
VALUE  y,
volatile VALUE divp,
volatile VALUE modp 
)
static

Definition at line 6108 of file bignum.c.

References bigadd(), bigdivrem(), BIGZEROP, mod, rb_int2big(), and RBIGNUM_SIGN.

Referenced by rb_big_divide(), rb_big_divmod(), and rb_big_modulo().

static VALUE bigdivrem ( VALUE  x,
VALUE  y,
volatile VALUE divp,
volatile VALUE modp 
)
static
static void* bigdivrem1 ( void ptr)
static
static BDIGIT_DBL_SIGNED bigdivrem_mulsub ( BDIGIT zds,
size_t  zn,
BDIGIT  x,
const BDIGIT yds,
size_t  yn 
)
static

Definition at line 1487 of file bignum.c.

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

Referenced by bary_mulsub_1xN(), and bigdivrem1().

static void bigdivrem_restoring ( BDIGIT zds,
size_t  zn,
BDIGIT yds,
size_t  yn 
)
static
static BDIGIT bigdivrem_single ( BDIGIT qds,
const BDIGIT xds,
size_t  xn,
BDIGIT  y 
)
static

Definition at line 2592 of file bignum.c.

References bigdivrem_single1().

Referenced by bary_divmod(), bary_mul_toom3(), and bigdivrem().

static BDIGIT bigdivrem_single1 ( BDIGIT qds,
const BDIGIT xds,
size_t  xn,
BDIGIT  x_higher_bdigit,
BDIGIT  y 
)
static

Definition at line 2567 of file bignum.c.

References assert, bary_small_rshift(), BDIGIT, BDIGIT_DBL, BIGUP, bit_length, i, POW2_P, and r.

Referenced by bigdivrem_restoring(), and bigdivrem_single().

static VALUE bigfixize ( VALUE  x)
inlinestatic
static VALUE bigmul0 ( VALUE  x,
VALUE  y 
)
static

Definition at line 5963 of file bignum.c.

References bary_mul(), BDIGIT, BDIGITS, bignew, bigsq(), RB_GC_GUARD(), RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by rb_big_mul(), and rb_big_pow().

static VALUE bignew_1 ( VALUE  klass,
long  len,
int  sign 
)
static
static VALUE bignorm ( VALUE  x)
static
static VALUE bigor_int ( VALUE  x,
long  xn,
BDIGIT  hibitsx,
long  y 
)
static
static VALUE bigsq ( VALUE  x)
static
static VALUE bigsub ( VALUE  x,
VALUE  y 
)
static

Definition at line 5626 of file bignum.c.

References bary_2comp(), bary_sub(), BDIGIT, BDIGITS, bignew, RBIGNUM_LEN, and RBIGNUM_SET_NEGATIVE_SIGN.

Referenced by bigadd().

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

Definition at line 6656 of file bignum.c.

References BDIGIT, bdigit_roomof, BDIGITS, BDIGMAX, BIGDN, BIGLO, bignew, bignorm(), i, RB_GC_GUARD(), RBIGNUM_LEN, and twocomp2abs_bang().

Referenced by rb_big_xor().

static int bigzero_p ( VALUE  x)
static

Definition at line 2897 of file bignum.c.

References bary_zero_p(), BDIGITS, and RBIGNUM_LEN.

static int bytes_2comp ( unsigned char *  buf,
size_t  len 
)
static

Definition at line 612 of file bignum.c.

References i, and len.

Referenced by bary_pack().

static VALUE dbl2big ( double  d)
static

Definition at line 5181 of file bignum.c.

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

Referenced by big_fdiv_float(), and rb_dbl2big().

static void get2comp ( VALUE  x)
static

Definition at line 3022 of file bignum.c.

References bary_2comp(), BDIGIT, BDIGITS, big_extend_carry(), i, and RBIGNUM_LEN.

Referenced by bigsub_int(), rb_big_2comp(), and twocomp2abs_bang().

void Init_Bignum ( void  )
static void integer_pack_fill_dd ( BDIGIT **  dpp,
BDIGIT **  dep,
BDIGIT_DBL ddp,
int numbits_in_dd_p 
)
inlinestatic

Definition at line 588 of file bignum.c.

References BDIGIT_DBL, BITSPERDIG, CHAR_BIT, and int.

static void integer_pack_loop_setup ( size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags,
size_t *  word_num_fullbytes_ret,
int word_num_partialbits_ret,
size_t *  word_start_ret,
ssize_t *  word_step_ret,
size_t *  word_last_ret,
size_t *  byte_start_ret,
int byte_step_ret 
)
static
static BDIGIT_DBL integer_pack_take_lowbits ( int  n,
BDIGIT_DBL ddp,
int numbits_in_dd_p 
)
inlinestatic

Definition at line 601 of file bignum.c.

References BDIGIT_DBL, n, and ret.

static size_t integer_unpack_num_bdigits ( size_t  numwords,
size_t  wordsize,
size_t  nails,
int nlp_bits_ret 
)
static
static size_t integer_unpack_num_bdigits_generic ( size_t  numwords,
size_t  wordsize,
size_t  nails,
int nlp_bits_ret 
)
static

Definition at line 968 of file bignum.c.

References BITSPERDIG, CHAR_BIT, and int.

Referenced by integer_unpack_num_bdigits().

static size_t integer_unpack_num_bdigits_small ( size_t  numwords,
size_t  wordsize,
size_t  nails,
int nlp_bits_ret 
)
static

Definition at line 958 of file bignum.c.

References BITSPERDIG, CHAR_BIT, and int.

Referenced by integer_unpack_num_bdigits().

static void integer_unpack_push_bits ( int  data,
int  numbits,
BDIGIT_DBL ddp,
int numbits_in_dd_p,
BDIGIT **  dpp 
)
inlinestatic

Definition at line 1050 of file bignum.c.

References BDIGIT_DBL, BIGDN, BIGLO, and BITSPERDIG.

static int integer_unpack_single_bdigit ( BDIGIT  u,
size_t  size,
int  flags,
BDIGIT dp 
)
static

Definition at line 1062 of file bignum.c.

References BDIGMAX, BIGLO, CHAR_BIT, INTEGER_PACK_2COMP, INTEGER_PACK_NEGATIVE, LSHIFTX, and SIZEOF_BDIGITS.

Referenced by bary_unpack_internal().

static BDIGIT_DBL maxpow_in_bdigit_dbl ( int  base,
int exp_ret 
)
static
static int nlz ( BDIGIT  x)
static
static VALUE power_cache_get_power ( int  base,
int  power_level,
size_t *  numdigits_ret 
)
inlinestatic
static void power_cache_init ( void  )
static

Definition at line 4488 of file bignum.c.

References i, j, MAX_BASE36_POWER_TABLE_ENTRIES, and Qnil.

Referenced by Init_Bignum().

size_t rb_absint_numwords ( VALUE  val,
size_t  word_numbits,
size_t *  nlz_bits_ret 
)
int rb_absint_singlebit_p ( VALUE  val)

Definition at line 3430 of file bignum.c.

References BDIGIT, bdigit_roomof, BDIGITS, BIGDN, BIGLO, d, dp, FIX2LONG, FIXNUM_P, i, numberof, POW2_P, rb_to_int(), RBIGNUM_LEN, and v.

Referenced by rb_big_bit_length(), and rb_str_format().

size_t rb_absint_size ( VALUE  val,
int nlz_bits_ret 
)
double rb_big2dbl ( VALUE  x)
SIGNED_VALUE rb_big2long ( VALUE  x)

Definition at line 5101 of file bignum.c.

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

Referenced by rb_num2long().

VALUE rb_big2str ( VALUE  x,
int  base 
)

Definition at line 5014 of file bignum.c.

References rb_big2str1().

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

VALUE rb_big2str0 ( VALUE  x,
int  base,
int  trim 
)
static VALUE rb_big2str1 ( VALUE  x,
int  base 
)
static
VALUE rb_big2str_generic ( VALUE  x,
int  base 
)

Definition at line 4892 of file bignum.c.

References big2str_generic().

VALUE rb_big2str_poweroftwo ( VALUE  x,
int  base 
)

Definition at line 4809 of file bignum.c.

References big2str_base_poweroftwo().

VALUE rb_big2ulong ( VALUE  x)

Definition at line 5084 of file bignum.c.

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

Referenced by rb_num2ulong_internal(), and rb_num_to_uint().

VALUE rb_big2ulong_pack ( VALUE  x)

Definition at line 5075 of file bignum.c.

References INTEGER_PACK_2COMP, INTEGER_PACK_NATIVE_BYTE_ORDER, and rb_integer_pack().

void rb_big_2comp ( VALUE  x)

Definition at line 3033 of file bignum.c.

References get2comp().

static VALUE rb_big_abs ( VALUE  x)
static

Definition at line 6940 of file bignum.c.

References rb_big_clone(), RBIGNUM_SET_SIGN, and RBIGNUM_SIGN.

Referenced by Init_Bignum().

VALUE rb_big_and ( VALUE  x,
VALUE  y 
)
static VALUE rb_big_aref ( VALUE  x,
VALUE  y 
)
static
static VALUE rb_big_bit_length ( VALUE  big)
static
VALUE rb_big_clone ( VALUE  x)

Definition at line 3004 of file bignum.c.

References BDIGIT, BDIGITS, bignew_1(), CLASS_OF, len, MEMCPY, RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by rb_big_abs(), rb_big_neg(), and rb_big_uminus().

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 6161 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_divrem_normal ( VALUE  x,
VALUE  y 
)
VALUE rb_big_eq ( VALUE  x,
VALUE  y 
)
VALUE rb_big_eql ( VALUE  x,
VALUE  y 
)

Definition at line 5561 of file bignum.c.

References BDIGIT, BDIGITS, MEMCMP, Qfalse, Qtrue, RB_BIGNUM_TYPE_P, RBIGNUM_LEN, and RBIGNUM_SIGN.

Referenced by Init_Bignum().

static VALUE rb_big_even_p ( VALUE  num)
static

Definition at line 7063 of file bignum.c.

References BDIGITS, Qfalse, Qtrue, and RBIGNUM_LEN.

Referenced by Init_Bignum().

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

Definition at line 6894 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 6174 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 6189 of file bignum.c.

References bigdivmod(), bignorm(), FIX2LONG, FIXNUM_P, RB_BIGNUM_TYPE_P, rb_int2big(), and rb_num_coerce_bin().

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

VALUE rb_big_mul ( VALUE  x,
VALUE  y 
)
VALUE rb_big_mul_balance ( VALUE  x,
VALUE  y 
)
VALUE rb_big_mul_karatsuba ( VALUE  x,
VALUE  y 
)
VALUE rb_big_mul_normal ( VALUE  x,
VALUE  y 
)

Definition at line 1540 of file bignum.c.

References bary_mul_normal(), BDIGITS, bignew, RB_GC_GUARD(), RBIGNUM_LEN, and RBIGNUM_SIGN.

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

Definition at line 2998 of file bignum.c.

References bignew.

VALUE rb_big_norm ( VALUE  x)

Definition at line 3136 of file bignum.c.

References bignorm().

Referenced by fix_aref(), and rand_range().

static VALUE rb_big_odd_p ( VALUE  num)
static

Definition at line 7047 of file bignum.c.

References BDIGITS, Qfalse, Qtrue, and RBIGNUM_LEN.

Referenced by Init_Bignum().

VALUE rb_big_or ( VALUE  x,
VALUE  y 
)
void rb_big_pack ( VALUE  val,
unsigned long *  buf,
long  num_longs 
)
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 6214 of file bignum.c.

References bigdivrem(), bignorm(), FIX2LONG, FIXNUM_P, RB_BIGNUM_TYPE_P, rb_int2big(), rb_intern, and rb_num_coerce_bin().

Referenced by Init_Bignum().

void rb_big_resize ( VALUE  big,
long  len 
)

Definition at line 2973 of file bignum.c.

References rb_big_realloc(), and RBIGNUM_SET_LEN.

Referenced by big_extend_carry(), bigfixize(), and bigtrunc().

VALUE rb_big_rshift ( VALUE  x,
VALUE  y 
)
static VALUE rb_big_size ( VALUE  big)
static

Definition at line 6962 of file bignum.c.

References BIGSIZE, and SIZET2NUM.

Referenced by Init_Bignum().

VALUE rb_big_sq_fast ( VALUE  x)

Definition at line 1609 of file bignum.c.

References bary_sq_fast(), BDIGITS, bignew, RB_GC_GUARD(), and RBIGNUM_LEN.

static void rb_big_stop ( void ptr)
static

Definition at line 2560 of file bignum.c.

References ptr, Qtrue, and big_div_struct::stop.

Referenced by bigdivrem_restoring().

static VALUE rb_big_to_f ( VALUE  x)
static

Definition at line 5293 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 5034 of file bignum.c.

References b, big2str_struct::base, NUM2INT, rb_big2str(), and rb_scan_args().

Referenced by Init_Bignum().

VALUE rb_big_uminus ( VALUE  x)

Definition at line 5578 of file bignum.c.

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

Referenced by Init_Bignum(), and rand_int().

VALUE rb_big_unpack ( unsigned long *  buf,
long  num_longs 
)
VALUE rb_big_xor ( VALUE  x,
VALUE  y 
)
int rb_bigzero_p ( VALUE  x)

Definition at line 2903 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 4373 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 3192 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 5349 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().

int rb_integer_pack ( VALUE  val,
void words,
size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags 
)
VALUE rb_integer_unpack ( const void words,
size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags 
)
void rb_quad_pack ( char *  buf,
VALUE  val 
)
VALUE rb_quad_unpack ( const char *  buf,
int  signed_p 
)
VALUE rb_str2big_karatsuba ( VALUE  arg,
int  base,
int  badcheck 
)
VALUE rb_str2big_normal ( VALUE  arg,
int  base,
int  badcheck 
)
VALUE rb_str2big_poweroftwo ( VALUE  arg,
int  base,
int  badcheck 
)
VALUE rb_str2inum ( VALUE  str,
int  base 
)

Definition at line 4379 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)
STATIC_ASSERT ( sizeof_bdigit_dbl  ,
sizeof(BDIGIT_DBL = =SIZEOF_BDIGIT_DBL 
)
STATIC_ASSERT ( sizeof_bdigit_dbl_signed  ,
sizeof(BDIGIT_DBL_SIGNED = =SIZEOF_BDIGIT_DBL 
)
STATIC_ASSERT ( sizeof_bdigit  ,
SIZEOF_BDIGITS<=  sizeofBDIGIT 
)
STATIC_ASSERT ( sizeof_bdigit_and_dbl  ,
SIZEOF_BDIGITS *2<=  SIZEOF_BDIGIT_DBL 
)
STATIC_ASSERT ( bdigit_signedness  )
STATIC_ASSERT ( bdigit_dbl_signedness  )
STATIC_ASSERT ( bdigit_dbl_signed_signedness  ,
,
(BDIGIT_DBL_SIGNED)-  1 
)
STATIC_ASSERT ( rbignum_embed_len_max  ,
RBIGNUM_EMBED_LEN_MAX<=  RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT 
)
STATIC_ASSERT ( sizeof_long_and_sizeof_bdigit  ,
SIZEOF_BDIGITS SIZEOF_LONG = =0 
)
static VALUE str2big_karatsuba ( int  sign,
const char *  digits_start,
const char *  digits_end,
size_t  num_digits,
size_t  num_bdigits,
int  digits_per_bdigits_dbl,
int  base 
)
static
static VALUE str2big_normal ( int  sign,
const char *  digits_start,
const char *  digits_end,
size_t  num_bdigits,
int  base 
)
static

Definition at line 3792 of file bignum.c.

References assert, BDIGIT, BDIGIT_DBL, BDIGITS, BDIGITS_ZERO, BIGDN, BIGLO, bignew, c, conv_digit, i, p, and big_div_struct::zds.

Referenced by rb_cstr_to_inum(), and rb_str2big_normal().

static VALUE str2big_poweroftwo ( int  sign,
const char *  digits_start,
const char *  digits_end,
size_t  num_digits,
int  bits_per_digit 
)
static

Definition at line 3751 of file bignum.c.

References assert, BDIGIT, BDIGIT_DBL, BDIGITS, BIGDN, BIGLO, bignew, BITSPERDIG, c, conv_digit, dp, p, and roomof.

Referenced by rb_cstr_to_inum(), and rb_str2big_poweroftwo().

static void str2big_scan_digits ( const char *  s,
const char *  str,
int  base,
int  badcheck,
size_t *  num_digits_p,
size_t *  len_p 
)
static
static void twocomp2abs_bang ( VALUE  x,
int  hibits 
)
static

Definition at line 3060 of file bignum.c.

References get2comp(), and RBIGNUM_SET_SIGN.

Referenced by big_shift3(), bigand_int(), bigor_int(), bigxor_int(), rb_big_and(), rb_big_or(), and rb_big_xor().

static void validate_integer_pack_format ( size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags,
int  supported_flags 
)
static

Variable Documentation

mulfunc_t bary_mul_karatsuba_start
static

Definition at line 145 of file bignum.c.

Referenced by bary_mul_karatsuba().

mulfunc_t bary_mul_toom3_start
static

Definition at line 144 of file bignum.c.

Referenced by bary_mul(), and bary_mul_toom3().

size_t base36_numdigits_cache[35][MAX_BASE36_POWER_TABLE_ENTRIES]
static

Definition at line 4485 of file bignum.c.

VALUE base36_power_cache[35][MAX_BASE36_POWER_TABLE_ENTRIES]
static

Definition at line 4484 of file bignum.c.

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

Definition at line 36 of file bignum.c.

Referenced by big2str_2bdigits(), big2str_base_poweroftwo(), rb_fix2str(), and rb_str_format().