Skip to content

Commit

Permalink
use libgmp proper
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Oct 9, 2024
1 parent e1e568f commit 403b59d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/big/big_int.cr
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ struct BigInt < Int
{% for n in [8, 16, 32, 64, 128] %}
def to_i{{n}} : Int{{n}}
\{% if Int{{n}} == LibGMP::SI %}
LibGMP.{{ flag?(:win32) ? "fits_si_p".id : "fits_slong_p".id }}(self) != 0 ? LibGMP.get_si(self) : raise OverflowError.new
LibGMP.{{ flag?(:win32) && !flag?(:gnu) ? "fits_si_p".id : "fits_slong_p".id }}(self) != 0 ? LibGMP.get_si(self) : raise OverflowError.new
\{% elsif Int{{n}}::MAX.is_a?(NumberLiteral) && Int{{n}}::MAX < LibGMP::SI::MAX %}
LibGMP::SI.new(self).to_i{{n}}
\{% else %}
Expand All @@ -669,7 +669,7 @@ struct BigInt < Int

def to_u{{n}} : UInt{{n}}
\{% if UInt{{n}} == LibGMP::UI %}
LibGMP.{{ flag?(:win32) ? "fits_ui_p".id : "fits_ulong_p".id }}(self) != 0 ? LibGMP.get_ui(self) : raise OverflowError.new
LibGMP.{{ flag?(:win32) && !flag?(:gnu) ? "fits_ui_p".id : "fits_ulong_p".id }}(self) != 0 ? LibGMP.get_ui(self) : raise OverflowError.new
\{% elsif UInt{{n}}::MAX.is_a?(NumberLiteral) && UInt{{n}}::MAX < LibGMP::UI::MAX %}
LibGMP::UI.new(self).to_u{{n}}
\{% else %}
Expand Down
8 changes: 4 additions & 4 deletions src/big/lib_gmp.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if flag?(:win32) %}
{% if flag?(:win32) && !flag?(:gnu) %}
@[Link("mpir")]
{% if compare_versions(Crystal::VERSION, "1.11.0-dev") >= 0 %}
@[Link(dll: "mpir.dll")]
Expand All @@ -14,7 +14,7 @@ lib LibGMP
# MPIR uses its own `mpir_si` and `mpir_ui` typedefs in places where GMP uses
# the LibC types, when the function name has `si` or `ui`; we follow this
# distinction
{% if flag?(:win32) && flag?(:bits64) %}
{% if flag?(:win32) && !flag?(:gnu) && flag?(:bits64) %}
alias SI = LibC::LongLong
alias UI = LibC::ULongLong
{% else %}
Expand All @@ -26,7 +26,7 @@ lib LibGMP
alias Double = LibC::Double
alias BitcntT = UI

{% if flag?(:win32) && flag?(:bits64) %}
{% if flag?(:win32) && !flag?(:gnu) && flag?(:bits64) %}
alias MpExp = LibC::Long
alias MpSize = LibC::LongLong
alias MpLimb = LibC::ULongLong
Expand Down Expand Up @@ -151,7 +151,7 @@ lib LibGMP

fun fits_ulong_p = __gmpz_fits_ulong_p(op : MPZ*) : Int
fun fits_slong_p = __gmpz_fits_slong_p(op : MPZ*) : Int
{% if flag?(:win32) %}
{% if flag?(:win32) && !flag?(:gnu) %}
fun fits_ui_p = __gmpz_fits_ui_p(op : MPZ*) : Int
fun fits_si_p = __gmpz_fits_si_p(op : MPZ*) : Int
{% end %}
Expand Down

0 comments on commit 403b59d

Please sign in to comment.