Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
|
#include "internal.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "id.h"
#include <math.h>
#include <float.h>
#include <ctype.h>
#include "ruby_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 | 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) (BIGNUM_DIGITS(x)) |
#define | BITSPERDIG (SIZEOF_BDIGIT*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 | bdigit_roomof(n) roomof(n, SIZEOF_BDIGIT) |
#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 | BIGNUM_SET_NEGATIVE_SIGN(b) BIGNUM_SET_SIGN(b, 0) |
#define | BIGNUM_SET_POSITIVE_SIGN(b) BIGNUM_SET_SIGN(b, 1) |
#define | bignew(len, sign) bignew_1(rb_cInteger,(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 | NAIVE_MUL_DIGITS KARATSUBA_MUL_DIGITS |
#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 | reinterpret_cast(type, value) (type)value |
#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 | BIGNUM_SET_LEN(b, l) |
#define | conv_digit(c) (ruby_digit36_to_number_table[(unsigned char)(c)]) |
#define | ADV(n) |
#define | ASSERT_LEN() |
#define | MAX_BASE36_POWER_TABLE_ENTRIES (SIZEOF_SIZE_T * CHAR_BIT + 1) |
#define | rb_bdigit_dbl_isqrt(x) (BDIGIT)rb_ulong_isqrt(x) |
#define | BDIGIT_DBL_TO_DOUBLE(n) (double)(n) |
#define | MUL_MODULO(a, b, c) rb_int_modulo(rb_fix_mul_fix((a), (b)), (c)) |
Typedefs | |
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) |
Enumerations | |
enum | big_op_t { big_op_gt , big_op_ge , big_op_lt , big_op_le } |
enum | { DBL_BIGDIG = ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG) } |
Variables | |
const char | ruby_digitmap [] = "0123456789abcdefghijklmnopqrstuvwxyz" |
#define ASSERT_LEN | ( | ) |
#define BARY_TRUNC | ( | ds, | |
n | |||
) |
#define BDIGIT_DBL_MAX (~(BDIGIT_DBL)0) |
#define BDIGIT_MSB | ( | d | ) | (((d) & BIGRAD_HALF) != 0) |
#define BDIGITS | ( | x | ) | (BIGNUM_DIGITS(x)) |
#define BIGDN | ( | x | ) | RSHIFT((x),BITSPERDIG) |
#define bignew | ( | len, | |
sign | |||
) | bignew_1(rb_cInteger,(len),(sign)) |
#define BIGNUM_SET_LEN | ( | b, | |
l | |||
) |
#define BIGNUM_SET_NEGATIVE_SIGN | ( | b | ) | BIGNUM_SET_SIGN(b, 0) |
#define BIGNUM_SET_POSITIVE_SIGN | ( | b | ) | BIGNUM_SET_SIGN(b, 1) |
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG) |
#define BIGSIZE | ( | x | ) |
#define BIGUP | ( | x | ) | LSHIFTX(((x) + (BDIGIT_DBL)0), BITSPERDIG) |
#define BIGZEROP | ( | x | ) |
#define BITSPERDIG (SIZEOF_BDIGIT*CHAR_BIT) |
#define CLEAR_LOWBITS | ( | d, | |
numbits | |||
) | ((d) & LSHIFTX(~((d)*0), (numbits))) |
#define conv_digit | ( | c | ) | (ruby_digit36_to_number_table[(unsigned char)(c)]) |
#define FILL_DD integer_pack_fill_dd(&dp, &de, &dd, &numbits_in_dd) |
#define FILL_LOWBITS | ( | d, | |
numbits | |||
) | ((d) | (LSHIFTX(((d)*0+1), (numbits))-1)) |
#define INTEGER_PACK_BYTEORDER_MASK |
#define INTEGER_PACK_WORDORDER_MASK |
#define LSHIFTX | ( | d, | |
n | |||
) | (!LSHIFTABLE(d, n) ? 0 : ((d) << (!LSHIFTABLE(d, n) ? 0 : (n)))) |
#define MAX_BASE36_POWER_TABLE_ENTRIES (SIZEOF_SIZE_T * CHAR_BIT + 1) |
#define MUL_MODULO | ( | a, | |
b, | |||
c | |||
) | rb_int_modulo(rb_fix_mul_fix((a), (b)), (c)) |
#define NAIVE_MUL_DIGITS KARATSUBA_MUL_DIGITS |
#define PUSH_BITS | ( | data, | |
numbits | |||
) | integer_unpack_push_bits(data, numbits, &dd, &numbits_in_dd, &dp) |
#define rb_bdigit_dbl_isqrt | ( | x | ) | (BDIGIT)rb_ulong_isqrt(x) |
#define SIZEOF_BDIGIT_DBL SIZEOF_LONG_LONG |
enum big_op_t |
Definition at line 7177 of file bignum.c.
References rb_cBignum, rb_cInteger, rb_cObject, rb_define_const(), rb_define_method(), and rb_deprecate_constant().
NORETURN | ( | static inline void | invalid_integerVALUE s | ) |
NORETURN | ( | static inline void | invalid_radixint base | ) |
Definition at line 3382 of file bignum.c.
References CHAR_BIT, rb_absint_size(), and SIZE_MAX.
Definition at line 3446 of file bignum.c.
References BDIGIT, bdigit_roomof, BDIGITS, BIGDN, BIGLO, BIGNUM_LEN, dp, FIX2LONG, FIXNUM_P, i, numberof, POW2_P, rb_to_int(), and v.
Referenced by rb_big_bit_length().
Definition at line 3247 of file bignum.c.
References BDIGIT, bdigit_roomof, BDIGITS, BIGDN, BIGLO, BIGNUM_LEN, dp, FIX2LONG, FIXNUM_P, i, numberof, rb_to_int(), and v.
Referenced by rb_absint_numwords(), rb_big_bit_length(), and rb_num_to_uint().
Definition at line 5310 of file bignum.c.
Referenced by rb_big_mul(), rb_big_pow(), rb_float_div(), rb_float_minus(), rb_float_mul(), rb_float_plus(), and rb_float_pow().
Definition at line 5140 of file bignum.c.
Referenced by rb_num2long().
Definition at line 5091 of file bignum.c.
Referenced by rb_int2str().
Definition at line 5125 of file bignum.c.
Referenced by rb_num_to_uint().
Definition at line 6762 of file bignum.c.
References BIGNUM_NEGATIVE_P, BIGNUM_SET_POSITIVE_SIGN, and rb_big_clone().
Definition at line 6360 of file bignum.c.
References BDIGIT, i, RB_INTEGER_TYPE_P, rb_num_coerce_bit(), and yn().
Definition at line 6790 of file bignum.c.
References BDIGIT, bdigit_roomof, BIGNUM_NEGATIVE_P, CHAR_BIT, LONG2FIX, rb_absint_singlebit_p(), rb_absint_size(), SIZE_MAX, and SIZET2NUM.
Definition at line 3020 of file bignum.c.
References BIGNUM_LEN, and len.
Referenced by rb_big_abs(), rb_big_comp(), and rb_big_uminus().
Definition at line 5419 of file bignum.c.
References FIXNUM_P.
Referenced by rb_integer_float_cmp().
Definition at line 5564 of file bignum.c.
References BDIGIT, BDIGITS, BIGNUM_LEN, BIGNUM_POSITIVE_P, INT2FIX, n, and rb_big_clone().
Definition at line 6135 of file bignum.c.
References div(), FIX2LONG, FIXNUM_P, idDivmod, mod, RB_BIGNUM_TYPE_P, rb_int2big(), and rb_num_coerce_bin().
Definition at line 2714 of file bignum.c.
References BARY_TRUNC, BDIGIT, BDIGITS, BIGDIVREM_EXTRA_WORDS, bignew, BIGNUM_LEN, BIGNUM_SIGN, LONG2FIX, rb_assoc_new(), rb_num_zerodiv(), big_div_struct::yds, and yn().
Definition at line 5544 of file bignum.c.
References BDIGIT, BDIGITS, BIGNUM_LEN, BIGNUM_SIGN, MEMCMP, Qfalse, Qtrue, and RB_BIGNUM_TYPE_P.
Definition at line 6238 of file bignum.c.
References DBL2NUM, and rb_big_fdiv_double().
Definition at line 6911 of file bignum.c.
References BDIGIT, BDIGITS, BIGNUM_LEN, len, n, and rb_bdigit_dbl_isqrt.
Definition at line 6103 of file bignum.c.
References FIX2LONG, FIXNUM_P, RB_BIGNUM_TYPE_P, rb_int2big(), and rb_num_coerce_bin().
Definition at line 5933 of file bignum.c.
References DBL2NUM, FIX2LONG, FIXNUM_P, rb_big2dbl(), RB_BIGNUM_TYPE_P, RB_FLOAT_TYPE_P, rb_int2big(), rb_num_coerce_bin(), and RFLOAT_VALUE.
Definition at line 1689 of file bignum.c.
References bignew, BIGNUM_LEN, BIGNUM_SIGN, and yn().
Definition at line 1870 of file bignum.c.
References bignew, BIGNUM_LEN, BIGNUM_SIGN, KARATSUBA_BALANCED, rb_eArgError, rb_raise(), and yn().
Definition at line 1561 of file bignum.c.
References bignew, BIGNUM_LEN, BIGNUM_SIGN, and yn().
Definition at line 2267 of file bignum.c.
References bignew, BIGNUM_LEN, BIGNUM_SIGN, rb_eArgError, rb_raise(), TOOM3_BALANCED, and yn().
Definition at line 3152 of file bignum.c.
Referenced by rb_fix_aref().
Definition at line 6831 of file bignum.c.
References BDIGITS, BIGNUM_LEN, Qfalse, and Qtrue.
Referenced by rb_int_odd_p().
Definition at line 6479 of file bignum.c.
References BDIGIT, i, RB_INTEGER_TYPE_P, rb_num_coerce_bit(), and yn().
Definition at line 3215 of file bignum.c.
References buf, INTEGER_PACK_2COMP, INTEGER_PACK_LSWORD_FIRST, INTEGER_PACK_NATIVE_BYTE_ORDER, and rb_integer_pack().
Definition at line 5824 of file bignum.c.
References BIGNUM_SIGN, FIX2LONG, FIXNUM_P, and n.
Referenced by rb_int_succ().
Definition at line 6244 of file bignum.c.
References BIGNUM_NEGATIVE_P, BIGZEROP, INT2FIX, pow(), rb_big2dbl(), RB_BIGNUM_TYPE_P, rb_dbl_complex_new_polar_pi(), RB_FLOAT_TYPE_P, RFLOAT_VALUE, and SIGNED_VALUE.
Definition at line 6119 of file bignum.c.
References FIX2LONG, FIXNUM_P, RB_BIGNUM_TYPE_P, rb_int2big(), rb_intern, and rb_num_coerce_bin().
Definition at line 6772 of file bignum.c.
References BIGNUM_SIGN.
Definition at line 6784 of file bignum.c.
References rb_big_size(), and SIZET2NUM.
Definition at line 1630 of file bignum.c.
References bignew, and BIGNUM_LEN.
Definition at line 5554 of file bignum.c.
References BIGNUM_NEGATE, and rb_big_clone().
Definition at line 3223 of file bignum.c.
References buf, INTEGER_PACK_2COMP, INTEGER_PACK_LSWORD_FIRST, INTEGER_PACK_NATIVE_BYTE_ORDER, and rb_integer_unpack().
Definition at line 6573 of file bignum.c.
References BDIGIT, i, RB_INTEGER_TYPE_P, rb_num_coerce_bit(), and yn().
Definition at line 2925 of file bignum.c.
References BIGNUM_SIGN, BIGZEROP, FIX2LONG, FIXNUM_P, INT2FIX, NIL_P, RB_BIGNUM_TYPE_P, rb_cmperr(), rb_funcall, and RTEST.
Definition at line 4538 of file bignum.c.
References rb_cstr_to_inum(), and str.
Definition at line 4012 of file bignum.c.
Referenced by rb_cstr2inum().
Definition at line 5249 of file bignum.c.
Referenced by rb_integer_float_cmp(), and rb_node_case_when_optimizable_literal().
Definition at line 3180 of file bignum.c.
References BIGNUM_SET_NEGATIVE_SIGN, n, neg, and rb_uint2big().
Referenced by rb_big_divmod(), rb_big_modulo(), rb_big_mul(), rb_big_remainder(), and rb_int2inum().
VALUE rb_int_parse_cstr | ( | const char * | str, |
ssize_t | len, | ||
char ** | endp, | ||
size_t * | ndigits, | ||
int | base, | ||
int | flags | ||
) |
Definition at line 4041 of file bignum.c.
References ADV, ASSERT_LEN, bad, ISSPACE, len, Qnil, RB_INT_PARSE_PREFIX, RB_INT_PARSE_SIGN, and str.
Definition at line 7112 of file bignum.c.
References argc, argv, FIX2LONG, FIXNUM_P, HALF_LONG_MSB, long, rb_check_arity, rb_eRangeError, rb_eTypeError, rb_int_negative_p(), rb_int_pow(), rb_int_uminus(), RB_INTEGER_TYPE_P, rb_num_zerodiv(), and rb_raise().
Definition at line 5325 of file bignum.c.
References double, FIX2LONG, FIXNUM_MAX, FIXNUM_MIN, FIXNUM_P, INT2FIX, isinf, isnan, long, modf(), Qnil, rb_big_cmp(), rb_dbl2big(), RFLOAT_VALUE, and yn().
Referenced by rb_float_gt().
COMPILER_WARNING_POP VALUE rb_integer_float_eq | ( | VALUE | x, |
VALUE | y | ||
) |
int rb_integer_pack | ( | VALUE | val, |
void * | words, | ||
size_t | numwords, | ||
size_t | wordsize, | ||
size_t | nails, | ||
int | flags | ||
) |
Definition at line 3547 of file bignum.c.
References BDIGIT, bdigit_roomof, BDIGITS, BIGDN, BIGLO, BIGNUM_LEN, BIGNUM_POSITIVE_P, FIX2LONG, FIXNUM_P, i, numberof, RB_GC_GUARD, rb_to_int(), and v.
Referenced by rb_big_pack().
Definition at line 4544 of file bignum.c.
References rb_str_to_inum(), and str.
Definition at line 4246 of file bignum.c.
References len, rb_must_asciicompat(), RSTRING_GETMEM, str, and StringValue().
Referenced by rb_str_to_inum().
Definition at line 4268 of file bignum.c.
References rb_str_convert_to_inum(), str, and TRUE.
Referenced by rb_str2inum().
Definition at line 3158 of file bignum.c.
References BDIGIT, bdigit_roomof, BDIGITS, BIGDN, BIGLO, bignew, BIGNUM_SET_LEN, i, n, and SIZEOF_VALUE.
Referenced by rb_int2big(), and rb_uint2inum().
Definition at line 3201 of file bignum.c.
References LONG2FIX, n, POSFIXABLE, and rb_uint2big().
STATIC_ASSERT | ( | bdigit_dbl_signed_signedness | , |
0 | , | ||
(BDIGIT_DBL_SIGNED) - | 1 | ||
) |
STATIC_ASSERT | ( | bdigit_dbl_signedness | ) |
STATIC_ASSERT | ( | bdigit_signedness | ) |
STATIC_ASSERT | ( | rbignum_embed_len_max | , |
BIGNUM_EMBED_LEN_MAX<= | BIGNUM_EMBED_LEN_MASK > > BIGNUM_EMBED_LEN_SHIFT | ||
) |
STATIC_ASSERT | ( | sizeof_bdigit | , |
SIZEOF_BDIGIT<= | sizeofBDIGIT | ||
) |
STATIC_ASSERT | ( | sizeof_bdigit_and_dbl | , |
SIZEOF_BDIGIT *2<= | SIZEOF_BDIGIT_DBL | ||
) |
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_long_and_sizeof_bdigit | , |
SIZEOF_BDIGIT % | SIZEOF_LONG = =0 |
||
) |
Definition at line 38 of file bignum.c.
Referenced by rb_fix2str().