Bug 62040 - Quotient.evaluate function does not accept cell refences
Summary: Quotient.evaluate function does not accept cell refences
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 3.17-FINAL
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-23 21:02 UTC by cquezel
Modified: 2021-10-10 11:22 UTC (History)
1 user (show)



Attachments
Modifications to Quotient.java and QuotientFunctionTestCaseData.xls (4.91 KB, patch)
2019-04-16 18:02 UTC, Ian Giguère
Details | Diff
Edited Excel file: QuotientFunctionTestCaseData.xls (1.40 KB, text/x-java)
2019-04-16 18:03 UTC, Ian Giguère
Details
Modifications to Quotient.java to support cell references (2.85 KB, text/x-java)
2019-04-16 18:05 UTC, Ian Giguère
Details

Note You need to log in before you can comment on or make changes to this bug.
Description cquezel 2018-01-23 21:02:13 UTC
I think adding OperandResolver.getSingleValue for the numerator and denominator might solvce the problem.


    @Override
	public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval venumerator, ValueEval vedenominator) {

        double enumerator = 0;
        try {
			ValueEval ve = OperandResolver.getSingleValue(venumerator, srcRowIndex, srcColumnIndex); // added this line
            enumerator = OperandResolver.coerceValueToDouble(ve);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }

        double denominator = 0;
        try {
			ValueEval ve = OperandResolver.getSingleValue(vedenominator, srcRowIndex, srcColumnIndex); // added this line
            denominator = OperandResolver.coerceValueToDouble(ve);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }

        if (denominator == 0) {
            return ErrorEval.DIV_ZERO;
        }

        return new NumberEval((int)(enumerator / denominator));
    }
Comment 1 Dominik Stadler 2018-02-08 19:41:34 UTC
Do you have a code-sample that shows the problem? Ideally a self-standing unit-test? Would make it much easier to reproduce and ensure it stays fixed in the future.
Comment 2 cquezel 2018-02-08 22:03:47 UTC
(In reply to Dominik Stadler from comment #1)
> Do you have a code-sample that shows the problem? Ideally a self-standing
> unit-test? Would make it much easier to reproduce and ensure it stays fixed
> in the future.

I'm not at all familiar with your testing methods. What I did was load an Excel spreadsheet evaluate it and compare the results visually and with poi. I could write a simple Excel file and the POI unit test to show fail on the error. Is that OK?
Comment 3 Dominik Stadler 2018-02-09 08:18:00 UTC
That would be perfekt!
Comment 4 Dominik Stadler 2018-04-02 21:14:29 UTC
Any update on the sample file and unit-test?
Comment 5 Ian Giguère 2019-04-16 18:02:11 UTC
Created attachment 36529 [details]
Modifications to Quotient.java and QuotientFunctionTestCaseData.xls

Add new line to 'QuotientFunctionTestCaseData.xls' to test QUOTIENT with cell references as arguments.

Dereference Value before coercing it to double.
Comment 6 Ian Giguère 2019-04-16 18:03:17 UTC
Created attachment 36530 [details]
Edited Excel file: QuotientFunctionTestCaseData.xls

Add new line to 'QuotientFunctionTestCaseData.xls' to test QUOTIENT with cell references as arguments.
Comment 7 Ian Giguère 2019-04-16 18:05:19 UTC
Created attachment 36531 [details]
Modifications to Quotient.java to support cell references

Dereference Value before coercing it to double.
Comment 8 Ian Giguère 2019-04-16 18:06:15 UTC
I did not know if the patch file was sufficient so I also added the excel and java files I edited.
Comment 9 PJ Fanning 2021-10-10 11:22:01 UTC
fix applied with r1894103