Merge branch 'master' of github.com:adyache/mpir

This commit is contained in:
Alex Dyachenko 2014-06-05 17:06:13 -04:00
commit 45071bb9d1
3 changed files with 51 additions and 59 deletions

View File

@ -272,6 +272,15 @@ private ref class MPEXPR(name) : base
negativeOp(destination, destination, (mpir_ui)-Right); \
}
#define DEFINE_BINARY_ASSIGNMENT_REF_SI2(name, leftTypeAbbr, rightTypeAbbr, operation, negateOp) \
DEFINE_ASSIGNMENT_PROLOG(name##leftTypeAbbr##rightTypeAbbr) \
{ \
Left->AssignTo(destination); \
operation(destination, destination, (Right >= 0) ? (mpir_ui)Right : (mpir_ui)-Right); \
if (Right < 0) \
negateOp(destination, destination); \
}
#define DEFINE_BINARY_ASSIGNMENT_SI_REF(name, leftTypeAbbr, rightTypeAbbr, positiveOp, negativeOp1, negativeOp2) \
DEFINE_ASSIGNMENT_PROLOG(name##leftTypeAbbr##rightTypeAbbr) \
{ \
@ -285,6 +294,19 @@ private ref class MPEXPR(name) : base
} \
}
#define DEFINE_BINARY_ASSIGNMENT_SI_REF2(name, leftTypeAbbr, rightTypeAbbr, positiveOp, negativeOp1, negativeOp2) \
DEFINE_ASSIGNMENT_PROLOG(name##leftTypeAbbr##rightTypeAbbr) \
{ \
Right->AssignTo(destination); \
if (Left >= 0) \
positiveOp(destination, (mpir_ui)Left, destination); \
else \
{ \
negativeOp1(destination, (mpir_ui)-Left, destination); \
negativeOp2(destination, destination); \
} \
}
#define DEFINE_TERNARY_ASSIGNMENT_REF_REF_REF(name, typeAbbr, operation) \
DEFINE_ASSIGNMENT_PROLOG(name##typeAbbr##typeAbbr##typeAbbr) \
{ \

View File

@ -247,24 +247,24 @@ return result->ToString();
DEFINE_UNARY_ASSIGNMENT_REF(Abs, Flt, MP(abs))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Add, Flt, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Add, Flt, Ui, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Add, Flt, Si, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(Add, Flt, Ui, MP(add_ui))
DEFINE_BINARY_ASSIGNMENT_REF_SI (Add, Flt, Si, MP(add_ui), MP(sub_ui))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Subtract, Flt, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Subtract, Flt, Ui, MP(sub))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Subtract, Ui, Flt, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Subtract, Flt, Si, MP(sub))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Subtract, Si, Flt, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(Subtract, Flt, Ui, MP(sub_ui))
DEFINE_BINARY_ASSIGNMENT_VAL_REF(Subtract, Ui, Flt, MP(ui_sub))
DEFINE_BINARY_ASSIGNMENT_REF_SI (Subtract, Flt, Si, MP(sub_ui), MP(add_ui))
DEFINE_BINARY_ASSIGNMENT_SI_REF (Subtract, Si, Flt, MP(ui_sub), MP(add_ui), MP(neg))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Multiply, Flt, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Multiply, Flt, Ui, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Multiply, Flt, Si, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(Multiply, Flt, Ui, MP(mul_ui))
DEFINE_BINARY_ASSIGNMENT_REF_SI2(Multiply, Flt, Si, MP(mul_ui), MP(neg))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Divide, Flt, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Divide, Flt, Ui, MP(div))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Divide, Ui, Flt, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Divide, Flt, Si, MP(div))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Divide, Si, Flt, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(Divide, Flt, Ui, MP(div_ui))
DEFINE_BINARY_ASSIGNMENT_VAL_REF(Divide, Ui, Flt, MP(ui_div))
DEFINE_BINARY_ASSIGNMENT_REF_SI2(Divide, Flt, Si, MP(div_ui), MP(neg))
DEFINE_BINARY_ASSIGNMENT_SI_REF2(Divide, Si, Flt, MP(ui_div), MP(ui_div), MP(neg))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(ShiftLeft, Flt, Bits, MP(mul_2exp))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(ShiftRight, Flt, Bits, MP(div_2exp))
@ -279,28 +279,12 @@ return result->ToString();
size_t MPTYPE::Write(Stream^ stream)
{
auto writtenNumerator = Numerator->Write(stream);
if(writtenNumerator == 0)
return 0;
auto writtenDenominator = Denominator->Write(stream);
if(writtenDenominator == 0)
return 0;
return writtenNumerator + writtenDenominator;
throw gcnew NotImplementedException();
}
size_t MPTYPE::Read(Stream^ stream)
{
auto readNumerator = Numerator->Read(stream);
if(readNumerator == 0)
return 0;
auto readDenominator = Denominator->Read(stream);
if(readDenominator == 0)
return 0;
return readNumerator + readDenominator;
throw gcnew NotImplementedException();
}
size_t MPTYPE::Write(TextWriter^ writer, int base, bool lowercase)
@ -312,21 +296,7 @@ return result->ToString();
size_t MPTYPE::Read(TextReader^ reader, int base)
{
auto readNumerator = Numerator->Read(reader, base);
if(readNumerator == 0)
return 0;
size_t readDenominator = 0;
char c = reader->Peek();
if (c == '/')
{
reader->Read();
readDenominator = 1 + Denominator->Read(reader, base);
if(readDenominator == 1)
return 0;
}
return readNumerator + readDenominator;
throw gcnew NotImplementedException();
}
#pragma endregion

