aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/bigint.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-12-24 12:45:29 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-12-24 12:52:48 -0500
commit649977aae7e5922f992cd69eb84da0a2db368580 (patch)
treee61d35b74d2551901cc8f3f034aca7da1f375a8c /src/stdlib/bigint.h
parent88ccdab43c0a3ee53177e21a28724e496406a376 (diff)
Split out new()/gc logic from stdlib/util.h
Diffstat (limited to 'src/stdlib/bigint.h')
-rw-r--r--src/stdlib/bigint.h28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/stdlib/bigint.h b/src/stdlib/bigint.h
index 9ce4c800..387d47f5 100644
--- a/src/stdlib/bigint.h
+++ b/src/stdlib/bigint.h
@@ -5,7 +5,6 @@
#include <stdint.h>
#include "datatypes.h"
-#include "stdlib.h"
#include "types.h"
#include "util.h"
@@ -33,11 +32,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); \
@@ -185,29 +179,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); }
MACROLIKE CONSTFUNC Int_t Int$from_int16(Int16_t i) { return I_small(i); }
MACROLIKE CONSTFUNC Int_t Int$from_int8(Int8_t i) { return I_small(i); }
MACROLIKE CONSTFUNC Int_t Int$from_byte(Byte_t b) { return I_small(b); }
MACROLIKE CONSTFUNC Int_t Int$from_bool(Bool_t b) { return I_small(b); }
-
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif