Skip to content

Commit 1c7ff62

Browse files
committed
Some insertion of one conversion routine.
1 parent 071a584 commit 1c7ff62

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

src_number/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
PROGRAM = Test_SquareRoot Test_UnorderedMapMpzq Factorize Factorize_help Test_Factorize Test_PracticalInf Test_QuoInt Test_PrintStaticInfo Test_RealCubicField Test_QuadField Test_Rational Test_TypeBoostGmp Test_GetBit Test_QuadraticResidue Test_PrimeGenerator Test_SequenceApproximant ReadValueString ComputeQuadraticResidue Test_ComputePairGcdDot
1+
PROGRAM = Test_SquareRoot Test_UnorderedMapMpzq Factorize Factorize_help Test_Factorize Test_PracticalInf Test_QuoInt Test_PrintStaticInfo Test_RealCubicField Test_QuadField Test_Rational Test_TypeBoostGmp Test_GetBit Test_QuadraticResidue Test_PrimeGenerator Test_SequenceApproximant ReadValueString ComputeQuadraticResidue Test_ComputePairGcdDot Test_Conversion
22
#PROGRAM = test_mpz_givaro
33
#PROGRAM = test_unordered_map_mpzq
44
#PROGRAM = Factorize
55
#PROGRAM = PracticalInf
66
#PROGRAM = TestQuoInt
7-
#PROGRAM = TestConversion
8-
#PROGRAM = TestSquareRoot
7+
#PROGRAM = Test_Conversion
8+
#PROGRAM = Test_SquareRoot
99
#PROGRAM = PrintStaticInfo
1010
#PROGRAM = QuadFieldTest
1111
#PROGRAM = RealCubicFieldTest

src_number/NumberTheoryGmp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,16 @@ inline void TYPE_CONVERSION(stc<long> const &a1, mpz_class &a2) {
535535

536536
#endif
537537

538+
// double as input
539+
540+
// This conversion could be improved upon. But that would slow it
541+
// and in any case the conversion from double has inherent issues
542+
// that have to be addressed in other parts of the code.
543+
inline void TYPE_CONVERSION(stc<double> const &a1, mpz_class &a2) {
544+
uint64_t a1_b = static_cast<int64_t>(a1.val);
545+
a2 = convert_mpz_class_int64_t(a1_b);
546+
}
547+
538548
// int64_t as input
539549

540550
inline void TYPE_CONVERSION(stc<int64_t> const &a1, mpq_class &a2) {

src_number/Test_Conversion.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,8 @@
77
#include "TypeConversionFinal.h"
88
// clang-format on
99

10-
int main(int argc, char *argv[]) {
11-
using T1 = boost::multiprecision::cpp_int;
12-
using T2 = mpz_class;
13-
14-
T1 val1;
15-
T2 val2;
16-
/*
17-
std::string str1 = "43";
18-
std::istringstream is(str1);
19-
is >> val1;
20-
std::cerr << "val1=" << val1;
21-
*/
22-
23-
/*
24-
val1 = 43;
25-
TYPE_CONVERSION_STRING(val1, val2);
26-
std::cerr << "val1=" << val1 << " val2=" << val2 << "\n";
27-
*/
28-
29-
val1 = 43;
30-
val2 = UniversalScalarConversion<T2, T1>(val1);
31-
std::cerr << "val1=" << val1 << " val2=" << val2 << "\n";
10+
int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) {
11+
double val1_d = 1.0;
12+
mpz_class val1_z = UniversalScalarConversion<mpz_class, double>(val1_d);
13+
std::cerr << "val1_z=" << val1_z << " val1_d=" << val1_d << "\n";
3214
}

0 commit comments

Comments
 (0)