You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/11/10 15:43:44 UTC
svn commit: r1200350 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
Author: sebb
Date: Thu Nov 10 14:43:44 2011
New Revision: 1200350
URL: http://svn.apache.org/viewvc?rev=1200350&view=rev
Log:
Unnecessary casts - angbd is double, so ensures the rest of the calculation uses double
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java?rev=1200350&r1=1200349&r2=1200350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java Thu Nov 10 14:43:44 2011
@@ -2149,7 +2149,7 @@ public class BOBYQAOptimizer
redsav = ZERO;
iu = (int) (angbd * 17. + 3.1);
for (int i = 0; i < iu; i++) {
- angt = angbd * (double) i / (double) iu;
+ angt = angbd * i / iu;
sth = (angt + angt) / (ONE + angt * angt);
temp = shs + angt * (angt * dhd - dhs - dhs);
rednew = sth * (angt * dredg - sredg - HALF * sth * temp);
@@ -2171,7 +2171,7 @@ public class BOBYQAOptimizer
}
if (isav < iu) {
temp = (rdnext - rdprev) / (redmax + redmax - rdprev - rdnext);
- angt = angbd * ((double) isav + HALF * temp) / (double) iu;
+ angt = angbd * (isav + HALF * temp) / iu;
}
cth = (ONE - angt * angt) / (ONE + angt * angt);
sth = (angt + angt) / (ONE + angt * angt);
Re: svn commit: r1200350 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
Posted by sebb <se...@gmail.com>.
On 10 November 2011 17:15, Luc Maisonobe <Lu...@free.fr> wrote:
> Le 10/11/2011 15:43, sebb@apache.org a écrit :
>> Author: sebb
>> Date: Thu Nov 10 14:43:44 2011
>> New Revision: 1200350
>>
>> URL: http://svn.apache.org/viewvc?rev=1200350&view=rev
>> Log:
>> Unnecessary casts - angbd is double, so ensures the rest of the calculation uses double
>>
>> Modified:
>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
>>
>> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
>> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java?rev=1200350&r1=1200349&r2=1200350&view=diff
>> ==============================================================================
>> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java (original)
>> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java Thu Nov 10 14:43:44 2011
>> @@ -2149,7 +2149,7 @@ public class BOBYQAOptimizer
>> redsav = ZERO;
>> iu = (int) (angbd * 17. + 3.1);
>> for (int i = 0; i < iu; i++) {
>> - angt = angbd * (double) i / (double) iu;
>> + angt = angbd * i / iu;
>
> I'm not sure about this. It depends on how the compiler performs
> associativity.
>
> This multiplication can be compiled either as
> (angbd * i) / iu
> or as
> angbd * (i / iu)
>
> In the later case, the integer division is wrong.
http://introcs.cs.princeton.edu/java/11precedence/
says * and / have equal precedence, so * is done first.
> Luv
>
>
>> sth = (angt + angt) / (ONE + angt * angt);
>> temp = shs + angt * (angt * dhd - dhs - dhs);
>> rednew = sth * (angt * dredg - sredg - HALF * sth * temp);
>> @@ -2171,7 +2171,7 @@ public class BOBYQAOptimizer
>> }
>> if (isav < iu) {
>> temp = (rdnext - rdprev) / (redmax + redmax - rdprev - rdnext);
>> - angt = angbd * ((double) isav + HALF * temp) / (double) iu;
>> + angt = angbd * (isav + HALF * temp) / iu;
>> }
>> cth = (ONE - angt * angt) / (ONE + angt * angt);
>> sth = (angt + angt) / (ONE + angt * angt);
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1200350 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
Posted by Luc Maisonobe <Lu...@free.fr>.
Le 10/11/2011 15:43, sebb@apache.org a écrit :
> Author: sebb
> Date: Thu Nov 10 14:43:44 2011
> New Revision: 1200350
>
> URL: http://svn.apache.org/viewvc?rev=1200350&view=rev
> Log:
> Unnecessary casts - angbd is double, so ensures the rest of the calculation uses double
>
> Modified:
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
>
> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java?rev=1200350&r1=1200349&r2=1200350&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java (original)
> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BOBYQAOptimizer.java Thu Nov 10 14:43:44 2011
> @@ -2149,7 +2149,7 @@ public class BOBYQAOptimizer
> redsav = ZERO;
> iu = (int) (angbd * 17. + 3.1);
> for (int i = 0; i < iu; i++) {
> - angt = angbd * (double) i / (double) iu;
> + angt = angbd * i / iu;
I'm not sure about this. It depends on how the compiler performs
associativity. This multiplication can be compiled either as
(angbd * i) / iu
or as
angbd * (i / iu)
In the later case, the integer division is wrong.
Luv
> sth = (angt + angt) / (ONE + angt * angt);
> temp = shs + angt * (angt * dhd - dhs - dhs);
> rednew = sth * (angt * dredg - sredg - HALF * sth * temp);
> @@ -2171,7 +2171,7 @@ public class BOBYQAOptimizer
> }
> if (isav < iu) {
> temp = (rdnext - rdprev) / (redmax + redmax - rdprev - rdnext);
> - angt = angbd * ((double) isav + HALF * temp) / (double) iu;
> + angt = angbd * (isav + HALF * temp) / iu;
> }
> cth = (ONE - angt * angt) / (ONE + angt * angt);
> sth = (angt + angt) / (ONE + angt * angt);
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org