展开循环:为什么.NET不能添加1 + 2 + 3 ...? [英] Unwinding a loop: why can't .NET add 1 + 2 + 3 ... ?

查看:69
本文介绍了展开循环:为什么.NET不能添加1 + 2 + 3 ...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

采用一些标准代码,如下所示。它只是循环以添加一个

系列术语,它会产生正确的结果。


//带循环的数字总和

public int DoSumLooping(int iterations)

{

int result = 0;

for(int i = 1; i< =迭代; i ++)

{

结果+ = i;

}

返回结果;

}


现在将其转换为一个不使用循环的特定解决方案(并且

使用相同的迭代次数值循环执行)。这个

代码返回错误的结果。该方法完全由一个非常简单的代码语句组成,但在这种情况下,.NET会错误地添加数字



public double ComputeSum( )

{

//蛮力总和方法

//对于迭代== 10000

double sum = 0+ 1+ 2+ 3+ 4+ 5+ 6+ 7+ 8+ 9+ 10+ 11+ 12+ 13+ 14+ 15+ ...

+ 9997+ 9998+ 9999+ 10000;

返还金额;

}

上述方法返回错误的结果,上面有任意数量的条款

大约200.它将正确添加1 + 2 + ... + 200,但它不会

正确添加1 + 2 + ... + 1000.


我刚碰过这个,我还没有研究这种行为可能导致的原因。它可能是一个已知的问题,无论是堆栈大小还是代码行的长度,但据我所知,它并没有在任何一个中讨论过。 "流行"关于C#和.NET的文献。我需要这样编写

代码,所以如果有人已经遇到过这个问题,请

告诉我。

这是'另一个这个例子也会产生问题,但有点不同的性质。获取以下代码并将其转换为特定的,
非循环方法并尝试使用反射执行它。它失败了。


public double LoopToCompute()

{

double sumOfProducts = 0;

double grandTotal = 0;

for(int i = 0; i< maxRows; ++ i)

{

for(int j = 0; j< maxCols; ++ j)

{

sumOfProducts + = coeff [j] * table [i] [j];

}

a_point [i] = sumOfProducts;

grandTotal + = sumOfProducts;

sumOfProducts = 0;

}

返回grandTotal;

} // LoopToCompute


以上代码有效 - 但它相当于展开循环的代码(显示

以下)不起作用,除非maxRows设置得非常小。对于较小的值,

2种方法(上方和下方)产生相同的结果。什么都没有

错误在这个意义上的代码。它与上述情况类似。如果

则为大小。代码语句或代码语句的数量太多了,b $ b大,.NET失败了。在这种情况下(使用反射)它不会返回

不正确的结果,如第一个例子所做的那样。在这种情况下,反射调用

它是一个无效的程序并拒绝运行它(但只有当

maxRows的值大于250时)。原因可能是直接的b $ b。但是,由于性能原因,我需要做出这样的声明,所以我需要一个解决方法。任何建议都是值得赞赏的!所有评论都表示赞赏。


公开双倍DoBruteForceCompute()

