Precision in numeric calculations

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


Use a better floating point management framework, the one in expl3.

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn
\cs_set_eq:NN \fpeval \fp_eval:n
\ExplSyntaxOff

\begin{document}

\fpeval{10e-32/10e-30}

\end{document}

Note that, differently from pgf, the floating point macros are expandable.

Thus, you get the same output from

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn
\cs_set_eq:NN \fpeval \fp_eval:n
\ExplSyntaxOff

\newcommand{\varA}{10e-32}
\newcommand{\varB}{10e-30}

\begin{document}

\fpeval{\varA/\varB}

\end{document}

enter image description here

Consult texdoc interface3 for more information about the supported functions and the syntax.


Use lualatex:

\documentclass{article}
\begin{document}    
\directlua{tex.print(10^(-32)/10^(-30))}

\directlua{tex.print(1/10^(-30))}
\end{document}

enter image description here

Tags:

Pgfmath