我正在使用 Koen Vos 在“Burg\xe2\x80\x99s 方法的快速实现”中提出的方法制作 Burg 算法的 C# 版本。
\n\n我使用 GNU Octavearburg函数来比较结果。\n当我在 C# 代码中使用内部变量时,测试结果几乎相同(精度为 0.0000000000001),但当我使用时(精度为 0.01),测试结果decimal却截然不同。double
据我所知,GNU Octave 对 float 使用 64 位精度,而不是 128 位。我错了吗?
\n\n/* Coefficients for comparision are taken from GNU Octave arburg() \n* t = [0:2000];\n* x = sin( 2 * pi() * t / (512 / 5.2));\n* output_precision(16)\n* [a, v, k] = arburg(x(1:512), 4)\n*/\nRun Code Online (Sandbox Code Playgroud)\n\nC# 代码超过 300 行,所以我认为最好不要放在这里。
\n\n我认为要么 GNU Octave 在底层使用 128 位精度,要么我在 …
我一直在寻找代码中的迹象,表明可能会违反里氏替换原则。首先我创建了一个简单的类和另一个继承它的类:
public class Adder
{
public virtual int Add(int operand1, int operand2)
{
return operand1 + operand2;
}
}
public class AdvancedAdder : Adder
{
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个检测 LSP 违规的 UnitTest:
public abstract class AdderUnitTestsBase
{
protected static Adder Adder;
[DataTestMethod]
[DataRow(2, 2, 4)]
[DataRow(-1, 2, 1)]
[DataRow(2, -3, -1)]
[DataRow(0, 0, 0)]
public void Add_ReturnsCorrectResult(
int operand1, int operand2, int result)
{
Assert.AreEqual(result, Adder.Add(operand1, operand2));
}
}
[TestClass]
public class AdderUnitTests : AdderUnitTestsBase
{
[ClassInitialize]
public static void ClassInit(TestContext context) …Run Code Online (Sandbox Code Playgroud)