conversions to/from ui

This commit is contained in:
Alex Dyachenko 2014-03-23 15:08:30 -04:00
parent c6303e07cf
commit 3f87799456
4 changed files with 27 additions and 9 deletions

View File

@ -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
}
}

View File

@ -94,7 +94,7 @@
<ItemGroup>
<Compile Include="HugeIntTests\Arithmetic.cs" />
<Compile Include="HugeIntTests\Assignment.cs" />
<Compile Include="HugeIntTests\ObjectOverrides.cs" />
<Compile Include="HugeIntTests\Conversions.cs" />
<Compile Include="HugeIntTests\ExpressionTests.cs" />
<Compile Include="Utilities\Accessors.cs" />
<Compile Include="HugeIntTests\ConstructionAndDisposal.cs" />

View File

@ -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)

View File

@ -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); }
}
};
};