Issue 126758 - CURRENT() only evaluates first occurrence
Summary: CURRENT() only evaluates first occurrence
Status: UNCONFIRMED
Alias: None
Product: Calc
Classification: Application
Component: ui (show other issues)
Version: 4.1.1
Hardware: Mac OS X 10.10
: P5 (lowest) Normal (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-29 00:19 UTC by Jim
Modified: 2017-05-20 11:53 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jim 2015-12-29 00:19:28 UTC
The CURRENT() function seems to only evaluate the first occurrence.

EX:
enter the following in a cell:
=0.5+IF(AND(NOT(CURRENT()>=1);NOT(CURRENT()>=1);NOT(CURRENT()>=1);1;0))

Evaluates to .5 rather than 1.5

EX2:
=0.5+IF(OR(CURRENT()>=0.1;CURRENT()>=1;CURRENT()>= 1);1;0) 
Correctly Evaluates to 1.5

=0.5+IF(OR(CURRENT()>=1;CURRENT()>=0.1;CURRENT()>= 1);1;0)
Evaluates to .5

=0.5+IF(OR(CURRENT()>=1;CURRENT()>=1;CURRENT()>= 0.1);1;0)
Evaluates to .5
Comment 1 Wolfgang Jäger 2016-01-01 15:55:33 UTC
As of 2011-09-29 the relevant specification concerning the evaluator for Calc is http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.odt. It does not mention a function CURRENT. 
Thus implementing such a function must be based on the general clauses C) and should obey the requirements of D) in the subchapter "2.3.1 OpenDocument Formula Evaluator" of the above linked in document. 
Can someone point to the "clear{ly} document" concerning this extension? The best I could find is the Help text (quoted from AOO V4.1.2): 
"
CURRENT
This function returns the result to date of evaluating the formula of which it is a part (in other words the result as far as that evaluation has got). Its main use is together with the STYLE() function to apply selected styles to a cell depending on the cell content.
Syntax
CURRENT()
Example
=1+2+CURRENT()
The example returns 6. The formula is calculated from left to right as: 1 + 2 equals 3, giving the result to date when CURRENT() is encountered; CURRENT() therefore yields 3, which is added to the original 3 to give 6.
=A2+B2+STYLE(IF(CURRENT()>10;"Red";"Default"))
The example returns A2 + B2 (STYLE returns 0 here). If this sum is greater than 10, the style Red is applied to the cell. See the STYLE function for more explanation.
="choo"&CURRENT()
The example returns choochoo.
"
Obviously this can only apply to an evaluation using exactly one accumulator and not needing any postponing of operations. Only the second example of the Help text may assure that the previously calculated partial result must still be accessible when a condition is started to evaluate. Changing it into 
=A2+B2+STYLE(IF(10<CURRENT();"Red";"Default")) will change the result, and we should expect that. We have a very fragile situation and even the second example of the above mentioned Help depends on not initialising the accumulator anew when the partial result is pushed on the stack (supposed things are roughly done this traditional way).
To get it a bit clearer suspend using logical expressions, and try:
=5*(CURRENT()+2)
=5*(2+CURRENT())
=5*(CURRENT()+2+CURRENT())

I could not find an AOO documentation containing more detail (or in fact something at all). (The most recent LibO CalcGuide simply puts it this way: "CURRENT() Calculates the current value of a formula at the actual position.")

In consequence we should not judge the reported behaviouir a bug. We have instead a serious flaw concerning specification and documentation - and a possibly too rash implementation of an extension.
Comment 2 Wolfgang Jäger 2016-01-01 18:39:05 UTC
Here an additional attemp:

Let me modify the first example of the OP to
=0.5+IF(AND(NOT(CURRENT()>=1);NOT(CURRENT()<>1);CURRENT()=1);1;0)
It will return 1.5 . 
Why? Having evaluated the "NOT(CURRENT()>=1)" on the first parameter position of AND the result kept in (kind of) the accumulator will be 1 (meaning TRUE). This is the "current" value still present when the evaluation of the second parameter is starting. Now this intermediary result is returned by CURRENT. The second parameter will evaluate to TRUE again for this reason. I cannot judge whether the CURRENT value passed to the third parameter is now the TRUE returned for the second one or the TRUE already accumulating two TRUEs under the rule of AND. This is VERY implementation dependent.

Based on the undocumented utilisation of AND as a logical infix operator we may also look at
=0.5+IF((CURRENT()<1) AND (CURRENT()=1) AND (CURRENT()=1);1;0) 
to emphasise the similarity of the example to the arithmetic one from my above comment.