Reputation: 7281
I just noticed that when I change the last line in the code fragment from potential =+ rep_pot
to potential = potential + rep_pot
, I get completely different behaviour. Has anybody got any idea why this is happening?
double potential = euclideanDistance(i, goal);
for (IntPoint h: hits){
double dist = euclideanDistance(i, h);
double a = range - dist;
double rep_pot = (Math.exp(-1/a)) / dist;
potential =+ rep_pot;
}
Upvotes: 0
Views: 87
Reputation: 6095
Yes, because these two things are not equivalent.
potential =+ rep_pot;
Here we have potential assigned a value of the expression 'unary plus rep_pot'
The thing you intendet to write looks differently:
potential += rep_pot;
And this is equivalent to
potential = potential + rep_pot;
Upvotes: 1
Reputation: 13713
You probably meant +=
. In your case it is interpreted as x = +x
which is x = x
Use +=
:
potential += rep_pot;
Upvotes: 1
Reputation: 533880
That is because
potential = potential + rep_pot
is similar to
potential += rep_pot
and
potential =+ rep_pot;
is the same as
potential = rep_pot;
Upvotes: 1
Reputation:
There is no =+
operator in Java. See the Java Language Specification for all legal operators.
=+
are two operators: =
followed by +
.
Upvotes: 1