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

Correct number of significant digits for cases like 1.0000001 #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joneuhauser
Copy link
Contributor

#metro-setup(round-mode: "figures", round-precision: 4, round-pad: false)

#let fn(number) = (
  [#num(number, round-mode: "none")], 
  [#num(number, exponent-mode: "engineering")],
  [#num(number, exponent-mode: "scientific")],
  [#num(number, exponent-mode: "scientific", round-pad: true)],
  [#num(number, exponent-mode: "threshold")],
)

#table(columns: 5,
table.header([Normal], [Engineering], [Scientific], [Scientific-padded], [Threshold]), 
..(for exp in range(-5, 0) {
  fn(1 + 9*calc.pow(10, exp))
}),
..(for exp in range(0, 6) {
  fn(9 + 1*calc.pow(10, exp))
})
)

previously displayed:

image

In the first / last rows, there are more significant digits than requested.

The new code displays

image

which is in line with

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{siunitx}
\usepackage{tabularx}
\begin{document}
	\sisetup{round-mode = figures, round-precision=4, round-pad = false }
	\begin{table}
		\caption{Thresholds for exponents.%
			\label{tab:threshold}}
		\begin{tabular}
			{
				@{}
				S[round-mode = none]
				S[exponent-mode = engineering]
				S[exponent-mode = scientific]
				S[exponent-mode = scientific, round-pad = true]
				S[exponent-mode = threshold]
				@{}
			}
			{Input} & {Engineering} & {Scientific} & {Scientific-padded} & {Threshold} \\
			1.00009 & 1.00009 & 1.00009 & 1.00009 & 1.00009\\
			1.0009 & 1.0009 & 1.0009 & 1.0009 & 1.0009\\
			1.009 & 1.009 & 1.009 & 1.009 & 1.009\\
			1.09 & 1.09 & 1.09 & 1.09 & 1.09\\
			1.9 & 1.9 & 1.9 & 1.9 & 1.9\\
			10 & 10 & 10 & 10 & 10\\
			19 & 19 & 19 & 19 & 19\\
			109 & 109 & 109 & 109 & 109\\
			1009 & 1009 & 1009 & 1009 & 1009\\
			10009 & 10009 & 10009 & 10009 & 10009\\
			100009 & 100009 & 100009 & 100009 & 100009\\
			
		\end{tabular}
	\end{table}
\end{document}

which outputs

image

There might be some merit to adding special handling for numerical inaccuracies like

#metro-setup(round-mode: "figures", round-precision: 10, round-pad: false)
#num(1.23456 * calc.pow(10, -3), round-mode: "none") $arrow$
#num(1.23456 * calc.pow(10, -3), exponent-mode: "scientific")

but maybe using decimals (ongoing upstream work) solves that in userspace.

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

Successfully merging this pull request may close these issues.

1 participant