Ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e0ba6b95ab71a441357ed5484e33498)
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
51VALUE rb_big_new(size_t len, int sign);
52
64int rb_bigzero_p(VALUE x);
65
72VALUE rb_big_clone(VALUE num);
73
81void rb_big_2comp(VALUE num);
82
90VALUE rb_big_norm(VALUE x);
91
98void rb_big_resize(VALUE big, size_t len);
99
125VALUE rb_cstr_to_inum(const char *str, int base, int badcheck);
126
149VALUE rb_str_to_inum(VALUE str, int base, int badcheck);
150
171VALUE rb_cstr2inum(const char *str, int base);
172
196VALUE rb_str2inum(VALUE str, int base);
197
207VALUE rb_big2str(VALUE x, int base);
208
216long rb_big2long(VALUE x);
217
219#define rb_big2int(x) rb_big2long(x)
220
235unsigned long rb_big2ulong(VALUE x);
236
238#define rb_big2uint(x) rb_big2ulong(x)
239
240#if HAVE_LONG_LONG
248LONG_LONG rb_big2ll(VALUE);
249
264unsigned LONG_LONG rb_big2ull(VALUE);
265
266#endif /* HAVE_LONG_LONG */
267
281void rb_big_pack(VALUE val, unsigned long *buf, long num_longs);
282
296VALUE rb_big_unpack(unsigned long *buf, long num_longs);
297
298/* pack.c */
299
310int rb_uv_to_utf8(char buf[6], unsigned long uv);
311
312/* bignum.c */
313
326VALUE rb_dbl2big(double d);
327
339double rb_big2dbl(VALUE x);
340
351VALUE rb_big_cmp(VALUE lhs, VALUE rhs);
352
362VALUE rb_big_eq(VALUE lhs, VALUE rhs);
363
374VALUE rb_big_eql(VALUE lhs, VALUE rhs);
375
384VALUE rb_big_plus(VALUE x, VALUE y);
385
394VALUE rb_big_minus(VALUE x, VALUE y);
395
404VALUE rb_big_mul(VALUE x, VALUE y);
405
414VALUE rb_big_div(VALUE x, VALUE y);
415
424VALUE rb_big_idiv(VALUE x, VALUE y);
425
439VALUE rb_big_modulo(VALUE x, VALUE y);
440
450VALUE rb_big_divmod(VALUE x, VALUE y);
451
463VALUE rb_big_pow(VALUE x, VALUE y);
464
473VALUE rb_big_and(VALUE x, VALUE y);
474
483VALUE rb_big_or(VALUE x, VALUE y);
484
493VALUE rb_big_xor(VALUE x, VALUE y);
494
505VALUE rb_big_lshift(VALUE x, VALUE y);
506
517VALUE rb_big_rshift(VALUE x, VALUE y);
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
679int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
680
761VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
762
781size_t rb_absint_size(VALUE val, int *nlz_bits_ret);
782
804size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret);
805
842int rb_absint_singlebit_p(VALUE val);
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:106
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:97
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:3559
VALUE rb_big_lshift(VALUE x, VALUE y)
Performs shift left.
Definition: bignum.c:6618
VALUE rb_big_and(VALUE x, VALUE y)
Performs bitwise and of the passed two objects.
Definition: bignum.c:6357
VALUE rb_big_or(VALUE x, VALUE y)
Performs bitwise or of the passed two objects.
Definition: bignum.c:6476
VALUE rb_big_minus(VALUE x, VALUE y)
Performs subtraction of the passed two objects.
Definition: bignum.c:5850
VALUE rb_big_modulo(VALUE x, VALUE y)
Performs modulo of the passed two objects.
Definition: bignum.c:6100
VALUE rb_big_new(size_t len, int sign)
Allocates a bignum object.
Definition: bignum.c:3025
VALUE rb_big_pow(VALUE x, VALUE y)
Raises x to the powerof y.
Definition: bignum.c:6241
int rb_bigzero_p(VALUE x)
Queries if the passed bignum instance is a "bigzro".
Definition: bignum.c:2929
VALUE rb_big_plus(VALUE x, VALUE y)
Performs addition of the passed two objects.
Definition: bignum.c:5821
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:4280
VALUE rb_big_clone(VALUE num)
Duplicates the given bignum.
Definition: bignum.c:3031
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:3258
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:3393
int rb_absint_singlebit_p(VALUE val)
Tests abs(val) consists only of a bit or not.
Definition: bignum.c:3458
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:3645
unsigned long rb_big2ulong(VALUE x)
Converts a bignum into C's unsigned long.
Definition: bignum.c:5130
VALUE rb_big_idiv(VALUE x, VALUE y)
Performs "integer division".
Definition: bignum.c:6094
void rb_big_2comp(VALUE num)
Destructively modify the passed bignum into 2's complement representation.
Definition: bignum.c:3060
VALUE rb_big2str(VALUE x, int base)
Generates a place-value representation of the passed integer.
Definition: bignum.c:5096
VALUE rb_big_cmp(VALUE lhs, VALUE rhs)
Compares the passed two bignums.
Definition: bignum.c:5418
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:4556
VALUE rb_dbl2big(double d)
Converts a C's double into a bignum.
Definition: bignum.c:5254
VALUE rb_big_mul(VALUE x, VALUE y)
Performs multiplication of the passed two objects.
Definition: bignum.c:5930
VALUE rb_big_eql(VALUE lhs, VALUE rhs)
Equality, in terms of eql?.
Definition: bignum.c:5542
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:4550
int rb_uv_to_utf8(char buf[6], unsigned long uv)
Encodes a Unicode codepoint into its UTF-8 representation.
Definition: pack.c:1638
VALUE rb_big_unpack(unsigned long *buf, long num_longs)
Constructs a (possibly very big) bignum from a series of integers.
Definition: bignum.c:3234
VALUE rb_big_divmod(VALUE x, VALUE y)
Performs "divmod" operation.
Definition: bignum.c:6132
VALUE rb_big_xor(VALUE x, VALUE y)
Performs exclusive or of the passed two objects.
Definition: bignum.c:6570
VALUE rb_big_div(VALUE x, VALUE y)
Performs division of the passed two objects.
Definition: bignum.c:6088
VALUE rb_big_norm(VALUE x)
Normalises the passed bignum.
Definition: bignum.c:3163
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:4022
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
Converts a bignum into a series of its parts.
Definition: bignum.c:3226
VALUE rb_big_rshift(VALUE x, VALUE y)
Performs shift right.
Definition: bignum.c:6648
double rb_big2dbl(VALUE x)
Converts a bignum into C's double.
Definition: bignum.c:5315
long rb_big2long(VALUE x)
Converts a bignum into C's long.
Definition: bignum.c:5145
void rb_big_resize(VALUE big, size_t len)
Destructively resizes the backend storage of the passed bignum.
Definition: bignum.c:2999
VALUE rb_big_eq(VALUE lhs, VALUE rhs)
Equality, in terms of ==.
Definition: bignum.c:5523
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
Defines VALUE and ID.