Assignment rational to int

This commit is contained in:
Alex Dyachenko 2014-05-22 10:35:03 -04:00
parent 0b21fa4efd
commit f22660b71e
3 changed files with 29 additions and 0 deletions

View File

@ -36,6 +36,17 @@ namespace MPIR.Tests.HugeIntTests
}
}
[TestMethod]
public void IntAssignRational()
{
using (var a = new HugeRational("222509832503450298345029835740293845720/7"))
using (var b = new HugeInt())
{
b.SetTo(a);
Assert.AreEqual("31787118929064328335004262248613406531", b.ToString());
}
}
[TestMethod]
public void IntSwap()
{

View File

@ -48,6 +48,7 @@ using namespace System::Runtime::InteropServices;
namespace MPIR
{
ref class MpirRandom;
ref class RationalExpression;
ref class MPTYPE;
ref class MPEXPR(Divide);
ref class MPEXPR(DivideUi);
@ -1622,6 +1623,13 @@ namespace MPIR
/// For bases 37 to 62, upper-case letter represent the usual 10..35 while lower-case letter represent 36..61.</param>
void SetTo(String^ value, int base);
/// <summary>
/// Sets the value of the integer object. Any fractional portion is truncated.
/// <para>Do not change the value of an object while it is contained in a hash table, because that changes its hash code.
/// </para></summary>
/// <param name="value">new value for the object</param>
void SetTo(RationalExpression^ value);
/// <summary>
/// Swaps the values of two integers.
/// <para>This operation is a pointer swap and doesn't affect allocated memory.

View File

@ -387,4 +387,14 @@ namespace MPIR
}
#pragma endregion
#pragma region methods in other classes with rational parameters
void HugeInt::SetTo(MPEXPR_NAME^ value)
{
IN_CONTEXT(value);
mpz_set_q(_value, CTXT(0));
}
#pragma endregion
};