34 #ifndef ION_INT_INITTO
35 #define ION_INT_INITTO
41 #define ION_INT_INIT init
45 #ifndef ION_INT_GLOBAL
46 #define ION_INT_GLOBAL extern
60 typedef uint32_t II_DIGIT;
61 typedef uint64_t II_LONG_DIGIT;
66 #define II_BASE ((uint32_t)0x80000000)
67 #define II_MASK ((uint32_t)0x7FFFFFFF)
68 #define II_SHIFT ((uint32_t)31)
70 #define II_BITS_PER_II_DIGIT II_SHIFT
71 #define II_DIGIT_COUNT_FROM_BITS(bits) (((bits) == 0) ? 1 : (((((int)bits) - 1) / II_BITS_PER_II_DIGIT) + 1))
73 #define II_STRING_BASE 10
74 #define II_BITS_PER_DEC_DIGIT 3.35
75 #define II_DEC_DIGIT_PER_BITS 3.32191780821918
76 #define II_II_DIGITS_PER_DEC_DIGIT 0.108064516
77 #define II_DEC_DIGITS_PER_II_DIGIT 9.253731343
79 #define DECIMAL_DIGIT_COUNT_FROM_BITS(bits) (((bits) == 0) ? 1 : ((SIZE)(((double)(bits) / II_DEC_DIGIT_PER_BITS) + 1)))
81 #define II_BITS_PER_HEX_DIGIT 4
82 #define II_HEX_BASE 16
83 #define II_HEX_RADIX_CHARS "xX"
84 #define II_BITS_PER_BINARY_DIGIT 1
85 #define II_BINARY_BASE 2
86 #define II_BINARY_RADIX_CHARS "bB"
88 #define II_MAX_DIGIT (II_MASK)
89 #define II_BITS_PER_BYTE 8
90 #define II_BYTE_BASE 256
91 #define II_BYTE_MASK 0xFF
92 #define II_BYTE_SIGN_BIT 0x80
93 #define II_BYTE_NEG_OVERFLOW_LIMIT 0xFE
95 #define II_INT64_BIT_THRESHOLD (sizeof(int64_t)*8-2)
97 #define II_SMALL_DIGIT_ARRAY_LENGTH ((256 / II_BITS_PER_II_DIGIT)+1)
107 ION_INT_GLOBAL II_DIGIT g_int_zero_bytes[]
112 ION_INT_GLOBAL
ION_INT g_Int_Zero
121 ION_INT_GLOBAL
ION_INT g_Int_Null
131 ION_INT_GLOBAL THREAD_LOCAL_STORAGE BOOL g_ion_int_globals_initialized;
132 ION_INT_GLOBAL THREAD_LOCAL_STORAGE decQuad g_digit_base_quad;
133 ION_INT_GLOBAL THREAD_LOCAL_STORAGE decNumber g_digit_base_number;
139 ION_API_EXPORT iERR ion_int_alloc (
void *owner,
ION_INT **piint);
140 ION_API_EXPORT
void ion_int_free (
ION_INT *iint);
141 ION_API_EXPORT iERR ion_int_init (
ION_INT *iint,
void *owner);
142 ION_API_EXPORT iERR ion_int_copy (
ION_INT *dst,
ION_INT *src,
void *owner);
144 ION_API_EXPORT iERR ion_int_is_null (
ION_INT *iint, BOOL *p_is_null);
145 ION_API_EXPORT iERR ion_int_is_zero (
ION_INT *iint, BOOL *p_bool);
146 ION_API_EXPORT iERR ion_int_compare (
ION_INT *left,
ION_INT *right,
int *p_result);
147 ION_API_EXPORT iERR ion_int_signum (
ION_INT *iint, int32_t *p_signum);
148 ION_API_EXPORT iERR ion_int_highest_bit_set (
ION_INT *iint, SIZE *p_pos);
150 ION_API_EXPORT iERR ion_int_from_string (
ION_INT *iint,
const iSTRING p_str);
151 ION_API_EXPORT iERR ion_int_from_hex_string (
ION_INT *iint,
const iSTRING p_str);
152 ION_API_EXPORT iERR ion_int_from_binary_string(
ION_INT *iint,
const iSTRING p_str);
153 ION_API_EXPORT iERR ion_int_from_chars (
ION_INT *iint,
const char *p_chars, SIZE char_limit);
154 ION_API_EXPORT iERR ion_int_from_hex_chars (
ION_INT *iint,
const char *p_chars, SIZE char_limit);
155 ION_API_EXPORT iERR ion_int_from_binary_chars(
ION_INT *iint,
const char *p_chars, SIZE char_limit);
156 ION_API_EXPORT iERR ion_int_from_bytes (
ION_INT *iint, BYTE *buf, SIZE limit);
157 ION_API_EXPORT iERR ion_int_from_abs_bytes (
ION_INT *iint, BYTE *buf, SIZE limit, BOOL is_negative);
158 ION_API_EXPORT iERR ion_int_from_long (
ION_INT *iint, int64_t value);
165 ION_API_EXPORT iERR ion_int_char_length (
ION_INT *iint, SIZE *p_len);
166 ION_API_EXPORT iERR ion_int_to_char (
ION_INT *iint, BYTE *p_str, SIZE len, SIZE *p_written);
167 ION_API_EXPORT iERR ion_int_to_string (
ION_INT *iint, hOWNER owner,
iSTRING p_str);
169 ION_API_EXPORT iERR ion_int_byte_length (
ION_INT *iint, SIZE *p_byte_length);
170 ION_API_EXPORT iERR ion_int_to_bytes (
ION_INT *iint, SIZE starting_int_byte_offset, BYTE *buffer, SIZE buffer_length, SIZE *bytes_written);
171 ION_API_EXPORT iERR ion_int_abs_bytes_length(
ION_INT *iint, SIZE *p_byte_length);
172 ION_API_EXPORT iERR ion_int_to_abs_bytes (
ION_INT *iint, SIZE starting_int_byte_offset, BYTE *buffer, SIZE buffer_length, SIZE *bytes_written);
173 ION_API_EXPORT iERR ion_int_to_int64 (
ION_INT *iint, int64_t *p_int64);
174 ION_API_EXPORT iERR ion_int_to_int32 (
ION_INT *iint, int32_t *p_int32);
184 void _ion_int_dump_quad(decQuad *quad, int64_t expected);
185 int _ion_int_init_globals(
void);
187 iERR _ion_int_from_decimal_number(
ION_INT *iint,
const decNumber *p_value, decContext *context);
188 iERR _ion_int_to_decimal_number(
ION_INT *iint, decNumber *p_value, decContext *context);
190 iERR _ion_int_validate_arg(
const ION_INT *iint);
191 iERR _ion_int_validate_arg_with_ptr(
const ION_INT *iint,
const void *ptr);
192 iERR _ion_int_validate_non_null_arg_with_ptr(
const ION_INT *iint,
const void *ptr);
194 void _ion_int_init(
ION_INT *iint,
void *owner);
195 iERR _ion_int_zero(
ION_INT *iint);
196 void * _ion_int_realloc_helper(
void *value, SIZE old_len,
void *owner, SIZE new_len);
197 iERR _ion_int_extend_digits(
ION_INT *iint, SIZE digits_needed, BOOL zero_fill);
198 II_DIGIT *_ion_int_buffer_temp_copy( II_DIGIT *orig_digits, SIZE len, II_DIGIT *cache_buffer, SIZE cache_len);
199 II_DIGIT *_ion_int_buffer_temp_copy( II_DIGIT *orig_digits, SIZE len, II_DIGIT *cache_buffer, SIZE cache_len);
200 void _ion_int_free_temp(II_DIGIT *temp_buffer, II_DIGIT *cache_buffer);
202 BOOL _ion_int_from_bytes_helper(
ION_INT *iint, BYTE *buf, SIZE byte_idx, SIZE limit, BOOL invert, BOOL includes_sign_byte);
203 iERR _ion_int_from_chars_helper(
ION_INT *iint,
const char *str, SIZE len);
204 iERR _ion_int_from_radix_chars_helper(
ION_INT *iint,
const char *str, SIZE len,
unsigned int *digit_values,
unsigned int base,
unsigned int bits_per_digit,
const char *radix_chars);
205 iERR _ion_int_from_hex_chars_helper(
ION_INT *iint,
const char *str, SIZE len);
206 iERR _ion_int_from_binary_chars_helper(
ION_INT *iint,
const char *str, SIZE len);
208 BOOL _ion_int_is_null_helper(
const ION_INT *iint);
209 BOOL _ion_int_is_zero(
const ION_INT *iint);
210 BOOL _ion_int_is_zero_bytes(
const II_DIGIT *digits, SIZE len);
212 SIZE _ion_int_highest_bit_set_helper(
const ION_INT *iint);
214 SIZE _ion_int_get_char_len_helper(
const ION_INT *iint);
215 iERR _ion_int_to_string_helper(
ION_INT *iint,
char *strbuf, SIZE buflen, SIZE *p_written);
217 BOOL _ion_int_is_high_bytes_high_bit_set_helper(
const ION_INT *iint, SIZE abs_byte_count);
218 SIZE _ion_int_bytes_length_helper(
const ION_INT *iint);
219 iERR _ion_int_to_bytes_helper(
ION_INT *iint, SIZE bytes_in_int, SIZE starting_int_byte_offset, BOOL is_neg, BYTE *buffer, SIZE buffer_length, SIZE *bytes_written);
221 SIZE _ion_int_abs_bytes_length_helper(
const ION_INT *iint);
222 SIZE _ion_int_abs_bytes_signed_length_helper(
const ION_INT *iint);
225 iERR _ion_int_to_int64_helper(
ION_INT *iint, int64_t *p_int64);
227 iERR _ion_int_add_digit(II_DIGIT *digits, SIZE digit_count, II_DIGIT value);
228 iERR _ion_int_sub_digit(II_DIGIT *digits, SIZE digit_count, II_DIGIT value);
232 iERR _ion_int_multiply_and_add(II_DIGIT *digits, SIZE digit_count, II_DIGIT mult_value, II_DIGIT add_value);
233 iERR _ion_int_divide_by_digit(II_DIGIT *digits, SIZE digit_count, II_DIGIT value, II_DIGIT *p_remainder);
ION_API_EXPORT iERR ion_int_from_decimal(ION_INT *iint, const decQuad *p_value, decContext *context)
ION_API_EXPORT iERR ion_int_to_decimal(ION_INT *iint, decQuad *p_quad, decContext *context)
Definition: ion_int.h:100
Definition: ion_string.h:40