Float square root. MPIR 2.7.0 section 7.5 completed.

This commit is contained in:
Alex Dyachenko 2014-06-13 13:54:43 -04:00
parent 60da57e24c
commit abb2403cca
3 changed files with 45 additions and 0 deletions

View File

@ -277,6 +277,30 @@ namespace MPIR.Tests.HugeFloatTests
#endregion
#region Sqrt
[TestMethod]
public void FloatSqrt()
{
using(var a = new HugeFloat("9023404035982394058230584.9434590783455098345"))
{
a.Value = a.SquareRoot();
FloatAssert.AreEqual("3003898140081.0504277325488426221152130989784856425363142756", a);
}
}
[TestMethod]
public void FloatSqrtLimb()
{
using(var a = new HugeFloat())
{
a.Value = HugeFloat.SquareRoot(2540928740928357403UL);
FloatAssert.AreEqual("1594029090.3645257511790832426801336140951314995369452070983", a);
}
}
#endregion
#region Divide
#region Int

View File

@ -265,6 +265,7 @@ namespace MPIR
MAKE_UNARY_OPERATOR (MPEXPR_NAME, DEFINE, -, Negate, Flt)
MAKE_VOID_FUNCTION (MPEXPR_NAME, DEFINE, Abs, Flt)
MAKE_VOID_FUNCTION (MPEXPR_NAME, DEFINE, SquareRoot, Flt)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, /, Divide, Flt, Flt)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, /, Divide, Flt, Ui)
@ -274,6 +275,8 @@ namespace MPIR
DEFINE_UNARY_ASSIGNMENT_REF(Negate, Flt, MP(neg))
DEFINE_UNARY_ASSIGNMENT_REF(Abs, Flt, MP(abs))
DEFINE_UNARY_ASSIGNMENT_REF(SquareRoot, Flt, MP(sqrt))
DEFINE_UNARY_ASSIGNMENT_VAL(SquareRoot, Ui, MP(sqrt_ui))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Add, Flt, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(Add, Flt, Ui, MP(add_ui))

View File

@ -298,6 +298,12 @@ namespace MPIR
/// <returns>An expression object that, when assigned to the Value property or consumed by a primitive-returning method, computes the requested operation</returns>
MPEXPR_NAME^ Abs();
/// <summary>Computes the square root of the source number.
/// <para>As with all expressions, the result is not computed until the expression is assigned to the Value property or consumed by a method.
/// </para></summary>
/// <returns>An expression object that, when assigned to the Value property or consumed by a primitive-returning method, computes the requested operation</returns>
MPEXPR_NAME^ SquareRoot();
#pragma endregion
#pragma region Comparisons
@ -713,6 +719,8 @@ namespace MPIR
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Negate, Flt)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Abs, Flt)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, SquareRoot, Flt)
DEFINE_UNARY_EXPRESSION_WITH_BUILT_INS_ONLY (MPEXPR_NAME, SquareRoot, Ui)
#pragma endregion
@ -1239,6 +1247,16 @@ namespace MPIR
// size_t GetLimb(mp_size_t index) { return MP(getlimbn)(_value, index); }
#pragma endregion
#pragma region Arithmetic
/// <summary>Computes the square root of the source number.
/// <para>As with all expressions, the result is not computed until the expression is assigned to the Value property or consumed by a method.
/// </para></summary>
/// <returns>An expression object that, when assigned to the Value property or consumed by a primitive-returning method, computes the requested operation</returns>
static MPEXPR_NAME^ SquareRoot(mpir_ui a) { return gcnew MPEXPR(SquareRootUi)(a); }
#pragma endregion
};
#pragma endregion