{

double bruteForceSum = 0;


point1 = coeff1 * table [0] [0] + coeff2 * table [0] [1] + coeff3 * table [0] [2]

+ coeff4 * table [ 0] [3] + coeff5 * table [0] [4] + coeff6 * table [0] [5]

+ coeff7 * table [0] [6] + coeff8 * table [0] [7] + coeff9 * table [0] [8]

+ coeff10 * table [0] [9] + coeff11 * table [0] [10] + coeff12 * table [0] [11 ]

+ coeff13 * table [0] [12] + coeff14 * table [0] [13] + coeff15 * table [0] [14]

+ coeff16 * table [0] [15] + coeff17 * table [0] [16] + coeff18 * table [0] [17]

+ coeff19 * table [0] [18] + coeff20 * table [ 0] [19] + coeff21 * table [0] [20]

+ coeff22 * table [0] [21] + coeff23 * table [0] [22] + coeff24 * table [0] [23]

+ coeff25 * table [0] [24] + coeff26 * table [0] [25] + coeff27 * table [0] [26]

+ coeff28 * table [0] [27] + coeff29 * table [0] [28] + coeff30 * table [0] [29]

+ coeff31 * table [0] [30] + coeff32 *表[0] [31] + coeff33 *表[0] [32]

+ coeff34 *表[0] [33] + coeff35 * table [0] [34];


point2 = coeff1 * table [1] [0] + coeff2 * table [1] [1] + coeff3 *表[1] [2]

+ coeff4 *表[1] [3] + coeff5 *表[1] [4] + coeff6 *表[1] [5]

+ coeff7 * table [1] [6] + coeff8 * table [1] [7] + coeff9 * table [1] [8]

+ coeff10 * table [1 ] [9] + coeff11 *表[1] [10] + coeff12 *表[1] [11]

+ coeff13 *表[1] [12] + coeff14 *表[1] [ 13] + coeff15 *表[1] [14]

+ coeff16 *表[1] [15] + coeff17 *表[1] [16] + coeff18 *表[1] [17]

+ coeff19 *表[1] [18] + coeff20 *表[1] [19] + coeff21 *表[1] [20]

+ coeff22 *表[1] [21] + coeff23 *表[1] [22] + coeff24 *表[1] [23]

+ coeff25 *表[1] [24] + coeff26 *表[1 ] [25] + coeff27 *表[1] [26]

+ coeff28 *表[1] [27] + coeff29 *表[1] [28] + coeff30 *表[1] [ 29]

+ coeff31 *表[1] [30] + coeff32 *表[1] [31] + coeff33 *表[1] [32]

+ coeff34 * table [1] [33] + coeff35 * table [1] [34];

[...]


point500 = coeff1 * table [ 499] [0] + coef f2 * table [499] [1] + coeff3 * table [499] [2]

+ coeff4 * table [499] [3] + coeff5 * table [499] [4] + coeff6 *表[499] [5]

+ coeff7 *表[499] [6] + coeff8 *表[499] [7] + coeff9 *表[499] [8]

+ coeff10 * table [499] [9] + coeff11 * table [499] [10] + coeff12 * table [499] [11]

+ coeff13 * table [499] [12 ] + coeff14 *表[499] [13] + coeff15 *表[499] [14]

+ coeff16 *表[499] [15] + coeff17 *表[499] [16] + coeff18 *表[499] [17]

+ coeff19 *表[499] [18] + coeff20 *表[499] [19] + coeff21 *表[499] [20]
+ coeff22 * table [499] [21] + coeff23 * table [499] [22] + coeff24 * table [499] [23]

+ coeff25 * table [499] [24] + coeff26 * table [499] [25] + coeff27 * table [499] [26]

+ coeff28 * table [499] [27] + coeff29 * table [499] [28 ] + coeff30 *表[499] [29]

+ coeff31 *表[499] [30] + coeff32 *表[499] [31] + coeff33 *表[499] [32]

+ coeff34 *表[499] [33] + coeff35 *表[499] [34];


bruteForceSum =

point1 +

point2 + ... +


point499 +

point500

;


返回bruteForceSum;


} // DoBruteForceCompute

解决方案

您可以使用不同类型的变量作为结果。


结果是* int *

//带循环的数字总和
public int DoSumLooping(int iterations)
{
int result = 0;
for(int i = 1; i< = iterations; i ++)
{
结果+ = i;
}
返回结果;
}
public double ComputeSum()
// Brute force sum方法
//对于迭代== 10000
double sum = 0+ 1+ 2+ 3+ 4 + 5+ 6+ 7+ 8+ 9+ 10+ 11+ 12+ 13+ 14+ 15+
.... + 9997+ 9998+ 9999+ 10000;
返还金额;
}




结果是* double *


这可能是不同结果的原因吗?


B \ rgds



我刚做过使用200个硬编码的int,然后是390,然后是300.每次

我得到了正确的结果。你对输入数字是肯定的吗?我知道

这是一个愚蠢的问题,但我首先将每个加载到一个

Int数组并添加它们。有效。然后我实际上使用了

直接硬编码,我每次使用数字10并且添加100000到

最后一个用于好的测量(只是为了确保值I曾经是

同样很高)。没有任何问题。因为你可以在数组中加载那些

值并成功迭代它,你不能只加载

数组并使用迭代方法吗?我明白'你是什么?

询问......你为什么要这样做,但它可能比

更容易验证数学你知道它会起作用的时间。如果我能找到

的话,我会转发。


HTH,


Bill

Mountain Bikn''Guy < vc@attbi.com>在消息中写道

news:NZUjb.795942


YN5.793228@sccrnsc01 ...

取一些标准代码如显示下面。它只是循环以添加一系列术语,并产生正确的结果。
//用循环求和数
public int DoSumLooping(int iterations)
{
int result = 0;
for(int i = 1; i< = iterations; i ++)
{
结果+ = i;
} <返回结果;

现在将其转换为一个不使用循环的特定解决方案(并且对循环的迭代次数使用相同的值)施行)。此
代码返回不正确的结果。该方法完全由一个非常直接的代码语句组成,但在这种情况下.NET不正确地添加数字。
public double ComputeSum()
//
//强力求和方法
//对于迭代== 10000
双和= 0+ 1+ 2+ 3+ 4+ 5+ 6+ 7+ 8+ 9+ 10+ 11+ 12+ 13+ 14+ 15+
.... + 9997+ 9998+ 9999+ 10000;
返回总和;
}
上述方法返回不正确的结果,任意数量的术语
大约200以上。它会正确添加1 + 2 + ... + 200,但它不会正确添加1 + 2 + ... + 1000.

我刚刚遇到这个,我还没有研究这种行为的可能原因。它可能是与堆栈大小或代码行长度有关的已知问题,但据我所知,它并未在任何流行的内容中讨论过。关于C#和.NET的文献。我需要
写这样的代码,所以如果有人已经遇到过这个问题,请告诉我。

这里是另一个也会产生问题的例子,但是有点不同的性质。获取以下代码并将其转换为
特定的非循环方法,并尝试使用反射执行它。它失败了。

public double LoopToCompute()
{double sumOfProducts = 0;
double grandTotal = 0;
for(int i = 0; i< maxRows; ++ i)
{
for(int j = 0; j< maxCols; ++ j)
{
sumOfProducts + = coeff [j] * table [i] [j];
}
a_point [i] = sumOfProducts;
grandTotal + = sumOfProducts;
sumOfProducts = 0;
}
return grandTotal;
} // LoopToCompute

以上代码有效 - 但它是等效的代码,循环展开
(如下所示)不起作用,除非maxRows设置得非常小。对于小的
值,2种方法(上方和下方)产生相同的结果。有
没有错误在这个意义上的代码。它与上述情况类似。
如果是大小,代码语句或代码语句的数量太大,.NET失败。在这种情况下(使用反射)它不会返回
不正确的结果,如第一个例子所做的那样。在这种情况下,反射调用它是一个无效的程序并拒绝运行它(但只有当
maxRows的值高于约250时)。原因可能是直截了当的。但是,出于性能原因,我需要做出这样的声明,所以我需要一个解决方法。任何建议都表示赞赏!所有评论都表示赞赏。

