Prism Ruby parser
Loading...
Searching...
No Matches
integer.h
Go to the documentation of this file.
1
6#ifndef PRISM_INTEGER_H
7#define PRISM_INTEGER_H
8
9#include "prism/compiler/inline.h"
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
75pm_integer_uint64_value(const pm_integer_t *integer) {
76 return ((uint64_t) integer->words.value[1] << 32) | integer->words.value[0];
77}
78
79#endif
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::@0 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