Skip to content

Commit

Permalink
WIP fixing GMP usages
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoeurjo committed Dec 5, 2024
1 parent 46e2cfd commit 5c2e618
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/DGtal/kernel/IntegerConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace DGtal
/// @return the same integer
static DGtal::int32_t cast( DGtal::BigInteger i )
{
auto r = i.get_si();
auto r = NumberTraits<DGtal::BigInteger>::castToInt64_t(i);
if ( DGtal::BigInteger( r ) != i )
trace.warning() << "Bad integer conversion: " << i << " -> " << r
<< std::endl;
Expand Down Expand Up @@ -281,9 +281,14 @@ namespace DGtal
/// @return the same integer
static DGtal::int64_t cast( DGtal::BigInteger i )
{
#ifdef WITH_GMP
DGtal::int64_t r = detail::mpz_get_sll( i.get_mpz_t() );
DGtal::BigInteger tmp;
detail::mpz_set_sll( tmp.get_mpz_t(), r );
#else
DGtal::int64_t r = NumberTraits<DGtal::BigInteger>::castToInt64_t(i);
DGtal::BigInteger tmp(r);
#endif
if ( tmp != i )
trace.warning() << "Bad integer conversion: " << i << " -> " << r
<< std::endl;
Expand Down Expand Up @@ -348,7 +353,11 @@ namespace DGtal
static DGtal::BigInteger cast( DGtal::int64_t i )
{
DGtal::BigInteger tmp;
#ifdef WITH_GMP
detail::mpz_set_sll( tmp.get_mpz_t(), i );
#else
tmp = i;
#endif
return tmp;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/kernel/testIntegerConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ SCENARIO( "IntegerConverter< 1, BigInteger >", "[integer_conversions]" )
DGtal::BigInteger b = Converter::cast( big_int64 );
DGtal::BigInteger c = Converter::cast( big_bigint );
DGtal::BigInteger b_prime;
#ifdef WITH_GMP
detail::mpz_set_sll( b_prime.get_mpz_t(), big_int64 );
#else
b_prime = big_int64;
#endif
THEN( "Only bigger integers are identical" ) {
REQUIRE( a == big_int32 );
REQUIRE( a != b );
Expand Down

0 comments on commit 5c2e618

Please sign in to comment.