diff --git a/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/ObjectOverrides.cs b/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Conversions.cs similarity index 76% rename from build.vc11/mpir.net/mpir.net-tests/HugeIntTests/ObjectOverrides.cs rename to build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Conversions.cs index 722acdfb..49518822 100644 --- a/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/ObjectOverrides.cs +++ b/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Conversions.cs @@ -23,7 +23,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace MPIR.Tests.HugeIntTests { [TestClass] - public class ObjectOverrides + public class Conversions { [TestMethod] public void ToStringDecimal() @@ -46,6 +46,21 @@ namespace MPIR.Tests.HugeIntTests } } + [TestMethod] + public void ToAndFromUlong() + { + using (var a = new HugeInt()) + { + ulong b = 0xF84739ABCDEF4876; + a.AsUlong = b; + Assert.AreEqual(b.ToString(), a.ToString()); + + a.Value = -a; + ulong c = a.AsUlong; + Assert.AreEqual(b.ToString(), c.ToString()); + } + } + //todo truncated test } } diff --git a/build.vc11/mpir.net/mpir.net-tests/mpir.net-tests.csproj b/build.vc11/mpir.net/mpir.net-tests/mpir.net-tests.csproj index 4907bd01..b69a22a7 100644 --- a/build.vc11/mpir.net/mpir.net-tests/mpir.net-tests.csproj +++ b/build.vc11/mpir.net/mpir.net-tests/mpir.net-tests.csproj @@ -94,7 +94,7 @@ - + diff --git a/build.vc11/mpir.net/mpir.net/HugeInt.cpp b/build.vc11/mpir.net/mpir.net/HugeInt.cpp index 10c15d81..a83bedc7 100644 --- a/build.vc11/mpir.net/mpir.net/HugeInt.cpp +++ b/build.vc11/mpir.net/mpir.net/HugeInt.cpp @@ -163,11 +163,6 @@ namespace MPIR #pragma endregion - void HugeInt::Value::set(MpirExpression^ expr) - { - expr->AssignTo(_value); - } - #pragma region expression special cases void MpirDivideExpression::custom_mpz_div(mpz_ptr q, mpz_srcptr n, mpz_srcptr d) diff --git a/build.vc11/mpir.net/mpir.net/HugeInt.h b/build.vc11/mpir.net/mpir.net/HugeInt.h index 4abee436..18b25199 100644 --- a/build.vc11/mpir.net/mpir.net/HugeInt.h +++ b/build.vc11/mpir.net/mpir.net/HugeInt.h @@ -321,6 +321,7 @@ namespace MPIR void FromString(String^ value, int base); internal: + //assignment virtual void AssignTo(mpz_ptr destination) override { if(destination != _value) @@ -350,10 +351,17 @@ namespace MPIR virtual String^ ToString() override; String^ ToString(int base); - //properties + //assignment property MpirExpression^ Value { - void set(MpirExpression^ expr); + void set(MpirExpression^ expr) { expr->AssignTo(_value); } + } + + //conversions + property mpir_ui AsUlong + { + mpir_ui get() { return mpz_get_ui(_value); } + void set(mpir_ui value) { mpz_set_ui(_value, value); } } }; }; \ No newline at end of file