The following MWE results in the error Dimension too large. Changing the upper limit of the domain to a smaller value like 120 gets makes this error disappear.
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [
domain=-20:150,
]
\addplot+ {exp(-x*x)};
\end{axis}
\end{tikzpicture}
\end{document}
But I cannot understand why. The largest number that should be involved in the calculation is 150^2, which is well in pgfplots' range (and in fact plotting x*x works just fine). My guess is that it has something to do with the implementation of exp that makes pgfplots try to compute exp(150^2) in the process of calculating exp(-150^2). However, the plot still appears just fine, so I'm not sure.
What is the reason for this error and how can I avoid it?
(Of course the real function I want to plot is a bit more complex, so just manually plotting y = 0 for x > 50 or something like that won't work. I need to solve/circumvent the underlying issue.)






sagetexbut other options mentioned might suit you better. – DJP Nov 24 '21 at 22:21\pgfplotsset{compat=1.17}+ LuaLaTeX (TeXLive 2021) +domain = 120:150then it works but with\pgfplotsset{compat=1.10}is does not. – Dr. Manuel Kuehner Nov 24 '21 at 22:24pgfplotspeople.. Oh, and I'm pretty sure pinging does not work that way. – schtandard Nov 24 '21 at 22:47exp(-150^2)but simply with150^2. pgf does all its computations using TeX dimensions which are limited to 2^14 = 128^2. 150^2 is simply too big. – Eric Domenjoud Nov 24 '21 at 23:13pgfplotsuses thefpulibrary by default, so this is not an issue. As I mentioned, plottingx*x(which includes150^2) works just fine. – schtandard Nov 24 '21 at 23:15150^2to my non-answer. – Dr. Manuel Kuehner Nov 24 '21 at 23:30