Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
Macros | Functions
bignum.h File Reference

Public APIs related to so-called rb_cBignum. More...

#include "ruby/internal/config.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/backward/2/long_long.h"

Go to the source code of this file.

Macros

#define rb_big2int(x)   rb_big2long(x)
 
#define rb_big2uint(x)   rb_big2ulong(x)
 
#define INTEGER_PACK_MSWORD_FIRST   0x01
 
#define INTEGER_PACK_LSWORD_FIRST   0x02
 
#define INTEGER_PACK_MSBYTE_FIRST   0x10
 
#define INTEGER_PACK_LSBYTE_FIRST   0x20
 
#define INTEGER_PACK_NATIVE_BYTE_ORDER   0x40
 
#define INTEGER_PACK_2COMP   0x80
 
#define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION   0x400
 
#define INTEGER_PACK_FORCE_BIGNUM   0x100
 
#define INTEGER_PACK_NEGATIVE   0x200
 
#define INTEGER_PACK_LITTLE_ENDIAN
 
#define INTEGER_PACK_BIG_ENDIAN
 

Functions

VALUE rb_big_new (size_t, int)
 
int rb_bigzero_p (VALUE x)
 
VALUE rb_big_clone (VALUE)
 
void rb_big_2comp (VALUE)
 
VALUE rb_big_norm (VALUE)
 
void rb_big_resize (VALUE big, size_t len)
 
VALUE rb_cstr_to_inum (const char *, int, int)
 
VALUE rb_str_to_inum (VALUE, int, int)
 
VALUE rb_cstr2inum (const char *, int)
 
VALUE rb_str2inum (VALUE, int)
 
VALUE rb_big2str (VALUE, int)
 
long rb_big2long (VALUE)
 
unsigned long rb_big2ulong (VALUE)
 
void rb_big_pack (VALUE val, unsigned long *buf, long num_longs)
 
VALUE rb_big_unpack (unsigned long *buf, long num_longs)
 
int rb_uv_to_utf8 (char[6], unsigned long)
 
VALUE rb_dbl2big (double)
 
double rb_big2dbl (VALUE)
 
VALUE rb_big_cmp (VALUE, VALUE)
 
VALUE rb_big_eq (VALUE, VALUE)
 
VALUE rb_big_eql (VALUE, VALUE)
 
VALUE rb_big_plus (VALUE, VALUE)
 
VALUE rb_big_minus (VALUE, VALUE)
 
VALUE rb_big_mul (VALUE, VALUE)
 
VALUE rb_big_div (VALUE, VALUE)
 
VALUE rb_big_idiv (VALUE, VALUE)
 
VALUE rb_big_modulo (VALUE, VALUE)
 
VALUE rb_big_divmod (VALUE, VALUE)
 
VALUE rb_big_pow (VALUE, VALUE)
 
VALUE rb_big_and (VALUE, VALUE)
 
VALUE rb_big_or (VALUE, VALUE)
 
VALUE rb_big_xor (VALUE, VALUE)
 
VALUE rb_big_lshift (VALUE, VALUE)
 
VALUE rb_big_rshift (VALUE, VALUE)
 
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)
 
size_t rb_absint_size (VALUE val, int *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)
 

Detailed Description

Public APIs related to so-called rb_cBignum.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file bignum.h.

Macro Definition Documentation

◆ INTEGER_PACK_2COMP

#define INTEGER_PACK_2COMP   0x80

Definition at line 85 of file bignum.h.

◆ INTEGER_PACK_BIG_ENDIAN

#define INTEGER_PACK_BIG_ENDIAN
Value:
#define INTEGER_PACK_MSBYTE_FIRST
Definition: bignum.h:82
#define INTEGER_PACK_MSWORD_FIRST
Definition: bignum.h:80

Definition at line 94 of file bignum.h.

◆ INTEGER_PACK_FORCE_BIGNUM

#define INTEGER_PACK_FORCE_BIGNUM   0x100

Definition at line 88 of file bignum.h.

◆ INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION

#define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION   0x400

Definition at line 86 of file bignum.h.

◆ INTEGER_PACK_LITTLE_ENDIAN

#define INTEGER_PACK_LITTLE_ENDIAN
Value:
#define INTEGER_PACK_LSBYTE_FIRST
Definition: bignum.h:83
#define INTEGER_PACK_LSWORD_FIRST
Definition: bignum.h:81

Definition at line 91 of file bignum.h.

◆ INTEGER_PACK_LSBYTE_FIRST

#define INTEGER_PACK_LSBYTE_FIRST   0x20

Definition at line 83 of file bignum.h.

◆ INTEGER_PACK_LSWORD_FIRST

