FPeval clip and round

Added by Paco Riviere about 4 years ago

I see all examples in guide 5.6.1 use clip and trunc to reduce decimals on answers.

If I use \FPeval\VQsol{clip((\VQfor)*0.25)}
and the rVQFor is for example 181, it i evalauated to 45,2 but I need a rounded value, that is to say 45,3
Going to the doc in fp (https://ctan.javinator9889.com/macros/latex/contrib/fp/documentation.pdf page 5) I should use:
\FPeval\VQsol{round((\VQfor)*0.25):1}
gives me an AMC error:

FP-EVAL ( FP-UPN ( FP-RANDOM ( FP-DIV ) ) ( FP-MUL ) ( FP-ADD ) ( FP-TRUNC )
) ) ( FP-EVAL ( FP-UPN ( FP-MUL )
! FP error: UPN stack is empty!.
\FP@errmessage #1->\errmessage {FP error: #1!}

l.1125 \end{examcopy}

( FP-ROUND
! Missing number, treated as zero.
<to be read again> 
                   \relax 
l.1125 \end{examcopy}

)
! FP error: Evaluation results in multiple values!.
\FP@errmessage #1->\errmessage {FP error: #1!}


What I'm doing wrong?

Replies (10)

RE: FPeval clip and round - Added by Alexis Bienvenüe about 4 years ago

Parenthesis I think.

\FPeval\VQsol{round((VQfor * 0.25):1)}

RE: FPeval clip and round - Added by Paco Riviere about 4 years ago

Thanks Alexis, you are right.
Unfortunately, error:

! FP error: Evaluation results in multiple values!.

persits.

RE: FPeval clip and round - Added by Frédéric Bréal about 4 years ago

\FPeval\VQsol{round(VQfor * 0.25,1)}

comma

RE: FPeval clip and round - Added by Paco Riviere almost 5 years ago

On another case I have the same problem:
\FPeval\VQsol{clip((\VQfor)/2)}

gives as result 105.5 coming to a wrong solution of 105 when the right one is 106

But if do the same that the previous one;
\FPeval\VQsol{round((\VQfor/2),1}

or even:
\FPeval\VQsol{round((\VQfor/2),0}

Then AMC crashes with the following message:

! FP error: Evaluation results in multiple values!.
\FP@errmessage #1->\errmessage {FP error: #1!}

What is wrong now?

RE: FPeval clip and round - Added by Frédéric Bréal almost 5 years ago

Please give me the code for \VQfor.
My own help file (in french).

RE: FPeval clip and round - Added by Frédéric Bréal almost 5 years ago

\FPeval\VQsol{clip(\VQfor/2)}

RE: FPeval clip and round - Added by Paco Riviere almost 5 years ago

I see. It should be:

\FPeval\VQsol{round((\VQfor/2),1)}

Parentesi. Sorry,

RE: FPeval clip and round - Added by Frédéric Bréal almost 5 years ago

Just this would work

\FPeval\VQsol{round(\VQfor/2,1)}

(1-10/10)