公共双DoBruteForceCompute()
{bruteForceSum = 0;

point1 = coeff1 * table [0] [0 ] + coeff2 * table [0] [1] + coeff3 * table [0] [2]
+ coeff4 * table [0] [3] + coeff5 * table [0] [4] + coeff6 * table [ 0] [5]
+ coeff7 * table [0] [6] + coeff8 * table [0] [7] + coeff9 * table [0] [8]
+ coeff10 * table [0] [9] + coeff11 *表[0] [10] + coeff12 *表[0] [11]
+ coeff13 *表[0] [12] + coeff14 *表[0] [13] + coeff15 *表[0] [14]
+ coeff16 *表[0] [15] + coeff17 *表[0] [16] + coeff18 *表[0] [17]
+ coeff19 *表[ 0] [18] + coeff20 * table [0] [19] + coeff21 * table [0] [20]
+ coeff22 * table [0] [21] + coeff23 * table [0] [22] + coeff24 * table [0] [23]
+ coeff25 * table [0] [24] + coeff26 * table [0] [25] + coeff27 * table [0] [26]
+ coeff28 * table [0] [27] + coeff29 * table [0] [28] + coeff30 * table [0] [29]
+ coeff31 * table [0] [30] + coeff32 * table [0] [31 ] + coeff33 *表[0] [32]
+ coeff34 *表[0] [33] + coeff35 *表[0] [34];

point2 = coeff1 *表[ 1] [0] + coe ff2 *表[1] [1] + coeff3 *表[1] [2]
+ coeff4 *表[1] [3] + coeff5 *表[1] [4] + coeff6 *表[1] [5]
+ coeff7 * table [1] [6] + coeff8 * table [1] [7] + coeff9 * table [1] [8]
+ coeff10 * table [1] [9 ] + coeff11 *表[1] [10] + coeff12 *表[1] [11]
+ coeff13 *表[1] [12] + coeff14 *表[1] [13] + coeff15 *表[ 1] [14]
+ coeff16 *表[1] [15] + coeff17 *表[1] [16] + coeff18 *表[1] [17]
+ coeff19 *表[1] [18] + coeff20 *表[1] [19] + coeff21 *表[1] [20]
+ coeff22 *表[1] [21] + coeff23 *表[1] [22] + coeff24 *表[1] [23]
+ coeff25 *表[1] [24] + coeff26 *表[1] [25] + coeff27 *表[1] [26]
+ coeff28 *表[ 1] [27] + coeff29 *表[1] [28] + coeff30 *表[1] [29]
+ coeff31 *表[1] [30] + coeff32 *表[1] [31] + coeff33 *表[1] [32]
+ coeff34 *表[1] [33] + coeff35 *表[1] [34];

[...]

point500 = coeff1 *表[499] [0] + coeff2 *表[499] [1] + coeff3 *表[499] [2]
+ coeff4 *表[499] [3] + coeff5 * table [499] [4] + coeff6 * table [499] [5]
+ coeff7 * table [499] [6] + coeff8 * table [499] [7] + coeff9 * table [499] [8]
+ coeff10 * table [499] [9] + coeff11 * table [499] [10] + coeff12 * table [499] ] [11]
+ coeff13 *表[499] [12] + coeff14 *表[499] [13] + coeff15 *表[499] [14]
+ coeff16 *表[499] [ 15] + coeff17 *表[499] [16] + coeff18 *表[499] [17]
+ coeff19 *表[499] [18] + coeff20 *表[499] [19] + coeff21 *表[499] [20]
+ coeff22 *表[499] [21] + coeff23 *表[499] [22] + coeff24 *表[499] [23]
+ coeff25 *表[499] ] [24] + coeff26 *表[499] [25] + coeff27 *表[499] [26]
+ coeff28 *表[499] [27] + coeff29 *表[499] [28] + coeff30 *表[499] [29]
+ coeff31 *表[499] [30] + coeff32 *表[499] [31] + coeff33 *表[499] [32]
+ coeff34 *表[499] [33] + coeff35 *表[499] [34];

bruteForceSum =
point1 +
point2 + ... +
point499
point500
;

返回bruteForceSum;

} // DoBruteForceCompute



Take some standard code such as shown below. It simply loops to add up a
series of terms and it produces the correct result.

// sum numbers with a loop
public int DoSumLooping(int iterations)
{
int result = 0;
for(int i = 1;i <=iterations;i++)
{
result += i;
}
return result;
}

Now translate this into a specific solution that doesn''t use looping (and
use the same value for the number of iterations the loop performs). This
code returns an incorrect result. The method consists entirely of a very
straightforward code statement, but in this case .NET adds the numbers
incorrectly.
public double ComputeSum( )
{
// Brute force sum method
// For iterations == 10000
double sum = 0+ 1+ 2+ 3+ 4+ 5+ 6+ 7+ 8+ 9+ 10+ 11+ 12+ 13+ 14+ 15+ ...
+ 9997+ 9998+ 9999+ 10000;
return sum;
}
The above method returns an incorrect result with any number of terms above
about 200. It will correctly add 1 + 2 + ... + 200, but it will NOT
correctly add 1 + 2 + ... + 1000.

I have just run across this, and I have not yet researched the possible
reasons for this behavior. It may be a known issue related to either stack
size or the length of a code line, but to my knowledge it hasn''t been
discussed in any of the "popular" literature on C# and .NET. I need to write
code like this, so if anyone has already encountered this issue, please
advise me.
Here''s another example that also creates problems, but of a somewhat
different nature. Take the following code and translate it into a specific,
non-looping method and try to execute it using reflection. It fails.

public double LoopToCompute()
{
double sumOfProducts = 0;
double grandTotal = 0;
for (int i = 0; i < maxRows; ++i)
{
for (int j = 0; j < maxCols; ++j)
{
sumOfProducts += coeff[j] * table[i][j];
}
a_point[i] = sumOfProducts;
grandTotal += sumOfProducts;
sumOfProducts = 0;
}
return grandTotal;
}//LoopToCompute

The above code works -- but it''s equivalent code with loops unrolled (shown
below) doesn''t work unless the maxRows is set very small. For small values,
the 2 methods (above and below) produce identical results. There is nothing
"wrong" with the code in that sense. It''s similar to the above situation. If
the "size" of the code statement or the number of code statements is too
large, .NET fails. In this case (using reflection) it doesn''t return the
incorrect result, as the first example did. In this case, reflection calls
it an invalid program and refuses to run it (but only when the value of
maxRows is above about 250). The reason for this is probably
straightforward. However, I have the need to make statements like this for
performance reasons so I need a work-around. Any suggestions are
appreciated! All comments are appreciated.

public double DoBruteForceCompute()
{
double bruteForceSum = 0;

point1=coeff1*table[0][0] +coeff2*table[0][1] +coeff3*table[0][2]
+coeff4*table[0][3] +coeff5*table[0][4] +coeff6*table[0][5]
+coeff7*table[0][6] +coeff8*table[0][7] +coeff9*table[0][8]
+coeff10*table[0][9] +coeff11*table[0][10] +coeff12*table[0][11]
+coeff13*table[0][12] +coeff14*table[0][13] +coeff15*table[0][14]
+coeff16*table[0][15] +coeff17*table[0][16] +coeff18*table[0][17]
+coeff19*table[0][18] +coeff20*table[0][19] +coeff21*table[0][20]
+coeff22*table[0][21] +coeff23*table[0][22] +coeff24*table[0][23]
+coeff25*table[0][24] +coeff26*table[0][25] +coeff27*table[0][26]
+coeff28*table[0][27] +coeff29*table[0][28] +coeff30*table[0][29]
+coeff31*table[0][30] +coeff32*table[0][31] +coeff33*table[0][32]
+coeff34*table[0][33] +coeff35*table[0][34] ;

point2=coeff1*table[1][0] +coeff2*table[1][1] +coeff3*table[1][2]
+coeff4*table[1][3] +coeff5*table[1][4] +coeff6*table[1][5]
+coeff7*table[1][6] +coeff8*table[1][7] +coeff9*table[1][8]
+coeff10*table[1][9] +coeff11*table[1][10] +coeff12*table[1][11]
+coeff13*table[1][12] +coeff14*table[1][13] +coeff15*table[1][14]
+coeff16*table[1][15] +coeff17*table[1][16] +coeff18*table[1][17]
+coeff19*table[1][18] +coeff20*table[1][19] +coeff21*table[1][20]
+coeff22*table[1][21] +coeff23*table[1][22] +coeff24*table[1][23]
+coeff25*table[1][24] +coeff26*table[1][25] +coeff27*table[1][26]
+coeff28*table[1][27] +coeff29*table[1][28] +coeff30*table[1][29]
+coeff31*table[1][30] +coeff32*table[1][31] +coeff33*table[1][32]
+coeff34*table[1][33] +coeff35*table[1][34] ;
[...]

point500=coeff1*table[499][0] +coeff2*table[499][1] +coeff3*table[499][2]
+coeff4*table[499][3] +coeff5*table[499][4] +coeff6*table[499][5]
+coeff7*table[499][6] +coeff8*table[499][7] +coeff9*table[499][8]
+coeff10*table[499][9] +coeff11*table[499][10] +coeff12*table[499][11]
+coeff13*table[499][12] +coeff14*table[499][13] +coeff15*table[499][14]
+coeff16*table[499][15] +coeff17*table[499][16] +coeff18*table[499][17]
+coeff19*table[499][18] +coeff20*table[499][19] +coeff21*table[499][20]
+coeff22*table[499][21] +coeff23*table[499][22] +coeff24*table[499][23]
+coeff25*table[499][24] +coeff26*table[499][25] +coeff27*table[499][26]
+coeff28*table[499][27] +coeff29*table[499][28] +coeff30*table[499][29]
+coeff31*table[499][30] +coeff32*table[499][31] +coeff33*table[499][32]
+coeff34*table[499][33] +coeff35*table[499][34] ;

bruteForceSum =
point1 +
point2 + ... +

point499 +
point500
;

return bruteForceSum;

}//DoBruteForceCompute

解决方案

You use variables of diferent type for the result.

result is *int*

// sum numbers with a loop
public int DoSumLooping(int iterations)
{
int result = 0;
for(int i = 1;i <=iterations;i++)
{
result += i;
}
return result;
} public double ComputeSum( )
{
// Brute force sum method
// For iterations == 10000
double sum = 0+ 1+ 2+ 3+ 4+ 5+ 6+ 7+ 8+ 9+ 10+ 11+ 12+ 13+ 14+ 15+ .... + 9997+ 9998+ 9999+ 10000;
return sum;
}



result is *double*

Can it be de reason for the different results?

B\rgds
100


I just did it going with 200 Hard coded ints, then 390, then 300. Each time
I got the correct results. Are you positive of the input numbers? I know
that''s a stupid question, but I first did each one by loading them into an
Int Array and adding them like that. It worked. Then I actually used
straight hard coding, and I used the number 10 each time and added 100000 to
the last one for good measure (just to make sure the value I had was
similarly high). No problems whatsoever. Inasmuch as you can load those
values in an array and iterate it successfully, couldn''t you just load the
array and use an iterative approach? I understand that''s what you are
asking about...why should you have to do this, but it''s probably easier than
verifying the math each time when you know it will work. If I can find
anything, I''ll repost.

HTH,

Bill
"Mountain Bikn'' Guy" <vc@attbi.com> wrote in message
news:NZUjb.795942


YN5.793228@sccrnsc01...

Take some standard code such as shown below. It simply loops to add up a
series of terms and it produces the correct result.

// sum numbers with a loop
public int DoSumLooping(int iterations)
{
int result = 0;
for(int i = 1;i <=iterations;i++)
{
result += i;
}
return result;
}

Now translate this into a specific solution that doesn''t use looping (and
use the same value for the number of iterations the loop performs). This
code returns an incorrect result. The method consists entirely of a very
straightforward code statement, but in this case .NET adds the numbers
incorrectly.
public double ComputeSum( )
{
// Brute force sum method
// For iterations == 10000
double sum = 0+ 1+ 2+ 3+ 4+ 5+ 6+ 7+ 8+ 9+ 10+ 11+ 12+ 13+ 14+ 15+ .... + 9997+ 9998+ 9999+ 10000;
return sum;
}
The above method returns an incorrect result with any number of terms above about 200. It will correctly add 1 + 2 + ... + 200, but it will NOT
correctly add 1 + 2 + ... + 1000.

I have just run across this, and I have not yet researched the possible
reasons for this behavior. It may be a known issue related to either stack
size or the length of a code line, but to my knowledge it hasn''t been
discussed in any of the "popular" literature on C# and .NET. I need to write code like this, so if anyone has already encountered this issue, please
advise me.
Here''s another example that also creates problems, but of a somewhat
different nature. Take the following code and translate it into a specific, non-looping method and try to execute it using reflection. It fails.

public double LoopToCompute()
{
double sumOfProducts = 0;
double grandTotal = 0;
for (int i = 0; i < maxRows; ++i)
{
for (int j = 0; j < maxCols; ++j)
{
sumOfProducts += coeff[j] * table[i][j];
}
a_point[i] = sumOfProducts;
grandTotal += sumOfProducts;
sumOfProducts = 0;
}
return grandTotal;
}//LoopToCompute

