diff --git a/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Assignment.cs b/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Assignment.cs
new file mode 100644
index 00000000..0b882b87
--- /dev/null
+++ b/build.vc11/mpir.net/mpir.net-tests/HugeIntTests/Assignment.cs
@@ -0,0 +1,40 @@
+/*
+Copyright 2014 Alex Dyachenko
+
+This file is part of the MPIR Library.
+
+The MPIR Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published
+by the Free Software Foundation; either version 3 of the License, or (at
+your option) any later version.
+
+The MPIR Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPIR Library. If not, see http://www.gnu.org/licenses/.
+*/
+
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace MPIR.Tests.HugeIntTests
+{
+ [TestClass]
+ public class Assignment
+ {
+ [TestMethod]
+ public void AssignCopy()
+ {
+ using (var a = new HugeInt("-222509832503450298345029835740293845720"))
+ using (var b = new HugeInt())
+ {
+ b.Value = a;
+ Assert.AreEqual("-222509832503450298345029835740293845720", b.ToString());
+ }
+ }
+ //more tests coming here
+ }
+}
diff --git a/build.vc11/mpir.net/mpir.net-tests/Utilities/Accessors.cs b/build.vc11/mpir.net/mpir.net-tests/Utilities/Accessors.cs
index 82750934..6dbbc2bf 100644
--- a/build.vc11/mpir.net/mpir.net-tests/Utilities/Accessors.cs
+++ b/build.vc11/mpir.net/mpir.net-tests/Utilities/Accessors.cs
@@ -29,15 +29,11 @@ namespace MPIR.Tests
internal static class Accessors
{
private static readonly ConstructorInfo _intPtrConstructor;
- private static readonly FieldInfo _getNumberOfLimbsAllocated;
- private static readonly FieldInfo _getNumberOfLimbsUsed;
- private static readonly FieldInfo _getLimbs;
+ private static readonly FieldInfo _getValue;
static Accessors()
{
- _getNumberOfLimbsAllocated = GetAccessor("_numberOfLimbsAllocated");
- _getNumberOfLimbsUsed = GetAccessor("_numberOfLimbsUsed");
- _getLimbs = GetAccessor("_limbs");
+ _getValue = GetAccessor("_value");
_intPtrConstructor = typeof(IntPtr).GetConstructor(new[] { Type.GetType("System.Void*") });
}
@@ -49,17 +45,40 @@ namespace MPIR.Tests
public static int NumberOfLimbsAllocated(this HugeInt x)
{
- return (int)_getNumberOfLimbsAllocated.GetValue(x);
+ if (x._value() == IntPtr.Zero)
+ return 0;
+
+ unsafe
+ {
+ return ((int*)x._value().ToPointer())[0];
+ }
}
public static int NumberOfLimbsUsed(this HugeInt x)
{
- return (int)_getNumberOfLimbsUsed.GetValue(x);
+ if (x._value() == IntPtr.Zero)
+ return 0;
+
+ unsafe
+ {
+ return ((int*)x._value().ToPointer())[1];
+ }
}
public static IntPtr Limbs(this HugeInt x)
{
- return (IntPtr)_intPtrConstructor.Invoke(new object[] { _getLimbs.GetValue(x) });
+ if (x._value() == IntPtr.Zero)
+ return IntPtr.Zero;
+
+ unsafe
+ {
+ return new IntPtr(((void**)x._value().ToPointer())[1]);
+ }
+ }
+
+ public static IntPtr _value(this HugeInt x)
+ {
+ return (IntPtr)_intPtrConstructor.Invoke(new object[] { _getValue.GetValue(x) });
}
}
}
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 3709be65..27e6b83b 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
@@ -25,6 +25,7 @@
DEBUG;TRACE
prompt
4
+ true
pdbonly
@@ -33,6 +34,7 @@
TRACE
prompt
4
+ true
true
@@ -42,6 +44,7 @@
x64
prompt
MinimumRecommendedRules.ruleset
+ true
bin\x64\Release\
@@ -51,6 +54,7 @@
x64
prompt
MinimumRecommendedRules.ruleset
+ true
true
@@ -60,6 +64,7 @@
x86
prompt
MinimumRecommendedRules.ruleset
+ true
bin\x86\Release\
@@ -69,6 +74,7 @@
x86
prompt
MinimumRecommendedRules.ruleset
+ true
@@ -87,6 +93,7 @@
+
diff --git a/build.vc11/mpir.net/mpir.net/HugeInt.cpp b/build.vc11/mpir.net/mpir.net/HugeInt.cpp
index 4ea303e6..01bf6a82 100644
--- a/build.vc11/mpir.net/mpir.net/HugeInt.cpp
+++ b/build.vc11/mpir.net/mpir.net/HugeInt.cpp
@@ -237,6 +237,17 @@ namespace MPIR
#pragma endregion
+ #pragma region Properties
+
+ void HugeInt::Value::set(HugeInt^ a)
+ {
+ THIS_PTR;
+ mpz_set(src_this, a->_value);
+ SAVE_THIS;
+ }
+
+ #pragma endregion
+
#pragma region Arithmetic
HugeInt^ HugeInt::operator+(HugeInt^ destination, HugeInt^ source)
diff --git a/build.vc11/mpir.net/mpir.net/HugeInt.h b/build.vc11/mpir.net/mpir.net/HugeInt.h
index 6bdf74a4..23773e27 100644
--- a/build.vc11/mpir.net/mpir.net/HugeInt.h
+++ b/build.vc11/mpir.net/mpir.net/HugeInt.h
@@ -74,6 +74,12 @@ namespace MPIR
virtual String^ ToString() override;
String^ ToString(int base);
+ //properties
+ property HugeInt^ Value
+ {
+ void set(HugeInt^ value);
+ }
+
//arithmetic
static HugeInt^ operator+(HugeInt^ destination, HugeInt^ source);
DECLARE_VOID_FROM_MPZ_OR_UI(Add)