exponent-base gives non-sensical results when parsing numbers with exponent-mode=scientific
JasonGross opened this issue · 2 comments
JasonGross commented
\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 commented
This setting is really intended for manually-set values, like \qty[exponent-base = 2]{1e4}{\byte}
or similar.
JasonGross commented
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