The above code works -- but it''s equivalent code with loops unrolled (shown below) doesn''t work unless the maxRows is set very small. For small values, the 2 methods (above and below) produce identical results. There is nothing "wrong" with the code in that sense. It''s similar to the above situation. If the "size" of the code statement or the number of code statements is too
large, .NET fails. In this case (using reflection) it doesn''t return the
incorrect result, as the first example did. In this case, reflection calls
it an invalid program and refuses to run it (but only when the value of
maxRows is above about 250). The reason for this is probably
straightforward. However, I have the need to make statements like this for
performance reasons so I need a work-around. Any suggestions are
appreciated! All comments are appreciated.

public double DoBruteForceCompute()
{
double bruteForceSum = 0;

point1=coeff1*table[0][0] +coeff2*table[0][1] +coeff3*table[0][2]
+coeff4*table[0][3] +coeff5*table[0][4] +coeff6*table[0][5]
+coeff7*table[0][6] +coeff8*table[0][7] +coeff9*table[0][8]
+coeff10*table[0][9] +coeff11*table[0][10] +coeff12*table[0][11]
+coeff13*table[0][12] +coeff14*table[0][13] +coeff15*table[0][14]
+coeff16*table[0][15] +coeff17*table[0][16] +coeff18*table[0][17]
+coeff19*table[0][18] +coeff20*table[0][19] +coeff21*table[0][20]
+coeff22*table[0][21] +coeff23*table[0][22] +coeff24*table[0][23]
+coeff25*table[0][24] +coeff26*table[0][25] +coeff27*table[0][26]
+coeff28*table[0][27] +coeff29*table[0][28] +coeff30*table[0][29]
+coeff31*table[0][30] +coeff32*table[0][31] +coeff33*table[0][32]
+coeff34*table[0][33] +coeff35*table[0][34] ;

point2=coeff1*table[1][0] +coeff2*table[1][1] +coeff3*table[1][2]
+coeff4*table[1][3] +coeff5*table[1][4] +coeff6*table[1][5]
+coeff7*table[1][6] +coeff8*table[1][7] +coeff9*table[1][8]
+coeff10*table[1][9] +coeff11*table[1][10] +coeff12*table[1][11]
+coeff13*table[1][12] +coeff14*table[1][13] +coeff15*table[1][14]
+coeff16*table[1][15] +coeff17*table[1][16] +coeff18*table[1][17]
+coeff19*table[1][18] +coeff20*table[1][19] +coeff21*table[1][20]
+coeff22*table[1][21] +coeff23*table[1][22] +coeff24*table[1][23]
+coeff25*table[1][24] +coeff26*table[1][25] +coeff27*table[1][26]
+coeff28*table[1][27] +coeff29*table[1][28] +coeff30*table[1][29]
+coeff31*table[1][30] +coeff32*table[1][31] +coeff33*table[1][32]
+coeff34*table[1][33] +coeff35*table[1][34] ;
[...]

point500=coeff1*table[499][0] +coeff2*table[499][1] +coeff3*table[499][2]
+coeff4*table[499][3] +coeff5*table[499][4] +coeff6*table[499][5]
+coeff7*table[499][6] +coeff8*table[499][7] +coeff9*table[499][8]
+coeff10*table[499][9] +coeff11*table[499][10] +coeff12*table[499][11]
+coeff13*table[499][12] +coeff14*table[499][13] +coeff15*table[499][14]
+coeff16*table[499][15] +coeff17*table[499][16] +coeff18*table[499][17]
+coeff19*table[499][18] +coeff20*table[499][19] +coeff21*table[499][20]
+coeff22*table[499][21] +coeff23*table[499][22] +coeff24*table[499][23]
+coeff25*table[499][24] +coeff26*table[499][25] +coeff27*table[499][26]
+coeff28*table[499][27] +coeff29*table[499][28] +coeff30*table[499][29]
+coeff31*table[499][30] +coeff32*table[499][31] +coeff33*table[499][32]
+coeff34*table[499][33] +coeff35*table[499][34] ;

bruteForceSum =
point1 +
point2 + ... +

point499 +
point500
;

return bruteForceSum;

}//DoBruteForceCompute



这篇关于展开循环:为什么.NET不能添加1 + 2 + 3 ...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