Ruiqi Dong created MATH-1676:
--------------------------------
Summary: AccurateMathCalc.slowLog() lacks input validation for
documented constraints
Key: MATH-1676
URL: https://issues.apache.org/jira/browse/MATH-1676
Project: Commons Math
Issue Type: Bug
Components: core
Affects Versions: 3.6.1
Reporter: Ruiqi Dong
The slowLog() method documents that parameter 'xi' should be in range [1, 2],
but doesn't validate this constraint. When called with values outside this
range (especially 0 or negative values), it returns mathematically incorrect
results instead of failing fast. The method returns a finite value (~-4.79)
instead of the mathematically correct negative infinity.
Test Case:
@Test
void testSlowLogWithZeroInput()
{ double[] result = AccurateMathCalc.slowLog(0.0);
assertTrue(Double.isInfinite(result[0]) && result[0] < 0); }
Test Result:
[*ERROR*]
org.apache.commons.math4.core.jdkmath.AccurateMathCalcTest.testSlowLogWithZeroInput
– Time elapsed: 0.008 s <<< FAILURE!
org.opentest4j.AssertionFailedError: result[0] should be negative infinity, but
was: -4.791424751281738 ==> expected: <true> but was: <false>
at
org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at
org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:214)
at
org.apache.commons.math4.core.jdkmath.AccurateMathCalcTest.testSlowLogWithZeroInput(AccurateMathCalcTest.java:406)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at java.util.ArrayList.forEach(ArrayList.java:1259)
Suggested improvement:
Add validation to throw IllegalArgumentException for inputs outside [1, 2],
with special handling for xi=0 (return -infinity) and xi<0 (throw exception).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)