Ruby: include/ruby/internal/intern/bignum.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

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
29#include "ruby/internal/attr/nonnull.h"
30#include "ruby/internal/dllexport.h"
31#include "ruby/internal/value.h"
32#include "ruby/backward/2/long_long.h"
33
34 RBIMPL_SYMBOL_EXPORT_BEGIN()
35
36/* bignum.c */
37
38
51 VALUE rb_big_new(size_t len, int sign);
52
64int rb_bigzero_p(VALUE x);
65
72 VALUE rb_big_clone(VALUE num);
73
81void rb_big_2comp(VALUE num);
82
90 VALUE rb_big_norm(VALUE x);
91
98void rb_big_resize(VALUE big, size_t len);
99
100 RBIMPL_ATTR_NONNULL(())
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
151 RBIMPL_ATTR_NONNULL(())
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
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
248 LONG_LONG rb_big2ll(VALUE);
249
264unsigned LONG_LONG rb_big2ull(VALUE);
265
266#endif /* HAVE_LONG_LONG */
267
268 RBIMPL_ATTR_NONNULL(())
281void rb_big_pack(VALUE val, unsigned long *buf, long num_longs);
282
283 RBIMPL_ATTR_NONNULL(())
296 VALUE rb_big_unpack(unsigned long *buf, long num_longs);
297
298/* pack.c */
299
300 RBIMPL_ATTR_NONNULL(())
310int rb_uv_to_utf8(char buf[6], unsigned long uv);
311
312/* bignum.c */
313
326 VALUE rb_dbl2big(double d);
327
339double 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
384 VALUE rb_big_plus(VALUE x, VALUE y);
385
394 VALUE rb_big_minus(VALUE x, VALUE y);
395
404 VALUE rb_big_mul(VALUE x, VALUE y);
405
414 VALUE rb_big_div(VALUE x, VALUE y);
415
424 VALUE rb_big_idiv(VALUE x, VALUE y);
425
439 VALUE rb_big_modulo(VALUE x, VALUE y);
440
450 VALUE rb_big_divmod(VALUE x, VALUE y);
451
463 VALUE rb_big_pow(VALUE x, VALUE y);
464
473 VALUE rb_big_and(VALUE x, VALUE y);
474
483 VALUE rb_big_or(VALUE x, VALUE y);
484
493 VALUE rb_big_xor(VALUE x, VALUE y);
494
505 VALUE rb_big_lshift(VALUE x, VALUE y);
506
517 VALUE 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
578 RBIMPL_ATTR_NONNULL(())
679int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
680
681 RBIMPL_ATTR_NONNULL(())
761 VALUE 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
844 RBIMPL_SYMBOL_EXPORT_END()
845
846#endif /* RBIMPL_INTERN_BIGNUM_H */
long_long.h
Defines old LONG_LONG.
LONG_LONG
#define LONG_LONG
Definition long_long.h:38
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
rb_integer_pack
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:3577
rb_big_lshift
VALUE rb_big_lshift(VALUE x, VALUE y)
Performs shift left.
Definition bignum.c:6638
rb_big_and
VALUE rb_big_and(VALUE x, VALUE y)
Performs bitwise and of the passed two objects.
Definition bignum.c:6377
rb_big_or
VALUE rb_big_or(VALUE x, VALUE y)
Performs bitwise or of the passed two objects.
Definition bignum.c:6496
rb_big_minus
VALUE rb_big_minus(VALUE x, VALUE y)
Performs subtraction of the passed two objects.
Definition bignum.c:5870
rb_big_modulo
VALUE rb_big_modulo(VALUE x, VALUE y)
Performs modulo of the passed two objects.
Definition bignum.c:6120
rb_big_new
VALUE rb_big_new(size_t len, int sign)
Allocates a bignum object.
Definition bignum.c:3043
rb_big_pow
VALUE rb_big_pow(VALUE x, VALUE y)
Raises x to the powerof y.
Definition bignum.c:6261
rb_bigzero_p
int rb_bigzero_p(VALUE x)
Queries if the passed bignum instance is a "bigzro".
Definition bignum.c:2947
rb_big_plus
VALUE rb_big_plus(VALUE x, VALUE y)
Performs addition of the passed two objects.
Definition bignum.c:5841
rb_str_to_inum
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:4297
rb_big_clone
VALUE rb_big_clone(VALUE num)
Duplicates the given bignum.
Definition bignum.c:3049
rb_absint_size
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:3276
rb_absint_numwords
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:3411
rb_absint_singlebit_p
int rb_absint_singlebit_p(VALUE val)
Tests abs(val) consists only of a bit or not.
Definition bignum.c:3476
rb_integer_unpack
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:3663
rb_big2ulong
unsigned long rb_big2ulong(VALUE x)
Converts a bignum into C's unsigned long.
Definition bignum.c:5150
rb_big_idiv
VALUE rb_big_idiv(VALUE x, VALUE y)
Performs "integer division".
Definition bignum.c:6114
rb_big_2comp
void rb_big_2comp(VALUE num)
Destructively modify the passed bignum into 2's complement representation.
Definition bignum.c:3078
rb_big2str
VALUE rb_big2str(VALUE x, int base)
Generates a place-value representation of the passed integer.
Definition bignum.c:5116
rb_big_cmp
VALUE rb_big_cmp(VALUE lhs, VALUE rhs)
Compares the passed two bignums.
Definition bignum.c:5438
rb_str2inum
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:4573
rb_dbl2big
VALUE rb_dbl2big(double d)
Converts a C's double into a bignum.
Definition bignum.c:5274
rb_big_mul
VALUE rb_big_mul(VALUE x, VALUE y)
Performs multiplication of the passed two objects.
Definition bignum.c:5950
rb_big_eql
VALUE rb_big_eql(VALUE lhs, VALUE rhs)
Equality, in terms of eql?.
Definition bignum.c:5562
rb_cstr2inum
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:4567
rb_uv_to_utf8
int rb_uv_to_utf8(char buf[6], unsigned long uv)
Encodes a Unicode codepoint into its UTF-8 representation.
Definition pack.c:1625
rb_big_unpack
VALUE rb_big_unpack(unsigned long *buf, long num_longs)
Constructs a (possibly very big) bignum from a series of integers.
Definition bignum.c:3252
rb_big_divmod
VALUE rb_big_divmod(VALUE x, VALUE y)
Performs "divmod" operation.
Definition bignum.c:6152
rb_big_xor
VALUE rb_big_xor(VALUE x, VALUE y)
Performs exclusive or of the passed two objects.
Definition bignum.c:6590
rb_big_div
VALUE rb_big_div(VALUE x, VALUE y)
Performs division of the passed two objects.
Definition bignum.c:6108
rb_big_norm
VALUE rb_big_norm(VALUE x)
Normalises the passed bignum.
Definition bignum.c:3181
rb_cstr_to_inum
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:4040
rb_big_pack
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
Converts a bignum into a series of its parts.
Definition bignum.c:3244
rb_big_rshift
VALUE rb_big_rshift(VALUE x, VALUE y)
Performs shift right.
Definition bignum.c:6668
rb_big2dbl
double rb_big2dbl(VALUE x)
Converts a bignum into C's double.
Definition bignum.c:5335
rb_big2long
long rb_big2long(VALUE x)
Converts a bignum into C's long.
Definition bignum.c:5165
rb_big_resize
void rb_big_resize(VALUE big, size_t len)
Destructively resizes the backend storage of the passed bignum.
Definition bignum.c:3017
rb_big_eq
VALUE rb_big_eq(VALUE lhs, VALUE rhs)
Equality, in terms of ==.
Definition bignum.c:5543
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40