From b4940574c06ea2a61ee3097dc145302d4a48911e Mon Sep 17 00:00:00 2001 From: Alex Dyachenko Date: Mon, 24 Mar 2014 00:04:35 -0400 Subject: [PATCH] Swap. Completed MPIR 2.6.0 section 5.2, except setting MPZ from MPQ or MPF --- .../mpir.net-tests/HugeIntTests/Assignment.cs | 14 ++++++++++++++ build.vc11/mpir.net/mpir.net/HugeInt.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Assignment.cs b/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Assignment.cs index 0b882b87..b1b38358 100644 --- a/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Assignment.cs +++ b/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Assignment.cs @@ -35,6 +35,20 @@ namespace MPIR.Tests.HugeIntTests Assert.AreEqual("-222509832503450298345029835740293845720", b.ToString()); } } + + [TestMethod] + public void Swap() + { + using (var a = new HugeInt("-222509832503450298345029835740293845720")) + using (var b = new HugeInt("2039847290878794872059384789347534534")) + { + var aValue = a._value(); + var bValue = b._value(); + a.Swap(b); + Assert.AreEqual(bValue, a._value()); + Assert.AreEqual(aValue, b._value()); + } + } //more tests coming here } } diff --git a/build.vc11/mpir.net/mpir.net/HugeInt.h b/build.vc11/mpir.net/mpir.net/HugeInt.h index 0edea396..601e807d 100644 --- a/build.vc11/mpir.net/mpir.net/HugeInt.h +++ b/build.vc11/mpir.net/mpir.net/HugeInt.h @@ -367,5 +367,8 @@ namespace MPIR void SetTo(double value) { mpz_set_d(_value, value); } void SetTo(String^ value) { SetTo(value, 10); } void SetTo(String^ value, int base); + + //utility methods + void Swap(HugeInt^ a) { mpz_ptr temp = a->_value; a->_value = _value; _value = temp; } }; }; \ No newline at end of file