Fix DerivativeStructure.pow for 0 argument and power less than 1.

This commit is contained in:
Luc Maisonobe 2016-08-05 15:05:33 +02:00 committed by Emmanuel Bourg
parent c64856ff7f
commit 540564e190
2 changed files with 18 additions and 0 deletions

View File

@ -893,6 +893,12 @@ public class DSCompiler {
return;
}
if (operand[operandOffset] == 0) {
// special case, 0^p = 0 for all p
Arrays.fill(result, resultOffset, resultOffset + getSize(), 0);
return;
}
// create the function value and derivatives
// [x^p, px^(p-1), p(p-1)x^(p-2), ... ]
double[] function = new double[1 + order];

View File

@ -345,6 +345,18 @@ public class DerivativeStructureTest extends ExtendedFieldElementAbstractTest<De
Assert.assertEquals(0.0, d, Precision.SAFE_MIN);
}
}
// 0^p with p smaller than 1.0
DerivativeStructure u = new DerivativeStructure(3, maxOrder, 1, -0.0).pow(0.25);
for (int i0 = 0; i0 <= maxOrder; ++i0) {
for (int i1 = 0; i1 <= maxOrder; ++i1) {
for (int i2 = 0; i2 <= maxOrder; ++i2) {
if (i0 + i1 + i2 <= maxOrder) {
Assert.assertEquals(0.0, u.getPartialDerivative(i0, i1, i2), 1.0e-10);
}
}
}
}
}
}