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

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

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
523
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
577
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:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
rb_big2ulong
unsigned long rb_big2ulong(VALUE x)
Converts a bignum into C's unsigned long.
Definition bignum.c:5201
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:1601
rb_big2long
long rb_big2long(VALUE x)
Converts a bignum into C's long.
Definition bignum.c:5216
len
int len
Length of the buffer.
Definition io.h:8
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