Ruby  3.4.0dev (2024-11-22 revision 0989400a925cd201defdca9eb28eb87200b30785)
bignum.h
Go to the documentation of this file.
1 #ifndef RBIMPL_INTERN_BIGNUM_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_INTERN_BIGNUM_H
23 #include "ruby/internal/config.h"
24 
25 #ifdef STDC_HEADERS
26 # include <stddef.h>
27 #endif
28 
31 #include "ruby/internal/value.h"
33 
35 
36 /* bignum.c */
37 
38 
51 VALUE rb_big_new(size_t len, int sign);
52 
64 int rb_bigzero_p(VALUE x);
65 
73 
81 void rb_big_2comp(VALUE num);
82 
91 
98 void rb_big_resize(VALUE big, size_t len);
99 
125 VALUE rb_cstr_to_inum(const char *str, int base, int badcheck);
126 
149 VALUE rb_str_to_inum(VALUE str, int base, int badcheck);
150 
171 VALUE rb_cstr2inum(const char *str, int base);
172 
196 VALUE rb_str2inum(VALUE str, int base);
197 
207 VALUE rb_big2str(VALUE x, int base);
208 
216 long rb_big2long(VALUE x);
217 
219 #define rb_big2int(x) rb_big2long(x)
220 
235 unsigned long rb_big2ulong(VALUE x);
236 
238 #define rb_big2uint(x) rb_big2ulong(x)
239 
240 #if HAVE_LONG_LONG
248 LONG_LONG rb_big2ll(VALUE);
249 
264 unsigned LONG_LONG rb_big2ull(VALUE);
265 
266 #endif /* HAVE_LONG_LONG */
267 
281 void rb_big_pack(VALUE val, unsigned long *buf, long num_longs);
282 
296 VALUE rb_big_unpack(unsigned long *buf, long num_longs);
297 
298 /* pack.c */
299 
310 int rb_uv_to_utf8(char buf[6], unsigned long uv);
311 
312 /* bignum.c */
313 
326 VALUE rb_dbl2big(double d);
327 
339 double rb_big2dbl(VALUE x);
340 
351 VALUE rb_big_cmp(VALUE lhs, VALUE rhs);
352 
362 VALUE rb_big_eq(VALUE lhs, VALUE rhs);
363 
374 VALUE rb_big_eql(VALUE lhs, VALUE rhs);
375 
385 
395 
405 
415 
425 
440 
451 
464 
474 
483 VALUE rb_big_or(VALUE x, VALUE y);
484 
494 
506 
518 
525 #define INTEGER_PACK_MSWORD_FIRST 0x01
526 
528 #define INTEGER_PACK_LSWORD_FIRST 0x02
529 
534 #define INTEGER_PACK_MSBYTE_FIRST 0x10
535 
540 #define INTEGER_PACK_LSBYTE_FIRST 0x20
541 
546 #define INTEGER_PACK_NATIVE_BYTE_ORDER 0x40
547 
549 #define INTEGER_PACK_2COMP 0x80
550 
552 #define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION 0x400
553 
558 #define INTEGER_PACK_FORCE_BIGNUM 0x100
559 
564 #define INTEGER_PACK_NEGATIVE 0x200
565 
567 #define INTEGER_PACK_LITTLE_ENDIAN \
568  (INTEGER_PACK_LSWORD_FIRST | \
569  INTEGER_PACK_LSBYTE_FIRST)
570 
572 #define INTEGER_PACK_BIG_ENDIAN \
573  (INTEGER_PACK_MSWORD_FIRST | \
574  INTEGER_PACK_MSBYTE_FIRST)
575 
679 int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
680 
761 VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
762 
781 size_t rb_absint_size(VALUE val, int *nlz_bits_ret);
782 
804 size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret);
805 
843 
845 
846 #endif /* RBIMPL_INTERN_BIGNUM_H */
Defines old LONG_LONG.
#define LONG_LONG
Definition: long_long.h:38
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
Exports an integer into a buffer.
Definition: bignum.c:3588
VALUE rb_big_lshift(VALUE x, VALUE y)
Performs shift left.
Definition: bignum.c:6656
VALUE rb_big_and(VALUE x, VALUE y)
Performs bitwise and of the passed two objects.
Definition: bignum.c:6395
VALUE rb_big_or(VALUE x, VALUE y)
Performs bitwise or of the passed two objects.
Definition: bignum.c:6514
VALUE rb_big_minus(VALUE x, VALUE y)
Performs subtraction of the passed two objects.
Definition: bignum.c:5881
VALUE rb_big_modulo(VALUE x, VALUE y)
Performs modulo of the passed two objects.
Definition: bignum.c:6135
VALUE rb_big_new(size_t len, int sign)
Allocates a bignum object.
Definition: bignum.c:3056
VALUE rb_big_pow(VALUE x, VALUE y)
Raises x to the powerof y.
Definition: bignum.c:6276
int rb_bigzero_p(VALUE x)
Queries if the passed bignum instance is a "bigzero".
Definition: bignum.c:2959
VALUE rb_big_plus(VALUE x, VALUE y)
Performs addition of the passed two objects.
Definition: bignum.c:5852
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
Identical to rb_cstr2inum(), except it takes Ruby's strings instead of C's.
Definition: bignum.c:4308
VALUE rb_big_clone(VALUE num)
Duplicates the given bignum.
Definition: bignum.c:3062
size_t rb_absint_size(VALUE val, int *nlz_bits_ret)
Calculates the number of bytes needed to represent the absolute value of the passed integer.
Definition: bignum.c:3289
size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
Calculates the number of words needed represent the absolute value of the passed integer.
Definition: bignum.c:3424
int rb_absint_singlebit_p(VALUE val)
Tests abs(val) consists only of a bit or not.
Definition: bignum.c:3487
VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
Import an integer from a buffer.
Definition: bignum.c:3674
unsigned long rb_big2ulong(VALUE x)
Converts a bignum into C's unsigned long.
Definition: bignum.c:5161
VALUE rb_big_idiv(VALUE x, VALUE y)
Performs "integer division".
Definition: bignum.c:6129
void rb_big_2comp(VALUE num)
Destructively modify the passed bignum into 2's complement representation.
Definition: bignum.c:3091
VALUE rb_big2str(VALUE x, int base)
Generates a place-value representation of the passed integer.
Definition: bignum.c:5127
VALUE rb_big_cmp(VALUE lhs, VALUE rhs)
Compares the passed two bignums.
Definition: bignum.c:5449
VALUE rb_str2inum(VALUE str, int base)
Identical to rb_str_to_inum(), except the second argument controls the base and badcheck at once.
Definition: bignum.c:4584
VALUE rb_dbl2big(double d)
Converts a C's double into a bignum.
Definition: bignum.c:5285
VALUE rb_big_mul(VALUE x, VALUE y)
Performs multiplication of the passed two objects.
Definition: bignum.c:5965
VALUE rb_big_eql(VALUE lhs, VALUE rhs)
Equality, in terms of eql?.
Definition: bignum.c:5573
VALUE rb_cstr2inum(const char *str, int base)
Identical to rb_cstr_to_inum(), except the second argument controls the base and badcheck at once.
Definition: bignum.c:4578
int rb_uv_to_utf8(char buf[6], unsigned long uv)
Encodes a Unicode codepoint into its UTF-8 representation.
Definition: pack.c:1601
VALUE rb_big_unpack(unsigned long *buf, long num_longs)
Constructs a (possibly very big) bignum from a series of integers.
Definition: bignum.c:3265
VALUE rb_big_divmod(VALUE x, VALUE y)
Performs "divmod" operation.
Definition: bignum.c:6167
VALUE rb_big_xor(VALUE x, VALUE y)
Performs exclusive or of the passed two objects.
Definition: bignum.c:6608
VALUE rb_big_div(VALUE x, VALUE y)
Performs division of the passed two objects.
Definition: bignum.c:6123
VALUE rb_big_norm(VALUE x)
Normalises the passed bignum.
Definition: bignum.c:3194
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
Parses C's string to convert into a Ruby's integer.
Definition: bignum.c:4051
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
Converts a bignum into a series of its parts.
Definition: bignum.c:3257
VALUE rb_big_rshift(VALUE x, VALUE y)
Performs shift right.
Definition: bignum.c:6686
double rb_big2dbl(VALUE x)
Converts a bignum into C's double.
Definition: bignum.c:5346
long rb_big2long(VALUE x)
Converts a bignum into C's long.
Definition: bignum.c:5176
void rb_big_resize(VALUE big, size_t len)
Destructively resizes the backend storage of the passed bignum.
Definition: bignum.c:3029
VALUE rb_big_eq(VALUE lhs, VALUE rhs)
Equality, in terms of ==.
Definition: bignum.c:5554
int len
Length of the buffer.
Definition: io.h:8
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40