Ruby 4.1.0dev (2026-11-16 revision 9c7bc705b8bd4542beac71542a8ea79f9bb7622b)
integer.h
Go to the documentation of this file.
1
6#ifndef PRISM_INTEGER_H
7#define PRISM_INTEGER_H
8
10
11#include <stdbool.h>
12#include <stddef.h>
13#include <stdint.h>
14
19typedef struct {
24 uint32_t length;
25
30
35 union {
40 uint32_t value[2];
41
45 uint32_t *values;
46 } words;
48
56static PRISM_INLINE const uint32_t *
57pm_integer_words(const pm_integer_t *integer, uint32_t *length) {
58 *length = integer->length;
59
60 if (integer->length <= 2) {
61 return integer->words.value;
62 } else {
63 return integer->words.values;
64 }
65}
66
74static PRISM_INLINE uint64_t
76 return ((uint64_t) integer->words.value[1] << 32) | integer->words.value[0];
77}
78
79#endif
#define PRISM_INLINE
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition inline.h:12
static PRISM_INLINE uint64_t pm_integer_uint64_value(const pm_integer_t *integer)
Return the magnitude of an integer whose length is at most 2, which always fits in a uint64_t.
Definition integer.h:75
static PRISM_INLINE const uint32_t * pm_integer_words(const pm_integer_t *integer, uint32_t *length)
Return the words of an integer, least significant first.
Definition integer.h:57
C99 shim for <stdbool.h>
A structure represents an arbitrary-sized integer.
Definition integer.h:19
uint32_t length
The number of words in the magnitude, with no leading zero words.
Definition integer.h:24
union pm_integer_t::@107 words
The words of the magnitude.
uint32_t * values
The words of an integer whose length is greater than 2.
Definition integer.h:45
bool negative
Whether or not the integer is negative.
Definition integer.h:29
uint32_t value[2]
The words of an integer whose length is at most 2.
Definition integer.h:40