Ruby: internal/bignum.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Enumerations | Functions | Variables
bignum.h File Reference

Internal header for Bignums. More...

`#include "ruby/internal/config.h"`
`#include <stddef.h>`
`#include "ruby/internal/stdbool.h"`
`#include "ruby/ruby.h"`

Go to the source code of this file.

## Data Structures
struct | RBignum

## Macros
#define | BDIGIT unsigned int
#define | SIZEOF_BDIGIT SIZEOF_INT
#define | BDIGIT_DBL unsigned LONG_LONG
#define | BDIGIT_DBL_SIGNED LONG_LONG
#define | PRI_BDIGIT_PREFIX ""
#define | PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX
#define | SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT
#define | PRIdBDIGIT PRI_BDIGIT_PREFIX"d"
#define | PRIiBDIGIT PRI_BDIGIT_PREFIX"i"
#define | PRIoBDIGIT PRI_BDIGIT_PREFIX"o"
#define | PRIuBDIGIT PRI_BDIGIT_PREFIX"u"
#define | PRIxBDIGIT PRI_BDIGIT_PREFIX"x"
#define | PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d"
#define | PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i"
#define | PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o"
#define | PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u"
#define | PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x"
#define | RBIGNUM(obj) ((struct RBignum *)(obj))
#define | BIGNUM_SIGN_BIT FL_USER1
#define | BIGNUM_EMBED_FLAG ((VALUE)FL_USER2)
#define | BIGNUM_EMBED_LEN_NUMBITS 3
#define | BIGNUM_EMBED_LEN_MASK (~(~(VALUE)0U << BIGNUM_EMBED_LEN_NUMBITS) << BIGNUM_EMBED_LEN_SHIFT)
#define | BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+3) /* bit offset of BIGNUM_EMBED_LEN_MASK */
#define | BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)

## Enumerations
enum | rb_int_parse_flags { RB_INT_PARSE_SIGN = 0x01 , RB_INT_PARSE_UNDERSCORE = 0x02 , RB_INT_PARSE_PREFIX = 0x04 , RB_INT_PARSE_ALL = 0x07 , RB_INT_PARSE_DEFAULT = 0x07 }

