From d796e452a338e85cf02f194843a5cbe95af7b89d Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Sat, 15 May 2010 17:03:13 +0800 Subject: [PATCH] fixed silverlight errors --- .gitignore | 3 +- src/Numerics/Control.cs | 3 +- .../NumberTheory/IntegerTheory.Euclid.cs | 28 +++++------ src/Numerics/SpecialFunctions.cs | 1 + src/Silverlight/Silverlight.csproj | 7 +++ src/Silverlight/SilverlightUtilities.cs | 47 +++++++++++++++++++ 6 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 src/Silverlight/SilverlightUtilities.cs diff --git a/.gitignore b/.gitignore index 1105386c..2acf9210 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ _ReSharper* *.bak bin *.vsdoc -*.XML \ No newline at end of file +*.XML +Version1.cs \ No newline at end of file diff --git a/src/Numerics/Control.cs b/src/Numerics/Control.cs index db4e2637..13dceba7 100644 --- a/src/Numerics/Control.cs +++ b/src/Numerics/Control.cs @@ -32,8 +32,9 @@ namespace MathNet.Numerics { using System; using Algorithms.LinearAlgebra; + using Threading; - /// + /// /// Sets parameters for the library. /// public static class Control diff --git a/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs b/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs index 7adc0aa4..de3b2b1b 100644 --- a/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs +++ b/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs @@ -3,9 +3,7 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// // Copyright (c) 2009-2010 Math.NET -// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -14,10 +12,8 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: -// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -48,7 +44,7 @@ namespace MathNet.Numerics.NumberTheory { while (b != 0) { - long remainder = a % b; + var remainder = a % b; a = b; b = remainder; } @@ -76,7 +72,7 @@ namespace MathNet.Numerics.NumberTheory var gcd = Math.Abs(integers[0]); - for (int i = 1; (i < integers.Count) && (gcd > 1); i++) + for (var i = 1; (i < integers.Count) && (gcd > 1); i++) { gcd = GreatestCommonDivisor(gcd, integers[i]); } @@ -111,21 +107,25 @@ namespace MathNet.Numerics.NumberTheory /// The gcd of 45 and 18 is 9: 18 = 2*9, 45 = 5*9. 9 = 1*45 -2*18, therefore x=1 and y=-2. /// public static long ExtendedGreatestCommonDivisor( - long a, - long b, - out long x, + long a, + long b, + out long x, out long y) { long mp = 1, np = 0, m = 0, n = 1; while (b != 0) { - long rem; - long quot = Math.DivRem(a, b, out rem); + long rem; +#if SILVERLIGHT + var quot = SilverlightUtilities.DivRem(a, b, out rem); +#else + long quot = Math.DivRem(a, b, out rem); +#endif a = b; b = rem; - long tmp = m; + var tmp = m; m = mp - (quot * m); mp = tmp; @@ -181,7 +181,7 @@ namespace MathNet.Numerics.NumberTheory var lcm = Math.Abs(integers[0]); - for (int i = 1; i < integers.Count; i++) + for (var i = 1; i < integers.Count; i++) { lcm = LeastCommonMultiple(lcm, integers[i]); } @@ -199,4 +199,4 @@ namespace MathNet.Numerics.NumberTheory return LeastCommonMultiple((IList)integers); } } -} +} \ No newline at end of file diff --git a/src/Numerics/SpecialFunctions.cs b/src/Numerics/SpecialFunctions.cs index 767b9541..29c362c0 100644 --- a/src/Numerics/SpecialFunctions.cs +++ b/src/Numerics/SpecialFunctions.cs @@ -26,6 +26,7 @@ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +// // // Cephes Math Library, Stephen L. Moshier diff --git a/src/Silverlight/Silverlight.csproj b/src/Silverlight/Silverlight.csproj index 292be4ad..2aa1d3cf 100644 --- a/src/Silverlight/Silverlight.csproj +++ b/src/Silverlight/Silverlight.csproj @@ -314,7 +314,14 @@ Trigonometry.cs + + Version1.cs + True + True + Version.tt + + diff --git a/src/Silverlight/SilverlightUtilities.cs b/src/Silverlight/SilverlightUtilities.cs new file mode 100644 index 00000000..8c21ea20 --- /dev/null +++ b/src/Silverlight/SilverlightUtilities.cs @@ -0,0 +1,47 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://numerics.mathdotnet.com +// http://github.com/mathnet/mathnet-numerics +// http://mathnetnumerics.codeplex.com +// Copyright (c) 2009-2010 Math.NET +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +namespace MathNet.Numerics +{ + /// + /// Contains methods missing from Silverlight. + /// + public static class SilverlightUtilities + { + /// + /// Calculates the quotient of two 64-bit signed integers and also returns the remainder in an output parameter. + /// + /// The dividend. + /// The divisor. + /// The remainder. + /// The quotient of the specified numbers. + public static long DivRem(long a, long b, out long result) + { + result = a % b; + return a / b; + } + } +}