4

Consider the following example:

\documentclass{article}

\usepackage{pstricks-add}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\newcommand*\SideLength[1]{\calc{sqrt(#1)}}
\newcommand*\Angle[1]{\calc{asin(1/sqrt(#1))}}

\begin{document}

\begin{pspicture}(-2.9,-3.5)(4.5,2.2)
  \multido{\iA = 2+1, \iB = 1+1}{16}{%
    \psRelLine[angle = \Angle{\iA}](0,0)(2,0){\SideLength{\iB}}{A}}
\end{pspicture}

\end{document}

When compiling, I get the error

! Number too big.
<argument> 7853981633
                     974483
l.17 ...ngle{\iA}](0,0)(2,0){\SideLength{\iB}}{A}}

How do I fix this?

5

You are passing the full set of digits from l3fp back to pstricks, but that's too many! (The LaTeX3 FPU is IEEE-compliant so works at 16 digit precision.) In common with many TeX packages, pstricks is expecting a number here with no more digits than TeX will accept as a \number. Probably the easiest fix is to round within the FPU:

\newcommand*\Angle[1]{\calc{round(asin(1/sqrt(#1)),5)}}

or

\ExplSyntaxOn
  \cs_new:Npn \calc #1 { \fp_eval:n { round ( #1 , 5 ) } }
\ExplSyntaxOff

depending on your use cases. (Five decimal digits is probably enough to pass back to most TeX end-uses.)

  • 2
    "5 digits should be enough for anyone." You may live to rue those words! – Loop Space Jan 20 '14 at 22:31
  • @AndrewStacey I did say 'probably' :-) Depending on the internal set up of what you send data back to, you may loose additional places in any case. (Picking up as a dimen is not uncommon, and that limits you to 5 d.p.) – Joseph Wright Jan 20 '14 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.