View File

@ -359,7 +359,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator == (MPEXPR_NAME^ a, MPEXPR_NAME^ b) { return IS_NULL(a) ? IS_NULL(b) : a->Equals(b); }
static bool operator == (MPEXPR_NAME^ a, MPEXPR_NAME^ b) { return IS_NULL(a) ? IS_NULL(b) : a->CompareTo(b) == 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -367,7 +367,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator != (MPEXPR_NAME^ a, MPEXPR_NAME^ b) { return IS_NULL(a) ? !IS_NULL(b) : !a->Equals(b); }
static bool operator != (MPEXPR_NAME^ a, MPEXPR_NAME^ b) { return IS_NULL(a) ? !IS_NULL(b) : a->CompareTo(b) != 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -423,7 +423,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator != (MPEXPR_NAME^ a, mpir_ui b) { return IS_NULL(a) || !a->Equals(b); }
static bool operator != (MPEXPR_NAME^ a, mpir_ui b) { return IS_NULL(a) || a->CompareTo(b) != 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -431,7 +431,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator == (MPEXPR_NAME^ a, mpir_ui b) { return !IS_NULL(a) && a->Equals(b); }
static bool operator == (MPEXPR_NAME^ a, mpir_ui b) { return !IS_NULL(a) && a->CompareTo(b) == 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -471,7 +471,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator != (mpir_ui b, MPEXPR_NAME^ a) { return IS_NULL(a) || !a->Equals(b); }
static bool operator != (mpir_ui b, MPEXPR_NAME^ a) { return IS_NULL(a) || a->CompareTo(b) != 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -479,7 +479,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator == (mpir_ui b, MPEXPR_NAME^ a) { return !IS_NULL(a) && a->Equals(b); }
static bool operator == (mpir_ui b, MPEXPR_NAME^ a) { return !IS_NULL(a) && a->CompareTo(b) == 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -519,7 +519,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator != (MPEXPR_NAME^ a, mpir_si b) { return IS_NULL(a) || !a->Equals(b); }
static bool operator != (MPEXPR_NAME^ a, mpir_si b) { return IS_NULL(a) || a->CompareTo(b) != 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -527,7 +527,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator == (MPEXPR_NAME^ a, mpir_si b) { return !IS_NULL(a) && a->Equals(b); }
static bool operator == (MPEXPR_NAME^ a, mpir_si b) { return !IS_NULL(a) && a->CompareTo(b) == 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -567,7 +567,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator != (mpir_si b, MPEXPR_NAME^ a) { return IS_NULL(a) || !a->Equals(b); }
static bool operator != (mpir_si b, MPEXPR_NAME^ a) { return IS_NULL(a) || a->CompareTo(b) != 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -575,7 +575,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator == (mpir_si b, MPEXPR_NAME^ a) { return !IS_NULL(a) && a->Equals(b); }
static bool operator == (mpir_si b, MPEXPR_NAME^ a) { return !IS_NULL(a) && a->CompareTo(b) == 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -615,7 +615,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator != (MPEXPR_NAME^ a, double b) { return IS_NULL(a) || !a->Equals(b); }
static bool operator != (MPEXPR_NAME^ a, double b) { return IS_NULL(a) || a->CompareTo(b) != 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -623,7 +623,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator == (MPEXPR_NAME^ a, double b) { return !IS_NULL(a) && a->Equals(b); }
static bool operator == (MPEXPR_NAME^ a, double b) { return !IS_NULL(a) && a->CompareTo(b) == 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -663,7 +663,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator != (double b, MPEXPR_NAME^ a) { return IS_NULL(a) || !a->Equals(b); }
static bool operator != (double b, MPEXPR_NAME^ a) { return IS_NULL(a) || a->CompareTo(b) != 0; }
/// <summary>Compares two numbers.
/// <para>If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed.
@ -671,7 +671,7 @@ namespace MPIR
/// <param name="a">Source value to compare</param>
/// <param name="b">Source value to compare with</param>
/// <returns>A boolean result of the comparison.</returns>
static bool operator == (double b, MPEXPR_NAME^ a) { return !IS_NULL(a) && a->Equals(b); }
static bool operator == (double b, MPEXPR_NAME^ a) { return !IS_NULL(a) && a->CompareTo(b) == 0; }
/// <summary>Calculates the sign (+1, 0, or -1) of the source value.
/// <para>If the source is an expression, it is evaluated into a temporary variable before the sign is computed.