Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accuracy of divide and reciprocal #1148

Open
muzimuzhi opened this issue Mar 19, 2022 · 1 comment
Open

Improve accuracy of divide and reciprocal #1148

muzimuzhi opened this issue Mar 19, 2022 · 1 comment
Labels

Comments

@muzimuzhi
Copy link
Member

Brief outline of the bug

Without fpu library, currently the accuracy of math functions divide and reciprocal are not so good. eTeX's \dimexpr might help, by using

‘scaling’ operations (a multiplication immediately followed by a division) which are performed as one combined operation with a 64-bit product as intermediate value.
excerpted from the eTeX manual, sec. 3.5 "Expressions"

Existing discussions

Minimal working example (MWE)

\documentclass{article}
\usepackage{pgfmath}

\begin{document}
\pgfmathprint{38.89993/38.9}, % = 1.2, should be less than 1
\pgfmathprint{38.8999/38.9}   % = 1.1

\pgfmathreciprocal{1.25}\pgfmathresult % = 0.80019, 0.8 expected
\end{document}
@hmenke
Copy link
Member

hmenke commented Mar 19, 2022

I think you are conflating a few different things here. There are a number of orthogonal issues with the divide and reciprocal functions:

  1. Loss of precision (\pgfmathreciprocal{1.25})
  2. Dimension too large (\pgfmathdivide{1000.0}{0.001})
  3. Bogus results (\pgfmathdivide{38.89993}{38.9})

The most pressing issue is fixing the bogus results. Eventually we should find workarounds for the other two issues as well, but as of now they just reflect the nature and limitations of TeX's fixed-point arithmetic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants