What does script operation "OP_IFDUP" do?

2

According to the wiki page, OP_IFDUP will duplicate the top of the stack "if the input is true or false". It seems to me that everything is true or false when interpreted as a boolean.

According to the source code:

case OP_IFDUP:
    [...]
    valtype vch = stacktop(-1);
    if (CastToBool(vch))
        stack.push_back(vch);

That suggests the wiki is incorrect. What would be a better way of wording it, and what is the operation for?

Chris Moore

Posted 2012-03-19T21:00:46.540

Reputation: 13 952

Answers

2

It duplicates the top stack item if the top stack item is not 0 and not negative 0. I'm not sure where this would be useful.

theymos

Posted 2012-03-19T21:00:46.540

Reputation: 8 228

Thanks. I fixed the wiki accordingly. I copied the description from the OP_IF operation, since the code is the same.Chris Moore 2012-03-19T21:46:15.307