#define INTEGER_PACK_LSWORD_FIRST   0x02

Definition at line 81 of file bignum.h.

◆ INTEGER_PACK_MSBYTE_FIRST

#define INTEGER_PACK_MSBYTE_FIRST   0x10

Definition at line 82 of file bignum.h.

◆ INTEGER_PACK_MSWORD_FIRST

#define INTEGER_PACK_MSWORD_FIRST   0x01

Definition at line 80 of file bignum.h.

◆ INTEGER_PACK_NATIVE_BYTE_ORDER

#define INTEGER_PACK_NATIVE_BYTE_ORDER   0x40

Definition at line 84 of file bignum.h.

◆ INTEGER_PACK_NEGATIVE

#define INTEGER_PACK_NEGATIVE   0x200

Definition at line 89 of file bignum.h.

◆ rb_big2int

#define rb_big2int (   x)    rb_big2long(x)

Definition at line 48 of file bignum.h.

◆ rb_big2uint

#define rb_big2uint (   x)    rb_big2ulong(x)

Definition at line 50 of file bignum.h.

Function Documentation

◆ rb_absint_numwords()

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

Definition at line 3388 of file bignum.c.

References assert, CHAR_BIT, rb_absint_size(), and SIZE_MAX.

Referenced by rb_big_pow(), and rb_str_format().

◆ rb_absint_singlebit_p()

int rb_absint_singlebit_p ( VALUE  val)

Definition at line 3452 of file bignum.c.

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

Referenced by rb_big_bit_length(), and rb_str_format().

◆ rb_absint_size()

size_t rb_absint_size ( VALUE  val,
int nlz_bits_ret 
)

◆ rb_big2dbl()

double rb_big2dbl ( VALUE  x)

◆ rb_big2long()

long rb_big2long ( VALUE  x)

Definition at line 5139 of file bignum.c.

References long(), LONG_MAX, LONG_MIN, num, rb_eRangeError, and rb_raise().

Referenced by rb_num2long().

◆ rb_big2str()

VALUE rb_big2str ( VALUE  x,
int  base 
)

Definition at line 5090 of file bignum.c.

References big2str_struct::base.

Referenced by rb_int2str(), and rb_str_format().

◆ rb_big2ulong()

unsigned long rb_big2ulong ( VALUE  x)

Definition at line 5124 of file bignum.c.

References long(), LONG_MIN, num, rb_eRangeError, and rb_raise().

Referenced by rb_num_to_uint().

◆ rb_big_2comp()

void rb_big_2comp ( VALUE  x)

Definition at line 3055 of file bignum.c.

◆ rb_big_and()

VALUE rb_big_and ( VALUE  x,
VALUE  y 
)

Definition at line 6357 of file bignum.c.

References BDIGIT, BDIGITS, bignew, FIX2LONG, FIXNUM_P, RB_GC_GUARD, RB_INTEGER_TYPE_P, and rb_num_coerce_bit().

Referenced by rb_int_and().

◆ rb_big_clone()

VALUE rb_big_clone ( VALUE  x)

Definition at line 3026 of file bignum.c.

References BDIGIT, BDIGITS, CLASS_OF, len, and MEMCPY.

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

◆ rb_big_cmp()

VALUE rb_big_cmp ( VALUE  x,
VALUE  y 
)

◆ rb_big_div()

VALUE rb_big_div ( VALUE  x,
VALUE  y 
)

Definition at line 6088 of file bignum.c.

Referenced by rb_int_div().

◆ rb_big_divmod()

VALUE rb_big_divmod ( VALUE  x,
VALUE  y 
)

Definition at line 6132 of file bignum.c.

References div, FIX2LONG, FIXNUM_P, mod, rb_assoc_new(), RB_BIGNUM_TYPE_P, rb_int2big(), and rb_num_coerce_bin().

Referenced by rb_int_divmod().

◆ rb_big_eq()

VALUE rb_big_eq ( VALUE  x,
VALUE  y 
)

◆ rb_big_eql()

VALUE rb_big_eql ( VALUE  x,
VALUE  y 
)

Definition at line 5541 of file bignum.c.

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

◆ rb_big_idiv()

VALUE rb_big_idiv ( VALUE  x,
VALUE  y 
)

Definition at line 6094 of file bignum.c.

Referenced by rb_int_idiv().

◆ rb_big_lshift()

VALUE rb_big_lshift ( VALUE  x,
VALUE  y 
)

Definition at line 6618 of file bignum.c.

References bit_length, BITSPERDIG, FIX2LONG, FIXNUM_P, int(), long(), RB_BIGNUM_TYPE_P, and rb_to_int().

Referenced by rb_int_lshift().

◆ rb_big_minus()

