Skip to content

Commit

Permalink
RootFinding: migrate message strings to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrnet committed May 1, 2013
1 parent be5d8b9 commit 8742c92
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
18 changes: 18 additions & 0 deletions src/Numerics/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions src/Numerics/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,16 @@
<data name="TooManyElements" xml:space="preserve">
<value>We only support sparse matrix with less than int.MaxValue elements.</value>
</data>
<data name="Interpolation_Initialize_SamplePointsNotStrictlyAscendingOrder">
<value xml:space="preserve">Sample points should be sorted in strictly ascending order</value>
<data name="Interpolation_Initialize_SamplePointsNotStrictlyAscendingOrder" xml:space="preserve">
<value>Sample points should be sorted in strictly ascending order</value>
</data>
<data name="Interpolation_Initialize_SamplePointsNotUnique">
<value xml:space="preserve">All sample points should be unique.</value>
<data name="Interpolation_Initialize_SamplePointsNotUnique" xml:space="preserve">
<value>All sample points should be unique.</value>
</data>
<data name="AccuracyNotReached" xml:space="preserve">
<value>The accuracy couldn't be reached with the specified number of iterations.</value>
</data>
<data name="RootNotFound" xml:space="preserve">
<value>The algorithm ended without root in the range.</value>
</data>
</root>
3 changes: 2 additions & 1 deletion src/Numerics/RootFinding/BrentRootFinder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MathNet.Numerics.Properties;

namespace MathNet.Numerics.RootFinding
{
Expand Down Expand Up @@ -108,7 +109,7 @@ University Press
}

// The algorithm has exceeded the number of iterations allowed
throw new RootFinderException(ACCURACY_NOT_REACHED, i, new Range(XMin, XMax), Math.Abs(xMid));
throw new RootFinderException(Resources.AccuracyNotReached, i, new Range(XMin, XMax), Math.Abs(xMid));
}
}
}
13 changes: 4 additions & 9 deletions src/Numerics/RootFinding/RootFinder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MathNet.Numerics.Properties;

namespace MathNet.Numerics.RootFinding
{
Expand Down Expand Up @@ -41,13 +42,7 @@ public Range Range
}
public abstract class RootFinder
{

protected const string INVALID_RANGE="Invalid range while finding root";
protected const string ACCURACY_NOT_REACHED = "The accuracy couldn't be reached with the specified number of iterations";
protected const string ROOT_NOT_FOUND = "The algorithm ended without root in the range";
protected const string ROOT_NOT_BRACKETED = "The algorithm could not start because the root seemed not to be bracketed";
protected const string INVALID_ALGORITHM = "This algorithm is not able to solve this equation";
protected const double DOUBLE_ACCURACY = 9.99200722162641E-16;
protected const double DOUBLE_ACCURACY = 9.99200722162641E-16;
private const int DEFAULT_MAX_ITERATIONS = 30;
private const double DEFAULT_ACCURACY = 1e-8;

Expand Down Expand Up @@ -122,7 +117,7 @@ public bool SearchBracketsOutward(ref double xmin, ref double xmax, double facto
{
if (xmin >= xmax)
{
throw new RootFinderException(INVALID_RANGE, 0, new Range(xmin, xmax), 0.0);
throw new RootFinderException(string.Format(Resources.ArgumentOutOfRangeGreater,"xmax","xmin"), 0, new Range(xmin, xmax), 0.0);
}

double fmin = _func(xmin);
Expand All @@ -144,7 +139,7 @@ public bool SearchBracketsOutward(ref double xmin, ref double xmax, double facto
}
}

throw new RootFinderException(ROOT_NOT_FOUND, i, new Range(fmin, fmax), 0.0);
throw new RootFinderException(Resources.RootNotFound, i, new Range(fmin, fmax), 0.0);
}

/// <summary>Prototype algorithm for solving the equation f(x)=0.</summary>
Expand Down

0 comments on commit 8742c92

Please sign in to comment.