🐧 Cross-platform build support

This commit is contained in:
bitcookies
2026-04-05 22:09:59 +08:00
parent 47fe667eda
commit 8c3814fe8e
12 changed files with 908 additions and 19 deletions
+19 -2
View File
@@ -1,7 +1,24 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4146 4244 4267)
#endif
#include <gmp.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// MPIR (used by vcpkg x86/x64) provides mpz_*_sx/mpz_*_ux for intmax_t.
// Standard GMP (used by ARM64 and Linux/macOS) does not; fall back to long variants.
#ifndef __MPIR_VERSION
#define mpz_init_set_sx(z, v) mpz_init_set_si((z), static_cast<long>(v))
#define mpz_init_set_ux(z, v) mpz_init_set_ui((z), static_cast<unsigned long>(v))
#define mpz_set_sx(z, v) mpz_set_si((z), static_cast<long>(v))
#define mpz_set_ux(z, v) mpz_set_ui((z), static_cast<unsigned long>(v))
#endif
#include <vector>
#include <string>
#include <type_traits>
@@ -300,11 +317,11 @@ public:
}
bool TestBit(size_t i) const noexcept {
return mpz_tstbit(_Value, i) != 0;
return mpz_tstbit(_Value, static_cast<mp_bitcnt_t>(i)) != 0;
}
void SetBit(size_t i) noexcept {
mpz_setbit(_Value, i);
mpz_setbit(_Value, static_cast<mp_bitcnt_t>(i));
}
std::string ToString(size_t Base, bool LowerCase) const {