\numexpr with parentheses / order of operations

\documentclass{article}
\usepackage{xfp}
\begin{document}

\inteval{(10+5)/3}

\end{document}

A solution with PSTricks only for fun purposes.

\documentclass[border=\dimexpr355pt/113\relax]{standalone}
\usepackage{pst-calculate}
\begin{document}

\pscalculate{(10+5)/2}

\end{document}

enter image description here

Or if you want to get the output in a fractional form, you can use Computer Algebra System named SageMath that can be invoked from LaTeX via sagetex package as follows. An extra setup is needed, let me know if you need it.

\documentclass{standalone}
\usepackage{sagetex}
\begin{document}

$\sage{(10+5)/2}$

\end{document}

enter image description here


Here's a LuaLaTeX-based solution. It assumes you're doing integer arithmetic, mainly because your code example uses \numexpr. If the result needn't be integer-valued, just omit the math.floor part.

\documentclass{article}
\newcommand\inteval[1]{\directlua{tex.sprint(math.floor(#1))}}
\begin{document}
\inteval{( 10 + 5 ) / 3 }
\end{document}

Tags:

Arithmetic