[Tex/LaTex] Precision in numeric calculations

pgfmath

When using pgfmathsetmacro with very small of high exponents, it doesn't work. The example below exits by complaining a division by zero. Is there any way to increase the precision that this works or another package which handles this example?

\documentclass{article}

\usepackage{tikz}

\begin{document}

\pgfmathsetmacro{\a}{10e-32}
\pgfmathsetmacro{\b}{10e-30}

\pgfmathsetmacro{\c}{\a/\b}
\c
\pgfmathsetmacro{\c}{1/\b}
\c
\end{document}

Best Answer

The number range in the default math engine of pgf is quite restricted because of the limitations of TeX's numbers. Also the library for fixed point arithmetic does not help with these exponents, because this library only covers ten digits before and after the decimal point.

The example can be processed with the floating point unit library:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fpu}

\begin{document}

\pgfset{fpu}
\pgfmathsetmacro{\a}{10e-32}
\pgfmathsetmacro{\b}{10e-30}

\pgfset{fpu/output format=fixed}
\pgfmathsetmacro{\c}{\a/\b}
\c

\pgfset{fpu/output format=sci}
\pgfmathsetmacro{\c}{1/\b}
\c
\end{document}

Result

Related Question