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

exponent-base gives non-sensical results when parsing numbers with exponent-mode=scientific #736

Open
JasonGross opened this issue Jun 21, 2024 · 2 comments

Comments

@JasonGross
Copy link

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\num[exponent-base=2,exponent-mode=scientific]{1024}
\end{document}

I expect to see something like 210, but instead I see 1.024 × 23. I get that someone might want to pass something non-numerical expression as exponent-base, like \mathbb{R} or whatever, but I'd quite like to have a version of exponent-base that was treated semantically.

@josephwright
Copy link
Owner

josephwright commented Jun 21, 2024

This setting is really intended for manually-set values, like \qty[exponent-base = 2]{1e4}{\byte} or similar.

@JasonGross
Copy link
Author

I ended up using the following, which I guess works well enough

\makeatletter
\NewDocumentCommand{\NumAsPow}{oO{2}m}{\ensuremath{%
    \edef\NumAsPow@exp{\fpeval{ln(#3)/ln(#2)}}%
    \edef\NumAsPow@expf{\fpeval{floor(\NumAsPow@exp)}}%
    \edef\NumAsPow@mantissa{\fpeval{(#3)/(#2^{\NumAsPow@expf})}}%
    \IfNoValueTF{#1}{%
        #2^{\num[round-precision=0,round-mode=places]{\NumAsPow@exp}}%
    }{%
        \num[exponent-base=#2,#1]{\NumAsPow@mantissa e\NumAsPow@expf}%
    }%
}}
\makeatother

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

No branches or pull requests

2 participants