diff options
Diffstat (limited to 'src/stdlib/bigint.h')
| -rw-r--r-- | src/stdlib/bigint.h | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/src/stdlib/bigint.h b/src/stdlib/bigint.h index 8c3502bf..d7eae403 100644 --- a/src/stdlib/bigint.h +++ b/src/stdlib/bigint.h @@ -1,16 +1,16 @@ // Big integer type (`Int` in Tomo) +#pragma once -#include <gmp.h> #include <stdbool.h> #include <stdint.h> #include "datatypes.h" -#include "stdlib.h" #include "types.h" #include "util.h" Text_t Int$as_text(const void *i, bool colorize, const TypeInfo_t *type); Text_t Int$value_as_text(Int_t i); +int Int$print(FILE *f, Int_t i); PUREFUNC uint64_t Int$hash(const void *x, const TypeInfo_t *type); PUREFUNC int32_t Int$compare(const void *x, const void *y, const TypeInfo_t *type); PUREFUNC int32_t Int$compare_value(const Int_t x, const Int_t y); @@ -33,17 +33,6 @@ bool Int$get_bit(Int_t x, Int_t bit_index); #define BIGGEST_SMALL_INT 0x3fffffff #define SMALLEST_SMALL_INT -0x40000000 -#define Int$from_mpz(mpz) \ - (mpz_cmpabs_ui(mpz, BIGGEST_SMALL_INT) <= 0 \ - ? ((Int_t){.small = (mpz_get_si(mpz) << 2L) | 1L}) \ - : ((Int_t){.big = memcpy(new (__mpz_struct), mpz, sizeof(__mpz_struct))})) - -#define mpz_init_set_int(mpz, i) \ - do { \ - if likely ((i).small & 1L) mpz_init_set_si(mpz, (i).small >> 2L); \ - else mpz_init_set(mpz, (i).big); \ - } while (0) - #define I_small(i) ((Int_t){.small = (int64_t)((uint64_t)(i) << 2L) | 1L}) #define I(i) _Generic(i, int8_t: I_small(i), int16_t: I_small(i), default: Int$from_int64(i)) #define I_is_zero(i) ((i).small == 1L) @@ -63,11 +52,6 @@ Int_t Int$slow_negative(Int_t x); Int_t Int$slow_negated(Int_t x); bool Int$is_prime(Int_t x, Int_t reps); Int_t Int$next_prime(Int_t x); -#if __GNU_MP_VERSION >= 6 -#if __GNU_MP_VERSION_MINOR >= 3 -OptionalInt_t Int$prev_prime(Int_t x); -#endif -#endif Int_t Int$choose(Int_t n, Int_t k); Int_t Int$factorial(Int_t n); @@ -185,25 +169,11 @@ MACROLIKE PUREFUNC bool Int$is_negative(Int_t x) { // Constructors/conversion functions: // Int constructors: -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" -#endif -MACROLIKE PUREFUNC Int_t Int$from_num64(double n, bool truncate) { - mpz_t result; - mpz_init_set_d(result, n); - if (!truncate && unlikely(mpz_get_d(result) != n)) fail("Could not convert to an integer without truncation: ", n); - return Int$from_mpz(result); -} +PUREFUNC Int_t Int$from_num64(double n, bool truncate); MACROLIKE PUREFUNC Int_t Int$from_num32(float n, bool truncate) { return Int$from_num64((double)n, truncate); } -MACROLIKE Int_t Int$from_int64(int64_t i) { - if likely (i >= SMALLEST_SMALL_INT && i <= BIGGEST_SMALL_INT) return (Int_t){.small = (i << 2L) | 1L}; - mpz_t result; - mpz_init_set_si(result, i); - return Int$from_mpz(result); -} +PUREFUNC Int_t Int$from_int64(int64_t i); MACROLIKE CONSTFUNC Int_t Int$from_int32(Int32_t i) { return Int$from_int64((Int32_t)i); } @@ -219,7 +189,3 @@ MACROLIKE CONSTFUNC Int_t Int$from_byte(Byte_t b) { MACROLIKE CONSTFUNC Int_t Int$from_bool(Bool_t b) { return I_small(b); } - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif |
