From 609b9eb948b5e7c27714efc0b2f87f0afb699157 Mon Sep 17 00:00:00 2001 From: Alex Dyachenko Date: Wed, 4 Jun 2014 17:20:08 -0400 Subject: [PATCH 1/3] Removed irrelevant copied code in IO ops, fixed build. --- mpir.net/mpir.net/HugeFloat.cpp | 36 +++------------------------------ 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/mpir.net/mpir.net/HugeFloat.cpp b/mpir.net/mpir.net/HugeFloat.cpp index 2382e45a..6d27f152 100644 --- a/mpir.net/mpir.net/HugeFloat.cpp +++ b/mpir.net/mpir.net/HugeFloat.cpp @@ -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 From a7fc90ffa147c149482251fa2c9383f6ed55319d Mon Sep 17 00:00:00 2001 From: Alex Dyachenko Date: Thu, 5 Jun 2014 14:51:06 -0400 Subject: [PATCH 2/3] Float arithmetic 7.5 except two SQRT methods --- mpir.net/mpir.net/ExpressionMacros.h | 22 ++++++++++++++++++++++ mpir.net/mpir.net/HugeFloat.cpp | 24 ++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/mpir.net/mpir.net/ExpressionMacros.h b/mpir.net/mpir.net/ExpressionMacros.h index 681cfa9c..5119f1b2 100644 --- a/mpir.net/mpir.net/ExpressionMacros.h +++ b/mpir.net/mpir.net/ExpressionMacros.h @@ -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) \ { \ diff --git a/mpir.net/mpir.net/HugeFloat.cpp b/mpir.net/mpir.net/HugeFloat.cpp index 6d27f152..1c3fedf8 100644 --- a/mpir.net/mpir.net/HugeFloat.cpp +++ b/mpir.net/mpir.net/HugeFloat.cpp @@ -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)) From 8a3347655653adab3dc41343438c42fce16033af Mon Sep 17 00:00:00 2001 From: Alex Dyachenko Date: Thu, 5 Jun 2014 14:52:10 -0400 Subject: [PATCH 3/3] Float comparisons 7.6 except eq-bits and rel-dif --- mpir.net/mpir.net/HugeFloat.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mpir.net/mpir.net/HugeFloat.h b/mpir.net/mpir.net/HugeFloat.h index e18f02bc..785e8b18 100644 --- a/mpir.net/mpir.net/HugeFloat.h +++ b/mpir.net/mpir.net/HugeFloat.h @@ -359,7 +359,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -367,7 +367,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -423,7 +423,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -431,7 +431,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -471,7 +471,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -479,7 +479,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -519,7 +519,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -527,7 +527,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -567,7 +567,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -575,7 +575,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -615,7 +615,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -623,7 +623,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -663,7 +663,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Compares two numbers. /// If any argument is an expression, it is evaluated into a temporary variable before the comparison is performed. @@ -671,7 +671,7 @@ namespace MPIR /// Source value to compare /// Source value to compare with /// A boolean result of the comparison. - 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; } /// Calculates the sign (+1, 0, or -1) of the source value. /// If the source is an expression, it is evaluated into a temporary variable before the sign is computed.