## Functions
double | rb_big_fdiv_double (VALUE x, VALUE y)
VALUE | rb_big_uminus (VALUE x)
VALUE | rb_big_hash (VALUE)
VALUE | rb_big_odd_p (VALUE)
VALUE | rb_big_even_p (VALUE)
size_t | rb_big_size (VALUE)
VALUE | rb_integer_float_cmp (VALUE x, VALUE y)
VALUE | rb_integer_float_eq (VALUE x, VALUE y)
VALUE | rb_str_convert_to_inum (VALUE str, int base, int badcheck, int raise_exception)
VALUE | rb_big_comp (VALUE x)
VALUE | rb_big_aref (VALUE x, VALUE y)
VALUE | rb_big_abs (VALUE x)
VALUE | rb_big_size_m (VALUE big)
VALUE | rb_big_bit_length (VALUE big)
VALUE | rb_big_remainder (VALUE x, VALUE y)
VALUE | rb_big_gt (VALUE x, VALUE y)
VALUE | rb_big_ge (VALUE x, VALUE y)
VALUE | rb_big_lt (VALUE x, VALUE y)
VALUE | rb_big_le (VALUE x, VALUE y)
VALUE | rb_int_powm (int const argc, VALUE *const argv, VALUE const num)
VALUE | rb_big_mul_normal (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_toom3 (VALUE x, VALUE y)
VALUE | rb_big_sq_fast (VALUE x)
VALUE | rb_big_divrem_normal (VALUE x, VALUE y)
VALUE | rb_big2str_poweroftwo (VALUE x, int base)
VALUE | rb_big2str_generic (VALUE x, int base)
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_int_parse_cstr (const char *str, ssize_t len, char **endp, size_t *ndigits, int base, int flags)

## Variables
const char | ruby_digitmap []

## Detailed Description

Internal header for Bignums.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Definition in file bignum.h.

## Macro Definition Documentation

## ◆ BDIGIT

#define BDIGIT unsigned int

Definition at line 24 of file bignum.h.

## ◆ BDIGIT_DBL

#define BDIGIT_DBL unsigned LONG_LONG

Definition at line 26 of file bignum.h.

## ◆ BDIGIT_DBL_SIGNED

#define BDIGIT_DBL_SIGNED LONG_LONG

Definition at line 27 of file bignum.h.

## ◆ BIGNUM_EMBED_FLAG

#define BIGNUM_EMBED_FLAG ((VALUE)FL_USER2)

Definition at line 79 of file bignum.h.

## ◆ BIGNUM_EMBED_LEN_MASK

#define BIGNUM_EMBED_LEN_MASK (~(~(VALUE)0U << BIGNUM_EMBED_LEN_NUMBITS) << BIGNUM_EMBED_LEN_SHIFT)

Definition at line 81 of file bignum.h.

## ◆ BIGNUM_EMBED_LEN_MAX

#define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)

Definition at line 89 of file bignum.h.

## ◆ BIGNUM_EMBED_LEN_NUMBITS

#define BIGNUM_EMBED_LEN_NUMBITS 3

Definition at line 80 of file bignum.h.

## ◆ BIGNUM_EMBED_LEN_SHIFT

#define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+3) /* bit offset of BIGNUM_EMBED_LEN_MASK */

Definition at line 83 of file bignum.h.

## ◆ BIGNUM_SIGN_BIT

#define BIGNUM_SIGN_BIT FL_USER1

Definition at line 78 of file bignum.h.

## ◆ PRI_BDIGIT_DBL_PREFIX

#define PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX

Definition at line 29 of file bignum.h.

## ◆ PRI_BDIGIT_PREFIX

#define PRI_BDIGIT_PREFIX ""

Definition at line 28 of file bignum.h.

## ◆ PRIdBDIGIT

#define PRIdBDIGIT PRI_BDIGIT_PREFIX"d"

Definition at line 60 of file bignum.h.

## ◆ PRIdBDIGIT_DBL

#define PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d"

Definition at line 69 of file bignum.h.

## ◆ PRIiBDIGIT

#define PRIiBDIGIT PRI_BDIGIT_PREFIX"i"

Definition at line 61 of file bignum.h.

## ◆ PRIiBDIGIT_DBL

#define PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i"

Definition at line 70 of file bignum.h.

## ◆ PRIoBDIGIT

#define PRIoBDIGIT PRI_BDIGIT_PREFIX"o"

Definition at line 62 of file bignum.h.

## ◆ PRIoBDIGIT_DBL

#define PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o"

Definition at line 71 of file bignum.h.

## ◆ PRIuBDIGIT

#define PRIuBDIGIT PRI_BDIGIT_PREFIX"u"

Definition at line 63 of file bignum.h.

## ◆ PRIuBDIGIT_DBL

#define PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u"

Definition at line 72 of file bignum.h.

## ◆ PRIxBDIGIT

#define PRIxBDIGIT PRI_BDIGIT_PREFIX"x"

Definition at line 64 of file bignum.h.

## ◆ PRIXBDIGIT

#define PRIXBDIGIT PRI_BDIGIT_PREFIX"X"

Definition at line 65 of file bignum.h.

## ◆ PRIxBDIGIT_DBL

#define PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x"

Definition at line 73 of file bignum.h.

## ◆ PRIXBDIGIT_DBL

#define PRIXBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"X"

Definition at line 74 of file bignum.h.

## ◆ RBIGNUM

#define RBIGNUM | ( |  | obj | ) | ((struct RBignum *)(obj))

Definition at line 77 of file bignum.h.

## ◆ SIZEOF_ACTUAL_BDIGIT

#define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT

Definition at line 56 of file bignum.h.

## ◆ SIZEOF_BDIGIT

#define SIZEOF_BDIGIT SIZEOF_INT

Definition at line 25 of file bignum.h.

## Enumeration Type Documentation

## ◆ rb_int_parse_flags

enum rb_int_parse_flags

Enumerator
RB_INT_PARSE_SIGN |
RB_INT_PARSE_UNDERSCORE |
RB_INT_PARSE_PREFIX |
RB_INT_PARSE_ALL |
RB_INT_PARSE_DEFAULT |

Definition at line 93 of file bignum.h.

## Function Documentation

## ◆ rb_big2str_generic()

VALUE rb_big2str_generic | ( | VALUE | x,
|  | int | base
| ) |  |

Definition at line 5004 of file bignum.c.

References big2str_struct::base.

## ◆ rb_big2str_poweroftwo()

VALUE rb_big2str_poweroftwo | ( | VALUE | x,
|  | int | base
| ) |  |

Definition at line 4921 of file bignum.c.

## ◆ rb_big_abs()

VALUE rb_big_abs | ( | VALUE | x | ) |

Definition at line 6759 of file bignum.c.

References BIGNUM_SET_POSITIVE_SIGN, and rb_big_clone().

Referenced by rb_int_abs().

## ◆ rb_big_aref()

VALUE rb_big_aref | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 6678 of file bignum.c.

References BDIGIT, BDIGITS, BIGSIZE, BITSPERDIG, INT2FIX, NUM2LONG, and RB_BIGNUM_TYPE_P.

## ◆ rb_big_bit_length()

VALUE rb_big_bit_length | ( | VALUE | big | ) |

Definition at line 6787 of file bignum.c.

References BARY_ARGS, BARY_SHORT_MUL, BARY_SUB, BDIGIT, bdigit_roomof, CHAR_BIT, INTEGER_PACK_LSWORD_FIRST, INTEGER_PACK_NATIVE_BYTE_ORDER, LONG2FIX, numberof, rb_absint_singlebit_p(), rb_absint_size(), rb_integer_unpack(), SIZE_MAX, and SIZET2NUM.

Referenced by rb_int_bit_length().

## ◆ rb_big_comp()

VALUE rb_big_comp | ( | VALUE | x | ) |

Definition at line 5561 of file bignum.c.

References BDIGIT, BDIGITS, BIGNUM_SET_NEGATIVE_SIGN, BIGNUM_SET_POSITIVE_SIGN, INT2FIX, and rb_big_clone().

Referenced by rb_int_comp().

## ◆ rb_big_divrem_normal()

VALUE rb_big_divrem_normal | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 2741 of file bignum.c.

References BARY_TRUNC, BDIGIT, BDIGITS, BIGDIVREM_EXTRA_WORDS, bignew, LONG2FIX, rb_assoc_new(), RB_GC_GUARD, rb_num_zerodiv(), big_div_struct::yds, and big_div_struct::yn.

## ◆ rb_big_even_p()

VALUE rb_big_even_p | ( | VALUE | num | ) |

Definition at line 6837 of file bignum.c.

References BDIGITS, num, Qfalse, and Qtrue.

## ◆ rb_big_fdiv_double()

double rb_big_fdiv_double | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 6206 of file bignum.c.

References DBL2NUM, FIX2LONG, FIXNUM_P, isinf(), isnan, NUM2DBL, RB_BIGNUM_TYPE_P, rb_flo_div_flo(), rb_int2big(), rb_num_coerce_bin(), and RFLOAT_VALUE.

Referenced by rb_big_fdiv(), and rb_int_fdiv_double().

## ◆ rb_big_ge()

VALUE rb_big_ge | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 5492 of file bignum.c.

References big_op_ge.

Referenced by rb_int_ge().

## ◆ rb_big_gt()

VALUE rb_big_gt | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 5486 of file bignum.c.

References big_op_gt.

Referenced by rb_int_gt().

## ◆ rb_big_hash()

VALUE rb_big_hash | ( | VALUE | x | ) |

Definition at line 6723 of file bignum.c.

References BDIGIT, BDIGITS, rb_memhash(), and ST2FIX.

## ◆ rb_big_le()

VALUE rb_big_le | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 5504 of file bignum.c.

References big_op_le.

## ◆ rb_big_lt()

VALUE rb_big_lt | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 5498 of file bignum.c.

References big_op_lt.

## ◆ rb_big_mul_balance()

VALUE rb_big_mul_balance | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1699 of file bignum.c.

References BDIGITS, bignew, NULL, and RB_GC_GUARD.

## ◆ rb_big_mul_karatsuba()

VALUE rb_big_mul_karatsuba | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1880 of file bignum.c.

References BDIGITS, bignew, KARATSUBA_BALANCED, NULL, rb_eArgError, RB_GC_GUARD, and rb_raise().

## ◆ rb_big_mul_normal()

VALUE rb_big_mul_normal | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1571 of file bignum.c.

References BDIGITS, bignew, and RB_GC_GUARD.

## ◆ rb_big_mul_toom3()

VALUE rb_big_mul_toom3 | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 2277 of file bignum.c.

References BDIGITS, bignew, NULL, rb_eArgError, RB_GC_GUARD, rb_raise(), and TOOM3_BALANCED.

## ◆ rb_big_odd_p()

VALUE rb_big_odd_p | ( | VALUE | num | ) |

Definition at line 6828 of file bignum.c.

References BDIGITS, num, Qfalse, and Qtrue.

Referenced by rb_int_odd_p().

## ◆ rb_big_remainder()

VALUE rb_big_remainder | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 6116 of file bignum.c.

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

## ◆ rb_big_size()

size_t rb_big_size | ( | VALUE | big | ) |

Definition at line 6775 of file bignum.c.

References BIGSIZE.

Referenced by rb_big_size_m().

## ◆ rb_big_size_m()

VALUE rb_big_size_m | ( | VALUE | big | ) |

Definition at line 6781 of file bignum.c.

References rb_big_size(), and SIZET2NUM.

## ◆ rb_big_sq_fast()

VALUE rb_big_sq_fast | ( | VALUE | x | ) |

Definition at line 1640 of file bignum.c.

References BDIGITS, bignew, and RB_GC_GUARD.

## ◆ rb_big_uminus()

VALUE rb_big_uminus | ( | VALUE | x | ) |

Definition at line 5551 of file bignum.c.

References rb_big_clone().

Referenced by rb_int_uminus(), and rb_str_format().

## ◆ rb_int_parse_cstr()

VALUE rb_int_parse_cstr | ( | const char * | str,
|  | ssize_t | len,
|  | char ** | endp,
|  | size_t * | ndigits,
|  | int | base,
|  | int | flags
| ) |  |

Definition at line 4045 of file bignum.c.

References ADV, ASSERT_LEN, bit_length, conv_digit, GMP_STR2BIG_DIGITS, INT2FIX, ISSPACE, KARATSUBA_MUL_DIGITS, len, long(), LONG2FIX, NULL, POSFIXABLE, POW2_P, Qnil, RB_INT_PARSE_PREFIX, RB_INT_PARSE_SIGN, RB_INT_PARSE_UNDERSCORE, rb_uint2big(), roomof, ruby_scan_digits(), and str.

## ◆ rb_int_powm()

VALUE rb_int_powm | ( | int const | argc,
|  | VALUE *const | argv,
|  | VALUE const | num
| ) |  |

Definition at line 7108 of file bignum.c.

References argc, argv, FIX2LONG, FIXNUM_P, HALF_LONG_MSB, INT2FIX, long(), num, Qnil, rb_bigzero_p(), rb_check_arity, rb_eRangeError, rb_eTypeError, rb_int_modulo(), rb_int_negative_p(), rb_int_pow(), rb_int_uminus(), RB_INTEGER_TYPE_P, rb_num_zerodiv(), rb_raise(), and UNREACHABLE_RETURN.

Referenced by Init_Numeric().

## ◆ rb_integer_float_cmp()

VALUE rb_integer_float_cmp | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 5324 of file bignum.c.

References FIX2LONG, FIXNUM_MAX, FIXNUM_MIN, FIXNUM_P, INT2FIX, isinf(), isnan, long(), Qnil, rb_big_cmp(), rb_dbl2big(), and RFLOAT_VALUE.

Referenced by rb_big_cmp(), and rb_float_gt().

## ◆ rb_integer_float_eq()

VALUE rb_integer_float_eq | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 5383 of file bignum.c.

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

Referenced by rb_big_eq(), and rb_float_equal().

## ◆ rb_str2big_karatsuba()

VALUE rb_str2big_karatsuba | ( | VALUE | arg,
|  | int | base,
|  | int | badcheck
| ) |  |

Definition at line 4358 of file bignum.c.

References len, RB_GC_GUARD, rb_must_asciicompat(), roomof, RSTRING_LEN, str, and StringValuePtr.

## ◆ rb_str2big_normal()

VALUE rb_str2big_normal | ( | VALUE | arg,
|  | int | base,
|  | int | badcheck
| ) |  |

Definition at line 4316 of file bignum.c.

References len, RB_GC_GUARD, rb_must_asciicompat(), roomof, RSTRING_LEN, str, and StringValuePtr.

## ◆ rb_str2big_poweroftwo()

VALUE rb_str2big_poweroftwo | ( | VALUE | arg,
|  | int | base,
|  | int | badcheck
| ) |  |

Definition at line 4280 of file bignum.c.

References bit_length, len, POW2_P, RB_GC_GUARD, rb_must_asciicompat(), RSTRING_LEN, str, and StringValueCStr.

## ◆ rb_str_convert_to_inum()

VALUE rb_str_convert_to_inum | ( | VALUE | str,
|  | int | base,
|  | int | badcheck,
|  | int | raise_exception
| ) |  |

Definition at line 4252 of file bignum.c.

References INT2FIX, len, NIL_P, NULL, Qnil, rb_must_asciicompat(), RSTRING_GETMEM, str, and StringValue.

Referenced by rb_str_to_inum().

## Variable Documentation

## ◆ ruby_digitmap

const char ruby_digitmap[]
| extern

Definition at line 48 of file bignum.c.

Referenced by rb_fix2str(), and rb_str_format().