H
haley
i am using java 6 sdk. I write a program like below:
public static void main(String[] args) {
double weight[][] = {
{ 0.0, 1.0, -3.0, 2.0, -0.3, -2.1, -1.0},
{ 1.0, 0.0, 1.0, 1.0, 3.0, -4.0, 0.0},
{-3.0, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0},
{ 2.0, 1.0, 0.0, 0.0, 0.0, -2.4, 3.3},
{-0.3, 3.0, 1.0, 0.0, 0.0, 1.0, 1.0},
{-2.1, -4.0, -1.0, -2.4, 1.0, 0.0, -1.0},
{ 1.0, 0.0, -1.0, 3.3, 1.0, -1.0, 0.0}
};
double input[] = {1.000000 ,-1.000000 ,1.000000 ,-1.000000 ,1.000000
,-1.000000 ,1.000000};
double sum = 0.0;
double temp;
for (int i = 0; i < 7; i++ ){
sum = 0.0;
for (int j = 0; j < 7; j++ ){
temp = weight[j] * input[j];
sum += temp;
System.out.println(temp);
}
System.out.println("\nsum " + i + " = " + sum);
}
}
The output i get is this:
0.0
-1.0
-3.0
-2.0
-0.3
2.1
-1.0
sum 0 = -5.199999999999999
1.0
-0.0
1.0
-1.0
3.0
4.0
0.0
sum 1 = 8.0
-3.0
-1.0
0.0
-0.0
1.0
1.0
-1.0
sum 2 = -3.0
2.0
-1.0
0.0
-0.0
0.0
2.4
3.3
sum 3 = 6.699999999999999
-0.3
-3.0
1.0
-0.0
0.0
-1.0
1.0
sum 4 = -2.3
-2.1
4.0
-1.0
2.4
1.0
-0.0
-1.0
sum 5 = 3.3
1.0
-0.0
-1.0
-3.3
1.0
1.0
0.0
sum 6 = -1.2999999999999998
Why this happen?
why sumation of
1.0
-0.0
-1.0
-3.3
1.0
1.0
0.0
= -1.2999999999999998
this is definitely not correct!!!!
the answer should be -1.30000000000000
public static void main(String[] args) {
double weight[][] = {
{ 0.0, 1.0, -3.0, 2.0, -0.3, -2.1, -1.0},
{ 1.0, 0.0, 1.0, 1.0, 3.0, -4.0, 0.0},
{-3.0, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0},
{ 2.0, 1.0, 0.0, 0.0, 0.0, -2.4, 3.3},
{-0.3, 3.0, 1.0, 0.0, 0.0, 1.0, 1.0},
{-2.1, -4.0, -1.0, -2.4, 1.0, 0.0, -1.0},
{ 1.0, 0.0, -1.0, 3.3, 1.0, -1.0, 0.0}
};
double input[] = {1.000000 ,-1.000000 ,1.000000 ,-1.000000 ,1.000000
,-1.000000 ,1.000000};
double sum = 0.0;
double temp;
for (int i = 0; i < 7; i++ ){
sum = 0.0;
for (int j = 0; j < 7; j++ ){
temp = weight[j] * input[j];
sum += temp;
System.out.println(temp);
}
System.out.println("\nsum " + i + " = " + sum);
}
}
The output i get is this:
0.0
-1.0
-3.0
-2.0
-0.3
2.1
-1.0
sum 0 = -5.199999999999999
1.0
-0.0
1.0
-1.0
3.0
4.0
0.0
sum 1 = 8.0
-3.0
-1.0
0.0
-0.0
1.0
1.0
-1.0
sum 2 = -3.0
2.0
-1.0
0.0
-0.0
0.0
2.4
3.3
sum 3 = 6.699999999999999
-0.3
-3.0
1.0
-0.0
0.0
-1.0
1.0
sum 4 = -2.3
-2.1
4.0
-1.0
2.4
1.0
-0.0
-1.0
sum 5 = 3.3
1.0
-0.0
-1.0
-3.3
1.0
1.0
0.0
sum 6 = -1.2999999999999998
Why this happen?
why sumation of
1.0
-0.0
-1.0
-3.3
1.0
1.0
0.0
= -1.2999999999999998
this is definitely not correct!!!!
the answer should be -1.30000000000000