Assignment float-to-rational
This commit is contained in:
parent
94a9578826
commit
35a2222d95
@ -86,6 +86,17 @@ namespace MPIR.Tests.HugeRationalTests
|
||||
Assert.AreEqual(d * 5, b.Denominator);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RationalAssignFloat()
|
||||
{
|
||||
using(var a = new HugeFloat("222509832503450298342455029.125"))
|
||||
using(var b = new HugeRational("1/3"))
|
||||
{
|
||||
b.SetTo(a);
|
||||
Assert.AreEqual("1780078660027602386739640233/8", b.ToString());
|
||||
}
|
||||
}
|
||||
//more tests coming here
|
||||
}
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ namespace MPIR
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region methods in other classes with rational parameters
|
||||
#pragma region methods in other classes with float parameters
|
||||
|
||||
void HugeInt::SetTo(MPEXPR_NAME^ value)
|
||||
{
|
||||
@ -435,5 +435,11 @@ namespace MPIR
|
||||
mpz_set_f(_value, CTXT(0));
|
||||
}
|
||||
|
||||
void HugeRational::SetTo(FloatExpression^ value)
|
||||
{
|
||||
IN_CONTEXT(value);
|
||||
mpq_set_f(_value, CTXT(0));
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
};
|
@ -1162,6 +1162,13 @@ namespace MPIR
|
||||
mpz_set(&_value->_mp_den, CTXTI(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of the rational object. There is no rounding, this conversion is exact.
|
||||
/// <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(FloatExpression^ value);
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the values of two rationals.
|
||||
/// <para>This operation is a pointer swap and doesn't affect allocated memory.
|
||||
|
Loading…
Reference in New Issue
Block a user