VALUE rb_big_minus ( VALUE  x,
VALUE  y 
)

Definition at line 5850 of file bignum.c.

References DBL2NUM, FIX2LONG, FIXNUM_P, rb_big2dbl(), RB_BIGNUM_TYPE_P, rb_num_coerce_bin(), and RFLOAT_VALUE.

Referenced by rb_int_minus().

◆ rb_big_modulo()

VALUE rb_big_modulo ( VALUE  x,
VALUE  y 
)

Definition at line 6100 of file bignum.c.

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

Referenced by rb_int_modulo().

◆ rb_big_mul()

VALUE rb_big_mul ( VALUE  x,
VALUE  y 
)

◆ rb_big_new()

VALUE rb_big_new ( size_t  len,
int  sign 
)

Definition at line 3020 of file bignum.c.

References bignew, and len.

◆ rb_big_norm()

VALUE rb_big_norm ( VALUE  x)

Definition at line 3158 of file bignum.c.

Referenced by rb_fix_aref().

◆ rb_big_or()

VALUE rb_big_or ( VALUE  x,
VALUE  y 
)

◆ rb_big_pack()

void rb_big_pack ( VALUE  val,
unsigned long buf,
long  num_longs 
)

◆ rb_big_plus()

VALUE rb_big_plus ( VALUE  x,
VALUE  y 
)

Definition at line 5821 of file bignum.c.

References DBL2NUM, FIX2LONG, FIXNUM_P, rb_big2dbl(), RB_BIGNUM_TYPE_P, rb_num_coerce_bin(), and RFLOAT_VALUE.

Referenced by rb_int_plus(), and rb_int_succ().

◆ rb_big_pow()

VALUE rb_big_pow ( VALUE  x,
VALUE  y 
)

◆ rb_big_resize()

void rb_big_resize ( VALUE  big,
size_t  len 
)

Definition at line 2994 of file bignum.c.

References BIGNUM_SET_LEN, and len.

◆ rb_big_rshift()

VALUE rb_big_rshift ( VALUE  x,
VALUE  y 
)

Definition at line 6648 of file bignum.c.

References bit_length, BITSPERDIG, FIX2LONG, FIXNUM_P, int(), long(), RB_BIGNUM_TYPE_P, and rb_to_int().

◆ rb_big_unpack()

VALUE rb_big_unpack ( unsigned long buf,
long  num_longs 
)

◆ rb_big_xor()

VALUE rb_big_xor ( VALUE  x,
VALUE  y 
)

◆ rb_bigzero_p()

int rb_bigzero_p ( VALUE  x)

Definition at line 2924 of file bignum.c.

References BIGZEROP.

Referenced by rb_int_powm().

◆ rb_cstr2inum()

VALUE rb_cstr2inum ( const char *  str,
int  base 
)

Definition at line 4544 of file bignum.c.

References rb_cstr_to_inum(), and str.

◆ rb_cstr_to_inum()

VALUE rb_cstr_to_inum ( const char *  str,
int  base,
int  badcheck 
)

Definition at line 4016 of file bignum.c.

References INT2FIX, NIL_P, NULL, rb_invalid_str(), and str.

Referenced by rb_cstr2inum().

◆ rb_dbl2big()

VALUE rb_dbl2big ( double  d)

◆ rb_integer_pack()

int rb_integer_pack ( VALUE  val,
void *  words,
size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags 
)

Definition at line 3553 of file bignum.c.

References BDIGIT, bdigit_roomof, BDIGITS, BIGDN, BIGLO, FIX2LONG, FIXNUM_P, numberof, RB_GC_GUARD, and rb_to_int().

Referenced by rb_big_pack(), rb_hash(), and rb_str_format().

◆ rb_integer_unpack()

VALUE rb_integer_unpack ( const void *  words,
size_t  numwords,
size_t  wordsize,
size_t  nails,
int  flags 
)

◆ rb_str2inum()

VALUE rb_str2inum ( VALUE  str,
int  base 
)

Definition at line 4550 of file bignum.c.

References rb_str_to_inum(), and str.

◆ rb_str_to_inum()

VALUE rb_str_to_inum ( VALUE  str,
int  base,
int  badcheck 
)

Definition at line 4274 of file bignum.c.

References rb_str_convert_to_inum(), str, and TRUE.

Referenced by rb_str2inum(), rb_str_format(), rb_str_upto_each(), and rb_str_upto_endless_each().

◆ rb_uv_to_utf8()

int rb_uv_to_utf8 ( char  buf[6],
unsigned long  uv 
)

Definition at line 1660 of file pack.c.

References castchar, Qnil, rb_eRangeError, rb_raise(), and UNREACHABLE_RETURN.