I want to define varafterglowepsdown, varafterglowa and varafterglowb and use them in a tikz function like this:

\pgfmathsetmacro{\varafterglowb}{ln(\varafterglowepsdown) - ln(1 + \varafterglowepsdown)}
\pgfmathsetmacro{\varafterglowa}{(1 + \varafterglowepsdown) / exp(\varafterglowb)}

\begin{tikzpicture}[declare function={
    % some function using varafterglowa, varafterglowb, and varafterglowepsdown
    % some axis definition

However on the third line I get a "Dimension too large." error.

How do I properly define varafterglowa?

2 Answers 2


A complementary approach to percusse's answer would be to use the LaTeX3 FPU (this provides an IEEE 754 floating point implementation in an expandable form):

\cs_new_eq:NN \fpeval \fp_eval:n

\fpset{\varafterglowb}{ln(\varafterglowepsdown) - ln(1 + \varafterglowepsdown)}
\fpset{\varafterglowa}{(1 + \varafterglowepsdown) / exp(\varafterglowb)}


The result here is a 'pure' number so should be usable where pgf needs a number. You can use fpeval directly in many places rather than store the result.

  • What does the \cs_new_eq:NN \fpeval \fp_eval:n line do? Commented Jan 20, 2016 at 10:19
  • 1
    @RobertHegner In expl3 syntax _ and : are 'letters'. To let us access the command \fp_eval:n with a 'document' name I've made a copy of it as \fpeval: \cs_new_eq:NN does that (it's more-or-less \let).
    – Joseph Wright
    Commented Jan 20, 2016 at 11:23
  • @JosephWright I think it would be great if \fpeval and \fpset comes with the box with batteries included.
    – percusse
    Commented Jan 20, 2016 at 12:23
  • @percusse I've thought about that, but there are issues. One of the design aims for expl3 is that as far as possible it keeps 'out of the way' in terms of existing documents. It adds no document-level syntax on at design-level only \ExplSyntax(On|Off), \ProvidesExpl... and \GetdInfo. So adding \fpeval would be 'risky'.
    – Joseph Wright
    Commented Jan 20, 2016 at 12:26
  • @JosephWright Maybe a math frontend as PGF parser might be a solution say a pars3 package which offers the document level macros.
    – percusse
    Commented Jan 20, 2016 at 12:32

There is a strict limitation in TeX about how big numbers can get which is plus minus 16384. Hence anything going above or anything that comes sufficiently close to zero in the divisor causes overflows. Here exp(-9...) is practically zero for TeX and it is done.

Instead you can use more precise calculation engines written for TeX for example FP or TikZ' internal fpu library.


\pgfkeys{/pgf/fpu}% Turn on the fp engine
\pgfmathsetmacro{\varafterglowb}{ln(\varafterglowepsdown) - ln(1 + \varafterglowepsdown)}
\pgfmathsetmacro{\varafterglowa}{(1 + \varafterglowepsdown) / exp(\varafterglowb)}
\pgfkeys{/pgf/fpu=false}% Turn it off

\node{\pgfmathfloattofixed\varafterglowa\pgfmathresult};% Show the fixed number

The downside with fpu is that you have to convert the results to the fixed notation from it's own float notation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .